Don't ad-block us - support your favorite websites. We have safe, unobstrusive, robotics related ads that you actually want to see - see here for more.
0 Members and 1 Guest are viewing this topic.
TCCR0A |= (1 << WGM01); // Configure timer 0 for CTC mode TCCR0A |= (1 << COM0B0); // Enable timer 0 Compare Output channel B in toggle mode OCR0B = 13; //Toggle the output every 13 uS TCCR0B |= (1 << CS00); // Start timer w/o presaler
#define freq_to_timerval(x) ((F_CPU / x - 1 )/ 2) // Code 000 -- Sony, Baur, Neckermann, Otto Versand, Palladium, Quelle, SEI, Sinudyne, Sonolor, Universumconst struct powercode sonyCode PROGMEM = { freq_to_timerval(37470), // 37.47 KHz {{245, 60}, {123, 60}, {61 , 60},.....
// Set Timer1 to 16 bit fast PWM using ICR1 (NB this code could be made smaller):-TCCR1B &= ~( (1<<CS12) | (1<<CS11) | (1<<CS10)); // disable PWMTCCR1B |= (1<<WGM13);TCCR1B |= (1<<WGM12);TCCR1A |= (1<<WGM11);TCCR1A &= ~(1<<WGM10);// Set up the prescaler to clock div 1 (assuming 1MHz)TCCR1B |= (1<<CS10);// Set the value of TOPICR1 = 25;You can now get the output on either OC1A and/or OC1BTo output on OC1A:TCCR1A |= (1<<COM1A1) | (1<<COM1A0);OCR1A = (ICR1>>1); // 50% duty cycleTo output on OC1B:TCCR1A |= (1<<COM1B1) | (1<<COM1B0);OCR1B = (ICR1>>1); // 50% duty cyclewhile(1){ // Adjust duty cycle by changing OCR1A or OCR1B // Adjust frequency by changing ICR1}