I am pretty new in this microcontroller topic, but I need it for my studies.
In the lectures we are just scratching on the surface, and we kind of need to find out on ourselves how things should be done.
Well I am struggeling with the PWM. I think i kind of know how to initialize it, and how to set the clock, and set the PWM in the right mode.
But there are a few things I did not really understand. I found some codesnippets on how to set up a simple PWM for the atmega32U4, but there are some open questions still, and I hope you folks may could help me out.
So first of all:
I saw that the OCR0A Register (which should be set to the value you want to compare the counter with) gets set on every loop iteration in the main function.
Why should I do that? Isn´t the OCR0A Register "memorizing" or so to say "saving" the value, to constantily compare it with the counter value?
The other thing is, i know that for example, if the counter (TCNT0) and the OCR0A values match, i can generate a waveform output on the OC0A.
(Which i guess just means that it is true and false for a certain amount of time, depending on the PWM configurations).
I saw some people setting the DDRB Register, Pin7 to 1, so that it´s marked as an output?
Why should I do that? Is this one somehow "mapped" with the OC0A?
And if so, do I need to set it as an Input again, when I want to read it´s value?
And how can I map this to for example a servomotor? Do i need it manually, by reading the Value of OC0A, and always writing it´s Value to the
Port where my servomotor is connected?
As you see, I am pretty sure my questions are quite obvious, but i really have no idea on this topic, on electronics, and on how to deal with that.
(Guess thats why i have chosen the name pretty_clueless)
So if anyone of you could bring some light in the dark, i would really appreciate.