Trouble getting timer interrupts working on Tiny13

For Adafruit customers who seek help with microcontrollers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
pneumatic
 
Posts: 186
Joined: Sun Jul 26, 2009 3:59 pm

Trouble getting timer interrupts working on Tiny13

Post by pneumatic »

I'm trying to build a slightly more subtle version of my AC PWM code for my magnetic LED toy. (By AC PWM I mean that I have two legs, A and B, and I want to alternately put A high while B is LOW and then B high while A is low, modulating the length of each to control brightness.)

Right now I'm just using stupid delay loops in util/delay.h (i.e. _delay_ms(..)), but since i have 3 states, and there are 3 timer interrupts possible (OCR0A, OCR0B and the overflow.), it seems like the perfect setup. I wrote some code that sets OCR0A to TIMER0_MAX (0xFF)-timeslice_a, and OC0B to OCR0A-timeslice_b, and set TIM0_COMPA_vect to set A high and B low, TIM0_COMPB_vect to set B high and A low, and TIM0_OVF_vect to set both legs low.

I have set TCCR0{A,B} to 0 (because I don't want the WGM to do the PWM for me),
TIMSK0 |= _BV(TOIE0) | _BV(OCIE0A) | _BV(OCIE0B);
and defined the appropriate vectors.

However, I get no modulation on the output pins at all. Ideas as to what could be going wrong?

(I've attached the code, which is derived from the minipov code, though shares little with it.)
Attachments
magled.c
(5.09 KiB) Downloaded 363 times

uhe
 
Posts: 178
Joined: Mon Sep 03, 2007 4:50 pm

Re: Trouble getting timer interrupts working on Tiny13

Post by uhe »

Disclaimer: I can't comment about the usage of sfr_defs.h and atomic.h. I've never used them.

Have you tried another timer setting? (E.g. Fast PWM which also has 0xFF as TOP value..)
As i read the Modes of Operation on page 63, I'm not sure if the OCR0x registers are usable in normal mode. Compared to the other modes, this mode only mentions the TOV bit.
I don't want the WGM to do the PWM for me
Do you mean things like *toggle the pin*?
Thats what the COM0xx bits are for not the WGMxx bits!

btw.
- there might be more answers if people can see your code (without downloading). phpBB has tags for code listings.
- switch(mode) case 4: is empty and evals to default:

HTH

mtbf0
 
Posts: 1645
Joined: Sat Nov 10, 2007 12:59 am

Re: Trouble getting timer interrupts working on Tiny13

Post by mtbf0 »

it does not appear that you ever start the timer. there are three clock select bits in TCCR0B, at least one of which must be set to start the clock.

Locked
Please be positive and constructive with your questions and comments.

Return to “Microcontrollers”