Attiny3216 ; TimerA "Example 1: 16-bit PWM in single mode, dual slope with interrupt" seems not to work in my case ... #498
Replies: 4 comments 7 replies
-
blink
with nothing writing the pin LOW is will only result in a flashing light idf something forcesthe part into a reset loop.... Should be CHANGE instead of HIGH |
Beta Was this translation helpful? Give feedback.
-
Change
to
|
Beta Was this translation helpful? Give feedback.
-
that was it ! |
Beta Was this translation helpful? Give feedback.
-
Glad to hear you got it sorted out. I can't belive I didn't catch the missing volatile. Yeah. Volatile tells the compiler that it must read the memory location associated with the variable when you want to use it. Even if it thinks it's already got it it in one of the 32 "working registers" that the CPU can directly access (normally it can be like "Oh, I read that variable a dozen lines ago, and it's still in r20, no need to read it again" and it won't generate the code to do that). Likewise, it must write it every time you assign to a volatile variable - otherwise if it knows it will be modifying the value again soon, it won't write out the result until both operations are done. And the compiler can't reorder read or write operations in any way that changes the order that volatile registers are accessed in. All of the hardware registers that control peripherals (like, in above examples, TCA0.SINGLE.CTRLA and the like are defined to be volatile). The other "variable hazard" with interrupts is that if you have a variable written OUTSIDE the interrupt which is larger than 1 byte, but which is read inside an interrupt, that interrupt could occur while it's writing the value, and it would read part of the old value and part of the new one; for that case, you briefly disable interrupts while writing the variable (unless, of course, you know that the interrupt will never be enabled then) |
Beta Was this translation helpful? Give feedback.
-
Hi All,
I have the (your) following code
Attiny3216 ; 20Mhz ; millis() on timerB0
the programming is through an usb - serial converter (whit a shottkey) , no bootloader
with the code
if(DutyCycle > 0) digitalWriteFast(led_onboard, HIGH); ///
the led is flashing
but with the code
if(DutyCycle > 1) digitalWriteFast(led_onboard, HIGH); ///
it doesn't
it looks like the timer stops after the first interrupt (or the interrupt triggers only one time)
don't now what happens, can you please help me ?
Beta Was this translation helpful? Give feedback.
All reactions