I am looking to assembly code a watchdog timer with interrupt to save energy.
I do manage to set the :
Vector table
Timer prescale in register (WDTCR) 32ms
Enable the time out interrupt in register (WDTCR)
Watchdog Reset Flag in register (MCUSR)
Sleep mode in register (MCUCR)
Set global interrupt and put in sleep mode ..
But after, I am not able to get it out of the sleep mode ( in fact yes but after 2 098,94 ms )
I have spend a lot of hours read the AVR doc without being able to find the issue by myself.
Would someone would be kind enought to help me.
You don't need assembler language to program the watchdog, and that cannot possibly be a critically timed part of the project. Get the watchdog part running with a higher level language, if you can't do it with the assembler.
here you are touching the point ..
After I have my main action prog but nothing more related to watchdog.
CAn you indicate me what is missing to create the interrupt ?
Compteurwatchdog:
cp R17,R18 ; Compare registers R30 and R0
breq Full_pulse_1 ; si compare = vrai jump to signal court
rjmp Watchdog_routine ; jump a signal court
If all you need to do with the watchdog is to wake or reset the processor, "reti" is the only instruction required. You don't even need an interrupt routine.
I understand your comments "this make no sense at all".
The interrupt routine would be used to decrease a counter that I can adjust the watchdog time precisely by step of 0.32ms and running for example 20 times the watchdog ..
The interrupt routine Have not been worked properly yet but would more be something like
Compteurwatchdog:
dec R17 ; decremente 1 a R17
cp R17,R18 ; Compare registers R17 and R18
breq Full_pulse_1 ; si compare = vrai jump to signal court
rjmp Watchdog_routine ; jump a signal court
And now the code with the missing info.. I do not share the main part as it as no effect to the watchdog
my timing have to be precise at usec in the main code when i am processing the action, that's why i need assembler code.
the watchdog waitting time periode can be precise with steps of 0.2ms so the 0.16ms watchdog flag combine with a loop and a counter is the perferct tool for me to save energy during this waitting time .. So let me ask the question differently..
does someone is having a working assembler code for a watchdog timer getting awake with an interrupt flag ?
If you are using a cpu with more than 8k of flash, your vector table is wrong because there are 4bytes per vector, and you have 3byte instructions there.
Set your goal first by clear statement what you want to do. After that you implement it using Arduino UNO Platform and then replace the high/Arduino level codes using inline assembly codes wherever possible.
1. You want to put the MCU into sleep -- which sleep mode of the following?
Idle, ADC Noise Reduction, Power-down, Power-save, Standby, and Extended Standby
2. For how long the MCU will remain in sleeping? 3. If you want to use WDT Timer to wake up the MCU, then the lowest sleep period is 16 ms (Fig-1).
2. Will use the WDP 4K (32ms) watchdog timer prescale
each time I have an interrupt, the vector table should start the interrupt routine that is decreasing the R17 value . than i compare the R17 value (count down that can be adjust) with a R18 value (0). the target is to create a loop counting the watchdog to be able to adjust the pause watchdog time.
The range of sleeping time could be 480 ms to 640 ms at 32 ms step. Every wakeup will augment the next sleeping time by 32 ms -- is it like this? Are you in a position to implement it using UNO-based high level codes?
The range of sleeping time could be 480 ms to 640 ms at 32 ms step. Every wakeup will augment the next sleeping time by 32 ms -- is it like this? Exactly
Are you in a position to implement it using UNO-based high level codes? Not sure what is uno-based high lvl codes but If i googled correctly seems to be a web simulator for arduino. so if the code is issue from that, i am sure i will be in position to understand my mistake and correct my code in assembler. My issue is that i am using microchip studio and home made PCB with attiny chip .. Meaning I have to transfert the full code in assembler.