Alternative methods after disabling millis() and micros()? #507
-
HW setup:
I have a code blocks where I use
Statement 1:I want to disable
Statement 2:Let's say after successful disabling of
Either way, example to create own functions like May be looking to wiring.c:
How to transform this for ATTINY-1604, say if I wanted to create some functions? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
The RTC is pretty good for this. Set it up to run as often as you like by setting the prescaler and period, activate the PIT interrupt and will invoke your interrupt code each time the cycle period is up. At a bare minimum, it could even just wake up your microcontroller, which just resumes from where you put it to sleep, or you can set a flag for your main loop to check. I've used Start to generate the skeleton code for this stuff and it works fine. So, here's a simple example that fires the interrupt every millisecond.
That sets up the RTC with a 1ms period Setup your interrupt:
I will not claim this is best practice, but works pretty well for my use-cases. |
Beta Was this translation helpful? Give feedback.
-
The millis and micros timer can be selected from the menu, defaults to TCA0 on parts with neither TCB1 nor TCD0 (like 1607). Parts with a TCD0 use that (since someone is unlikely to want to reprogram it because it;s nasty to work with), 2-series has a TCB1 and uses that (you don't want to use TCB0 if that's your only type B timer,because then tone, servo and some other basic libraries don't work) Disabling millis likely saves a tiny amount of power while the chip is in active mode only, if it's in sleep power down or standby without run standby set, it makes no difference because it's turned off If you want to implement your own versions of the timing functions, the only way to do that is to disable millis from the start, because you can only have one ISR defined for each vector. You get the RTC/PIT combo (note that on 0/1-series with 16k or less flash, you need to enable the PIT and RTC together or they don't work right, see errata - you don't need to enable the PIT interrupt, but you need to enable the PIT in RTC.PITCTRLA. |
Beta Was this translation helpful? Give feedback.
The millis and micros timer can be selected from the menu, defaults to TCA0 on parts with neither TCB1 nor TCD0 (like 1607). Parts with a TCD0 use that (since someone is unlikely to want to reprogram it because it;s nasty to work with), 2-series has a TCB1 and uses that (you don't want to use TCB0 if that's your only type B timer,because then tone, servo and some other basic libraries don't work)
Disabling millis likely saves a tiny amount of power while the chip is in active mode only, if it's in sleep power down or standby without run standby set, it makes no difference because it's turned off
If you want to implement your own versions of the timing functions, the only way to do that is…