Liebe Leute, ich scheitere zur Zeit auf einem ATMEGA328PB den PB3 über OC2A als Fast-PWM zu benutzen. PD3 über OC2B funktioniert!
1 | #include <avr/io.h> |
2 | #define F_CPU 16000000
|
3 | static const uint16_t OCR2DEF = F_CPU/8/16000; // 16kHz (prescaler 8) |
4 | static const uint8_t MASK_TCCR2A = (1<<COM2A1)|(1<<COM2B1); // PWM output to OC2A (PB3, D11) and OC2B (PD3, D3) |
5 | |
6 | int main (void) { |
7 | DDRD |= (1<<PIND3); // OC2B |
8 | DDRB |= (1<<PINB3); // OC2A |
9 | TCCR2A = (1<<WGM21) | (1<<WGM20); // Fast PWM with OCR2A as TOP value and OCR2B as duty cycle value |
10 | TCCR2B = (1<<WGM22) | (1<<CS21); // Activate timer, prescaler 8 |
11 | OCR2A = OCR2DEF; |
12 | OCR2B = (uint16_t)OCR2A*25/100; // 25% duty cycle |
13 | |
14 | volatile uint32_t nop; |
15 | while (1) { |
16 | TCCR2A |= MASK_TCCR2A; |
17 | for (nop=0; nop<1000; nop++) continue; // 2ms |
18 | TCCR2A &= ~MASK_TCCR2A; |
19 | for (nop=0; nop<10000; nop++) continue; // 20ms |
20 | }
|
21 | }
|
Das Board ist ein Pololu A*Star 328PB, programmiert aus Microchip Studio 7.0 mit AVR Dragon über ISP. Was mache ich falsch? LG, Sebastian