This shows you the differences between two versions of the page.
pm:lab:lab0xc0-3 [2020/03/30 11:34] ana.constantinescu [Tasks] |
pm:lab:lab0xc0-3 [2020/03/31 17:01] (current) constantin.ghilinta [Generating PWM using ATmega Timers] |
||
---|---|---|---|
Line 3: | Line 3: | ||
For more in-depth knowledge about the capabilities and the timing peripherals and how to program them you can find more information in the ATmega324 datasheet ({{:pm:doc8272.pdf|Datasheet ATmega324}}). | For more in-depth knowledge about the capabilities and the timing peripherals and how to program them you can find more information in the ATmega324 datasheet ({{:pm:doc8272.pdf|Datasheet ATmega324}}). | ||
- | Sketch is available here: | + | |
===== PWM (Pulse Width Modulation) ===== | ===== PWM (Pulse Width Modulation) ===== | ||
Line 93: | Line 93: | ||
{{ :pm:lab:lab3:pwm_unipolar.png?550 |}} | {{ :pm:lab:lab3:pwm_unipolar.png?550 |}} | ||
- | \begin{equstudation} | + | \begin{equation} |
V_{avg}=\frac{7.5ms}{10ms} \cdot 10=0.75 \cdot 10 = 7.5V | V_{avg}=\frac{7.5ms}{10ms} \cdot 10=0.75 \cdot 10 = 7.5V | ||
\end{equation} | \end{equation} | ||
Line 176: | Line 176: | ||
* Wait For T2 | * Wait For T2 | ||
- | he issue here would be that we need to determine how much time does the code before this sequence or after it take to execute. | + | The issue here would be that we need to determine how much time does the code before this sequence or after it take to execute. |
Another solution would be to use timer interrupts and in the ISR to change the state of the pin. | Another solution would be to use timer interrupts and in the ISR to change the state of the pin. | ||
In this manner, we will at least have a precise timing, but we will generate many interrupts that might affect our code in some situations. | In this manner, we will at least have a precise timing, but we will generate many interrupts that might affect our code in some situations. | ||
Line 235: | Line 235: | ||
TCCR1A |= _BV(WGM10); //Just WGM10 is in TCCR1A | TCCR1A |= _BV(WGM10); //Just WGM10 is in TCCR1A | ||
- | //WGM11, WGM12 and WGM13 will be set in TCCR1B | + | //WGM12 will be set in TCCR1B |
TCCR1B |= _BV(WGM12); | TCCR1B |= _BV(WGM12); | ||
Line 329: | Line 329: | ||
===== Tasks ===== | ===== Tasks ===== | ||
- | {{:pm:lab:lab3:lab2_0xc2.zip|}} | + | Sketch is available here: {{:pm:lab:lab3:lab2_0xc2.zip|}} |
1. Compile the code sketch in the archive and run it. | 1. Compile the code sketch in the archive and run it. |