This is the second part of our microcontroller tutorial series. This time we cover PWM, ADC, control some motors and servos etc.
How to get started with microcontrollers - Part 2
Hope you like it. :)
This is the second part of our microcontroller tutorial series. This time we cover PWM, ADC, control some motors and servos etc.
How to get started with microcontrollers - Part 2
Hope you like it. :)
Great stuff! Thanks! Definitely useful AND helpful!
Hehe, thanks. I was afraid that nobody even noticed this. :)
Yup - luverly stuff, thanks.
Great stuff. I've a question, in the project "Fading led" you use for the variable step type uint8_t which mean unsigned integer and in the while loop you have a state step *= -1;, is this ok?
Nice.
But it would be a good idea to put the link for part II at the end of the part I article (and maybe tell in the beginning of part I that there's a part II too). Otherwise you can read part I without realizing there's a part II.
Btw. great idea with the animations in the articles so people can see how the LEDs should blink etc.
It is a rather odd way of doing it, but it does actually work. Step ends up being either 1 or 255. Adding 255 to an 8 bit number will overflow. e.g. 5 + 255 = 260, which in hex is 0x0104. Truncating to 8 bits gives you 4, which is what we want. To make things clearer I would make step unsigned and use step = -1.
I'm not professional programmer, but in books for c programming language is written that unsigned can have value from 0 to 255 and you put -1 into it, is this some programming trick?
In a signed byte (decimal) -1 has a specific binary representation: 11111111 . In an unsigned byte the same bit pattern represents the decimal value 255. More on this and related here: http://en.wikipedia.org/wiki/Two... .
Ok, you are right, I was a little confused with statement step = -1 or step *= -1, since it was defined as unsigned, but now I get it, thanks.
awesome... cant wait to get my hands on a servo motor!! :D
Great! Thank you, its a very good tutorial, I like it and learn lots from it.
I have a question about the PWM, fading LED example.
In the code, PWM was set to phase correct mode and the PWM frequency was calculated as below
// Set prescaler to 8 // 1 MHz / 8*256 = ~490 Hz PWM frequency TCCR0B |= (1<<CS01);
However from the attiny 45 datasheet, it states that
PWM frequency = fclk_io/ N*510
The N variable represents the prescale factor (1, 8, 64, 256, or 1024).
taken from pg 78
So which is correct?
The tutorial is incorrect. You use 256 when using Fast PWM.
ok thank you.