How to prevent ADC interrupt from affecting LCD display on AVR MCU?
I am working with an AVR MCU and have encountered an issue with an interrupt routine affecting my LCD display. Specifically, I have an analog potentiometer connected to an analog pin, and the interrupt associated with the ADC conversion seems to be interfering with the LCD_display method. I need to ensure that interrupts are paused while executing the LCD update code to avoid conflicts.
I used
cli()
to disable interrupts before updating the LCD and sei()
to re-enable interrupts after the update is complete. This prevents the ADC interrupt from interfering with the LCD display operations.
Is there a better way to manage interrupt handling without affecting the LCD display? my code snippet is in the attached file.Solution:Jump to solution
Hey man, If you want to effectively handle interrupts without impacting your LCD display, You could try a few things like ;
Using atomic blocks for critical sections management & making sure that the updates of your LCD screen happen in the main loop only by flagging them with an ADC interrupt.
I hope this helps @Dtynin...
11 Replies
Solution
Hey man, If you want to effectively handle interrupts without impacting your LCD display, You could try a few things like ;
Using atomic blocks for critical sections management & making sure that the updates of your LCD screen happen in the main loop only by flagging them with an ADC interrupt.
I hope this helps @Dtynin
Hi @Dtynin you can use the
flag based
way to fix this , I don't know if you have tried that beforeIt will stop disabling all interrupts globally
cli()
or sei()
and instead it will selectively manage when the LCD is updatedOh thanks @Marvee Amasi please can you guide me through with it, I'd appreciate.
Yeah thanks @Sterling I'd consider using the
flag based
for it.This is your source code in your file ryt , I made some changes
The
adcDataReady
is a volatile flag set in the ISR(ADC_vect)
exactly once the ADC conversion is complete. Did this to avoid the need for disabling interrupts while waiting for the LCD to be updated. The lcd_puts
is called only when adcDataReady
is 1
, making sure that the display is only updated when new ADC data is availableThe LCD update is performed in the main loop if you observe, didnt do it in the interrupt handler, so no global interrupts
cli()
or sei()
are used. It will minimize the time spent with interrupts disabled, to improve your overall system performanceThe ADC interrupt routine is very short, only handling the data conversion and setting a flag, making sure the system doesn’t stay inside the ISR for too long