Guten Tag,
ich hätte eine Frage zur Fast PWM mit benutzerdefinierter Obergrenze auf
dem Atmega168.
Ich habe nachfolgenden Code geschrieben, auf dem Ausgang PD6 liegt
jedoch durchgehend ein High Pegel an und ich bekomme die PWM nicht zum
laufen. Hat jemand eine Idee was ich falsch mache?
Und schonmal vielen Dank :)
1 | #include <avr/io.h>
|
2 | #include <math.h>
|
3 |
|
4 | //Digital Pin 6 (PD6 / OC0A) PWM
|
5 |
|
6 | #define NO_OF_SAMPLES 100
|
7 | #define STEP_X 2.0 * PI / NO_OF_SAMPLES
|
8 | #define DELTA_TIME2OUT (0.5/NO_OF_SAMPLES) * 1000
|
9 |
|
10 | int main(void)
|
11 | {
|
12 | double x = 0.0, y;
|
13 | long oldTime = millis();
|
14 |
|
15 | //Define PD6 as Output
|
16 | DDRD |= 1<<DDD6;
|
17 |
|
18 | //Configure Timer0
|
19 |
|
20 | //Set Prescaler to 1 (internal clock)
|
21 | TCCR0B &= ~(1<<CS02 | 1<<CS01);
|
22 | TCCR0B |= 1<<CS00;
|
23 |
|
24 | //Set Timer Mode to Fast PWM with OCR0A as upper limit
|
25 | TCCR0B |= 1<<WGM02;
|
26 | TCCR0A |= 1<<WGM01 | 1<<WGM00;
|
27 |
|
28 | //Set PWM Mode: Non inverting - Clear OC0A on Compare Match,
|
29 | //set OC0A at BOTTOM
|
30 | TCCR0A |= 1<<COM0A1;
|
31 | TCCR0A &= ~(1<<COM0A0);
|
32 |
|
33 |
|
34 | OCR0A = 0x00;
|
35 |
|
36 |
|
37 | while(1)
|
38 | {
|
39 |
|
40 | OCR0A += 50;
|
41 | _delay_ms(200);
|
42 |
|
43 | }
|
44 |
|
45 | }
|