Skip to content

Instantly share code, notes, and snippets.

@avr-programmierung
Created May 14, 2019 11:25
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Fast PWM Pulsweitenmodulation
/* fast_pwm_02.c ATmega88 @ 1MHz */
#include <avr/io.h>
int main(void)
{
DDRB |= (1<<PB1); // OC1A = output
DDRB |= (1<<PB2); // OC1B = output
OCR1A = 307; // Compare match bei 307 = 30% Duty Cycle
OCR1B = 716; // Compare match bei 716 = 70% Duty Cycle
// Lösche OC1A und OC1B bei einem Compare Match
TCCR1A = (1 << COM1A1) + (1 << COM1B1) + (1 << WGM11) +(1 << WGM10);
// Mode 7, Fast PWM 10-bit und Prescaler = 8
TCCR1B = (1 << WGM12) +(1 << CS11);
while(1)
{
asm ("NOP"); // Nichts tun
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment