Hi again All,
I have a project and running @ 16Mhz with Atmega324p
this means that using the maximum prescaller of 128 my ADC speed will be 16000000 / 128 which is 125kHz Thus therefore each ADC conversion will be lasting about 13 / 125kHz which is about 104 us.
The MCU is normaly be sleeping and i will need to
periodically wake it every 500 ms and run some codes (ADC ISR)
The problem was that i was always wanted to use ADC interrupts but i didn't take into account the effects of its speed ':shock:'
I have calculated the possible runtime of my entire project and seems to be in about 165 ms. that is every 165 ms the system starts again from task_0 on... what does this have to with the ADC ISR?
well... it's clear that although a periodic 104 us ADC interrupt. will be a non blocking for the rest of tasks in my project, but will surely make the entire system
extremely slow! and this becomes really very poor and totally undesirable!
so my question was:
Is there anything wrong if i can eliminate the ADC ISR and place its ISR code into WDT's ISR insteady? since i decided to eliminate the ADC ISR due to its erroneous anyway?
the plan is that i must read what was in the ADC ISR every 500 ms. thus I am thinking that with this approach i will be waking the mcu up every 500 ms and do the ADC and checking of some bits stuff but again in WDT's ISR. i think it sounds funny to do ADC conversion within some other peripherals' ISR afterall ADC itself having its own ISR but which in this case fail to fit in due to the enormous speed which will almost be stopping the main() routine to execute!
The ISR code with the ADC is actually initializing an ADC and do some conversion for
2 channels and store their values into some other global volatile values. and if during this case these ADC values happen to exceed some threshold values I stop the mcu from sleeping mode
and main() routine is executed which in turn main() resumes the mcu back to sleep mode when it finishes doing the operation that's been caused due to the exceeding of the threshold by the ADC value and this carries on again& again
I know i wrote a lot and you still probably don't understand what my question was
but briefly i wanted to know if there would be anything wrong with doing ADC initialisation and other few quick bits (which don't have any delays) within the ISR WDT_vect. which will reasonably doing this every 500 ms.
I personally think that this isn't probably wiser (and surely someone will give me some better alternative approaches) But since it's just like any other ISR which is always meant to executes their code when fires it should be fine as long as all main() shared variables within it have declared volatile. ':o'
This is probably the lack of knowing how embedded system designer behave
in such conditions.
Please give me your thoughts and ideas or even better improvement
I will very much appreciated!
Thank you all