1

I have a special measuring system. Each measuring unit gives PWM output (total 4 outputs). Maximum frequency will be 10Khz (for each output). I wanna measure the frequency of each PWM evey second using raspi GPIO. I wanna set another one GPIO Pin high when any of the frequency exceeds a particular value. My question is, is it possible to measure 4 output at a same time? I would like to use python.

  • I am confused. For frequency modulation, FM, frequency is a variable. Say, higher output is modulated as higher frequency, and vice versa. There is also Phase Shift Modulation, where frequency is fixed, and higher value is modulated as higher phase shift. For PWM, or Pulse Width Modulation, frequency is fixed, and higher output is modulated as bigger width. BTW, can you give us a link of your measuring device? – tlfong01 May 20 at 11:48
  • it is simple. if frequency=50 Hz means there is 50 pulses per second. Duty cycle, let's say 85%. There is no any change in the duty cycle over the entire measuring period. it is always same. But my system can generate more or less signal per seconds based on the measurement, sometimes 100 Hz, or 1000Hz etc. But duty cycle will be always same (say 85%) – sunny_old_days May 20 at 14:21
  • OK, if duty cycle is fixed, but frequency changes, then that is frequency modulation, but not pulse width modulation. – tlfong01 May 20 at 14:29
0

The pigpio Python module will probably be able to do this.

However to be sure you really need to explain what the PWM looks like. For instance square waves are much easier to detect than pulses with a 5% duty cycle.

If piscope can see the pulses the pigpio Python module should work.

Example code

#!/usr/bin/env python

import time
import pigpio

GPIO=[23, 24, 25, 26]

NUM_GPIO=len(GPIO)

cb=[]
tally=[0]*NUM_GPIO
last=[0]*NUM_GPIO

pi = pigpio.pi()
if not pi.connected:
   exit()

for g in GPIO:
   pi.set_mode(g, pigpio.INPUT)
   cb.append(pi.callback(g))

for i in range(60):
   time.sleep(1.0)
   s=""
   for i in range(NUM_GPIO):
      tally[i] = cb[i].tally()
      s += "GPIO{}={}  ".format(GPIO[i], tally[i]-last[i])
      last[i] = tally[i]
   print(s)

for c in cb:
   c.cancel()

pi.stop()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.