Moin!
Ich bin neu ins Thema Microcontroller eingestiegen und möchte eine PWM
mittels Timer für eine LED generieren.
Ich habe folgenden Code geschrieben:
1 | #include <avr/io.h>
|
2 | #include <avr/interrupt.h>
|
3 |
|
4 | #ifndef F_CPU
|
5 | #define F_CPU 2000000
|
6 | #endif
|
7 |
|
8 | void pwm_init(void);
|
9 |
|
10 | int main(void)
|
11 | {
|
12 | pwm_init();
|
13 | TCC0_CCABUF = 0x7FFF; //set the duty cycle as 50%
|
14 | while((TCC0_INTFLAGS & 0x01) == 0); //wait for the new compare
|
15 | TCC0_INTFLAGS = 0x00;
|
16 |
|
17 | while(1);
|
18 | }
|
19 |
|
20 | void pwm_init()
|
21 | {
|
22 | PORTE_DIRSET = PIN5_bm; //PORTE Pin5
|
23 | TCC1_PER = 0xFFFF;
|
24 | TCC1_CTRLB = TC_WGMODE_SINGLESLOPE_gc; //Single slope mode
|
25 | TCC1_CTRLB = TC1_CCAEN_bm; //channel selection CCAEN
|
26 | TCC1_CTRLA = TC_CLKSEL_DIV2_gc; //clock selection clk/2
|
27 | }
|
Kann das so funktionieren? Die LED leuchtet, ich bin mir jedoch nicht
sicher, ob das nur daran liegt, das der PORT 5 in der pwm_init()
geschaltet wird.
Ich habe einmal mit einem Oszi gemessen und keine PWM gesehen.
Allerdings bin ich mir auch nicht sicher, ob ich richtig gemessen habe.
Vielleicht sieht jemand das Problem.
Viele Grüße,
Max