I have a GPIO that creates the PWM pulse. Would it be possible to have my python code read the same GPIO, and on high execute my code to read the ADC? Would that disrupt the PWM because I'm accessing the pin?
#======================================================= ## FOR THE PWM #======================================================= pi = pigpio.pi() GPIO_PWM=19 #======================================================= ## FOR THE ADC #======================================================= lsb = 0.004 # 4.096/1024 adc = spidev.SpiDev() adc.open(0,0) # SPI 0 with CE_N0 # max speed in intermal mode adc.max_speed_hz=400000 adc.mode = 0b00 #======================================================= ## Read from ADC while PWM'ing #======================================================= #process for PWM pwm_p=Process(target=tx_pulses, args=(pi, GPIO_PWM, 900, 65535,.5)) pwm_p.start() while(pwm_p.is_alive()): #if(pi.read(GPIO_PWM)): adc.writebytes([0x8E]) # ask for channel 1 my_bytes = adc.readbytes(2) # read channel 1 value = (my_bytes[0] << 3) value = value | (my_bytes[1] >> 5) print(value*lsb*4.01) When I add:
if(pi.read(GPIO_PWM)): To try and sample on the HIGH of the wave signal, the program stops running which I find strange. I imagine it's because it's turning off the wave while then ends the process. If I can't do this, I was thinking of maybe trying to add an event as when the wave goes high.