Go Down

Topic: Initializing timer registers on 16bit counter? (Read 27 times) previous topic - next topic


>Anyhow, it only works as it should when WGM10 = 0.

For normal counting mode, you need WGM10 set to 0.

>Now the question arises is why WGM10 is not 0, although the datasheet claims the default value for TCCR1A is 0.

Its not in the default normal counting mode because the Arduino startup code initializes the timers for PWM. If you want a particular mode you should always explicitly set all relevant registers.


Dec 27, 2009, 07:34 am Last Edit: Dec 27, 2009, 07:43 am by madworm Reason: 1
Ungh. In this case the arduino security blanket sucks.

Is there a way to selectively disable arduino glue when not needed ? If all the analogWrite stuff is never called at all for example, don't mess with the timer registers ? But there's also delay and so on. Maybe it's time to move on. I guess the arduino ide just can't provide a more open way of "include this, configure that, but exclude ...". Maybe an 'advanced mode' with e.g. a PWM.h include for the timers and so on. If the core were split up like that, more experienced users could decide what they really need.
• Upload doesn't work? Do a loop-back test.
• There's absolutely NO excuse for not having an ISP!
• Your AVR needs a brain surgery? Use the online FUSE calculator.
My projects: RGB LED matrix, RGB LED ring, various ATtiny gadgets...
• Microsoft is not the answer. It is the question, and the answer is NO!


Dec 27, 2009, 12:13 pm Last Edit: Dec 27, 2009, 12:14 pm by mem Reason: 1
Ungh. In this case the arduino security blanket sucks.

I think the problem may be more with your expectations than with Arduino  ;)
Saying it sucks because there is no simple way to cut holes in the security blanket is missing the point of Arduino - its purpose is the security blanket.

I wouldn't disagree that Arduino hardware initialization would benefit from being more flexible, but supporting more boards would IMO be a higher priority than disabling Arduino functionality for experienced programmers.

Anyway, there is nothing stopping you from modifying the initialization code in wiring.c to make it do what you want. And if you create a board variant in the hardware/cores directory for the hacked core, you can switch between the standard version and your customized core as needed.

Have fun


I am trying to set the TTCR1B resister and get a strange result

void setup()
   char s[4];
   TCCR1B |= (0 << CS12)|(1 << CS11)|(0 << CS10); // Should clear bit 0 and 2 and set bit 1.
   snprintf(s, 4, "%d", TCCR1B);
   Serial.println(s);  // (The result I get is a decimal 3 insted of a decimal 2)


void loop()

The expected result is a 2 and I get 3

Go Up