TINY13 PWM behavior stumps me.

Jim Brain <[email protected]>
Newsgroups gmane.comp.hardware.avr.gcc
Message-ID <[email protected]>
I have a chunk of code that operates fine on larger AVR8s, but does not 
seem to operate on the T13.  Just wondering if it's me (could be, this 
is the first time I have used such a small AVR8), or the uC...

A snippet:

static volatile uint8_t i = 0;

int main(void) {
   DDRB = _BV(PB0) | _BV(PB1);
   TCCR0A = _BV(COM0A1) | _BV(COM0B1) | _BV(WGM00);
   TCCR0B = _BV(CS00);
   while (1) {

       while(!(TIFR0 & _BV(OCF0A))) ;
       TIFR0 |= _BV(OCF0A);
       if(i == 2) {
         i = 0;
       }
           OCR0A = 192;
         else
           OCR0A = 64;
       i++;
}

When I run this on a larger AVR8, I get 192/64 split on the output, but 
the T13 just shows the first value on the OCR0A output (192, in this case).

I changed the loop to be:

   while (1) {
     for(i = 0; i < 2;i++) {
       while(!(TIFR0 & _BV(OCF0A))) ;
       TIFR0 |= _BV(OCF0A);
         if(!i)
           PWM1_OCR = 192;
         else
           PWM1_OCR = 64;
       }
}

And that shows random values (64 or 192, but in random arrangements, not 
alternating...)

Obviously, this code is non optimal (my original code was an ISR), but I 
thought I'd try to simplify to see if I could figure out the issue.

JIm


-- Jim Brain [email protected] www.jbrain.com
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.