Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <avr/io.h>
- #include <avr/iom128.h>
- void setup_dim_pwm() {
- }
- void setup_blink_pwm() {
- }
- int main(void)
- {
- DDRB |= (1 << PB5)|(1 << PB2);
- ICR1 = 0xFFFF;
- // set TOP to 16bit
- OCR1A = 0x3FFF;
- // set PWM for 25% duty cycle @ 16bit
- OCR1B = 0xBFFF;
- // set PWM for 75% duty cycle @ 16bit
- TCCR1A |= (1 << COM1A1)|(1 << COM1B1);
- // set none-inverting mode
- TCCR1A |= (1 << WGM11);
- TCCR1B |= (1 << WGM12)|(1 << WGM13);
- // set Fast PWM mode using ICR1 as TOP
- TCCR1B |= (1 << CS10);
- // START the timer with no prescaler
- // 2nd counter
- OCR2A = 128;
- // set PWM for 50% duty cycle
- TCCR2A |= (1 << COM2A1);
- // set none-inverting mode
- TCCR2A |= (1 << WGM21) | (1 << WGM20);
- // set fast PWM Mode
- TCCR2B |= (1 << CS21);
- // set prescaler to 8 and starts PWM
- while (1);
- {
- // we have a working Fast PWM
- }
- }
- // this code sets up counter2 for an 8kHz Fast PWM wave @ 16Mhz Clock
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement