I have the following code:
def read_adc(adc, lsb):
# first read
adc.writebytes([0x8E]) # ask for channel 0
my_bytes = adc.readbytes(2) # read channel
value = (my_bytes[0] << 3)
print(value*lsb*4.01)
# second read
adc.writebytes([0x8E]) # ask for channel 0
my_bytes = adc.readbytes(2) # read channel
value = (my_bytes[0] << 3)
print(value*lsb*4.01)
# sending pulses with PWM
def tx_pulses(pi, GPIO, frequency, num, dutycycle=0.5):
assert 1 <= frequency <= 500000
assert 1 <= num <= 65535
assert 0.0 <= dutycycle <= 1.0
duration = int(1000000/frequency)
on_micros = int(duration * dutycycle)
num_low = num % 256
num_high = num // 256
wf = []
# on off time
wf.append(pigpio.pulse(1<<GPIO, 0, on_micros))
wf.append(pigpio.pulse( 0, 1<<GPIO, duration - on_micros))
pi.wave_add_generic(wf)
wid = pi.wave_create()
if wid >= 0:
pi.wave_chain([255, 0, wid, 255, 1, num_low, num_high])
while pi.wave_tx_busy():
time.sleep(0.01)
pi.wave_delete(wid)
...
#=======================================================
## FOR THE PWM
#=======================================================
pi = pigpio.pi()
GPIO_PWM=19
pi.set_mode(GPIO_PWM, pigpio.OUTPUT)
#=======================================================
## Read from ADC while PWM'ing
#=======================================================
lsb = 0.004 # 4.096/1024
#process for PWM
pwm_p=Process(target=tx_pulses, args=(pi, GPIO_PWM, 1000, 65535))
pwm_p.start()
while(pwm_p.is_alive()):
cb = pi.callback(19,pigpio.RISING_EDGE, read_adc(adc, lsb))
The goal is to read my ADC on a rising edge. However, my code exits after a few callbacks, and the pwm_p process is still alive. I know this because I have connected a scope to the GPIO output, and we still see the waveform. Any idea why?