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.
attachment 0
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...
Jump to solution
11 Replies
Solution
Sterling
Sterling4mo ago
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
Marvee Amasi
Marvee Amasi4mo ago
Hi @Dtynin you can use the flag based way to fix this , I don't know if you have tried that before
Marvee Amasi
Marvee Amasi4mo ago
It will stop disabling all interrupts globally cli() or sei() and instead it will selectively manage when the LCD is updated
Dtynin
Dtynin3mo ago
Oh thanks @Marvee Amasi please can you guide me through with it, I'd appreciate.
Dtynin
Dtynin3mo ago
Yeah thanks @Sterling I'd consider using the flag based for it.
Marvee Amasi
Marvee Amasi3mo ago
This is your source code in your file ryt , I made some changes
Marvee Amasi
Marvee Amasi3mo ago
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 available
Marvee Amasi
Marvee Amasi3mo ago
The 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 performance
Marvee Amasi
Marvee Amasi3mo ago
The 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
Want results from more Discord servers?
Add your server