News:

PROTON pic BASIC Compilers for PIC, PIC24, dsPIC33

Main Menu

Position control Read AN in ISR?

Started by basparky, Apr 23, 2025, 02:38 PM

Previous topic - Next topic

basparky

Hi, I'm reading a pot in a procedure called from my main loop in a dspic33FJ128MC706A.
In my tmr1 ISR at 5khz i have a pid loop to control the OC4 and 5 (pwm)output. These outputs are connected to an H-bridge IC which controls dir and speed of a dc motor.
This control loop needs an actual pos read from the potentiometer to work at best(i  believe). In my case this read isnt actual in most cases because it is called from my main loop...

Is there an example available which does ISR bases analog read? Or can anybody please suggest how to do this position control correctly?
 

trastikata

If you place the ADC reading in the ISR then it will take some time to sample and convert the analog signal, which will distort the timing of your 5KHz ISR.

Better solution would be, in my opinion, to set continuous ADC conversion in the background with about the maximum sampling speed for the analog source impedance and in your ISR simply read the ADC register to get the most recent ADC reading.