avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] Tiny26 PWM?


From: Uwe Arends
Subject: Re: [avr-gcc-list] Tiny26 PWM?
Date: Sun, 5 Oct 2003 12:12:55 +0200

Kris,

does initializing "direction" change the behaviour?
-uwe
----- Original Message -----
From: "Kris" <address@hidden>
To: <address@hidden>
Sent: Sunday, October 05, 2003 2:07 AM
Subject: [avr-gcc-list] Tiny26 PWM?


> I've tried replicating the PWM demo on an ATtiny26, but my results
are
> sporadic at best. I've read all the docs I could find on the tiny26,
and
> while they describe the general procedure you should take, they're
> incredibly light on the specifics. Any help would be appreciated.
Here's my
> code:
>
> /*
>  attiny26 specifics:
>  output led should be on pb3, pin 4
> */
>
> #include <inttypes.h>
> #include <avr/io.h>
> #include <avr/interrupt.h>
> #include <avr/signal.h>
>
> // for the attiny26
> #define OC1 PB3 // 1 or OC1B
> #define DDROC DDRB // TCCR1A file://COM1B0/1 TIMSK
> #define OCR OCR1B
>
> enum { UP, DOWN };
>
> volatile uint16_t pwm;
> volatile uint8_t direction;
>
> SIGNAL (SIG_OVERFLOW1){
>
>     switch (direction)
>     {
>         case UP:
>             if (++pwm == 1023)
>                 direction = DOWN;
>             break;
>
>         case DOWN:
>             if (--pwm == 0)
>                 direction = UP;
>             break;
>     }
>
>     OCR = pwm;
> }
>
> void ioinit (void){
>
>  // set PWM value to 0
>  OCR = 0;
>
>  // enable OC1 (PB3) as output
>     DDROC |= _BV(OC1);
>
>  // Enable and lock PLL
>  PLLCSR |= _BV(PLLE);
>
>  // Wait for PLL to lock (app. 100 ms)
>  while(!(PLLCSR & _BV(PLOCK))){;}// may need to manually set plock?
>
>  // Set PLL as asynchronous PWM clock source
>  PLLCSR |= _BV(PCKE);
>
>  // Set PWM mode: toggle OC1B on compare
>  TCCR1A &= ~_BV(COM1B1);// COM1B1 = 0
>  TCCR1A |= _BV(COM1B0);// COM1B0 = 1
>
>  // Set PWM Top value: OCR1C = 0xFF
>  OCR1C = 0xff;
>
>  // enable PWMB
>  TCCR1A |= _BV(PWM1B);
>
>  // Enable Timer/ Set PWM clock prescaler to PCK/2 (32 MHz PWM
clock)
>  TCCR1B |= _BV(CS12) | _BV(CS10);// CS13=0, CS12=1, CS11=0, CS10=1
=> 4 Mhz?
>  // TCCR1B |= _BV(CS11);//CS13=0, CS12=0, CS11=1, CS10=0 => 32 Mhz?
>  // TCCR1B |= _BV(CS10);//CS13=0, CS12=0, CS11=0, CS10=1 => 64 Mhz?
>
>  // Enable Timer1 OVF interrupt
>  // TIMSK |= _BV(TOIE1);
>     timer_enable_int (_BV (TOIE1));
>
>     // enable interrupts
>     sei ();
> }
>
> int main (void){
>
>     ioinit ();
>
>     // loop forever, the interrupts are doing the rest
>
>     for (;;){;}
>
>     return 0;
> }
>
>
>
> _______________________________________________
> avr-gcc-list mailing list
> address@hidden
> http://www.avr1.org/mailman/listinfo/avr-gcc-list




reply via email to

[Prev in Thread] Current Thread [Next in Thread]