Just wondering if any of you have experience calling analogRead from within an interrupt?
I know it’s possibly not best practice considering the analogRead function takes 10 samples and averages them (a bit long for an interrupt).
I have an application where I need to take a couple of thousand samples per second, and they need to be timed according to a PWM generated by the micro - so an interrupt is really the only way to go.
I have got it to work, however I’ve found that whenever I add an analogRead anywhere else in the software (non interrupt driven) then the user application loop will freeze usually after 10-20 seconds or so.
I initially thought that perhaps every now and then my interrupt driven analogRead was probably being called during the non interrupt analogRead, and that perhaps registers were getting corrupted as the micro tried to set up the ADC peripherals while another was already under way. However I’ve since tried disabling interrupts while calling the loop driven analogRead and surprisingly this hasn’t made any difference.
Sorry for the drawn out post, if any has any ideas they would be much appreciated!