I don't understand what that last line of code is doing. I know "~" is a "not" operator and "&=" is a "compound and" operator, but what does that achieve? When I tried writing the results by hand all I got was 000. Also, does anyone have an idea to what the author means by "disable arduino standard timer interrupt"? Any ideas what they mean by "standard" interrupt?
Ok cool it's good to know that "&=~" is the standard form for clearing something, and that example was very helpful but I'm still a little confused. In section 19.9.3 of the the Atmel 328p datasheet, TOIE is just a single byte. So when doing the operation I originally posted, wouldn't the net effect still be 0 essentially? Why not just set "TIMSK0 = 0"?
Do you guys know what "disable arduino standard timer interrupt" might mean or do?
Here's the whole chunk of code I'm using as an example if it makes more sense in context. I'm trying to set up the three timers for an arduino 328p chip on a brushless gimbal board.
Our posts crossed. The &= prevents the other bits in TIMSK0 from being modified. If you would set it to 0, all bits will be cleared, not only the interrupt enable bit.
Because by setting Timer0 prescaler to 1 you break the millis() functionality anyway (it will count much faster) and the interrupt will come very often, every 256 CK eating a lot of processor time.
Also any idea why we would want to disable this timer 0 like this? Why not just leave it out and keep the use of millis() and delay() if we wanted?
The execution of the Timer0 overflow interrupt, used for millis(). can create timing jitter in the other outputs and its often disabled when precise timing is required..
However the code snippet that you posted is enabling a Timer1 overflow interrupt. What is it being used for?
It's being used for an inverted pendulum (self balancing) robot, which is my eventual end goal. The code is supposed to set up the timers, and then to my understanding so far, it uses those timers to create PWM wave(s?) to run a couple of brushless gimbal motors.
to my understanding so far, it uses those timers to create PWM wave(s?)
Yes. But with using the hardware output pins, that can be done without any interrupts. It seems strange to be clearing the Timer0 overflow interrupt, and then setting one up on Timer1.
Yea I don't know.... I'll keep in there for now, but at least I learned something. Later on when everything's working I can try to take it out and see what happens.
cattledog:
Yes. But with using the hardware output pins, that can be done without any interrupts. It seems strange to be clearing the Timer0 overflow interrupt, and then setting one up on Timer1.
I guess the Timer1 overflow ISR is used for something else than counting time. Such as read change of position and update PWM duty to fix it. This way you get nearly constant time between updates and your main loop does not have to care about this (i.e. the robot won't topple if you run into long something in main loop).