vamsimanideep / tlc5940arduino

Automatically exported from code.google.com/p/tlc5940arduino
0 stars 0 forks source link

delay() and millis() don't work on ATMEGA8 with this library as expected #18

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. If you include the TLC5490 library the delay() and millis() function is not 
working anymore as expected.

What version of the product are you using? On what operating system?
Arduino UI + ATMEGA8

Please provide any additional information below.

In the file Tlc5940.h is the Timer1 configured like this:

/** Enables the Timer1 Overflow interrupt, which will fire after an XLAT
    pulse */
#define set_XLAT_interrupt()    TIFR |= _BV(TOV1); TIMSK = _BV(TOIE1)
/** Disables any Timer1 interrupts */
#define clear_XLAT_interrupt()  TIMSK = 0
#else
/** Enables the Timer1 Overflow interrupt, which will fire after an XLAT
    pulse */
#define set_XLAT_interrupt()    TIFR1 |= _BV(TOV1); TIMSK1 = _BV(TOIE1)
/** Disables any Timer1 interrupts */
#define clear_XLAT_interrupt()  TIMSK1 = 0
#endif

In the ATMEGA8 is TIMSK for all times.
By setting the Enable overflow bit for timer1 the '=' should be changed by '|=' 
to leave the other bits in this register as they are.
Also by disabling timer1 should only the TOIE1 bit cleared and not the whole 
register. 

Change:

#define set_XLAT_interrupt()    TIFR |= _BV(TOV1); TIMSK = _BV(TOIE1)
#define clear_XLAT_interrupt()  TIMSK = 0

to:

#define set_XLAT_interrupt()    TIFR |= _BV(TOV1); TIMSK |= _BV(TOIE1)
#define clear_XLAT_interrupt()  TIMSK &= ~(_BV(TOIE1))

then the TOIE0 will stay like it is and the delay and millis will work as 
expected.

Greetings 
Walter

Original issue reported on code.google.com by walter....@essilor.at on 5 Dec 2013 at 9:31