ATTINY85 - SleepMode, but using timer0 compB to awaken

Hi there, bit stuck on a project I am working on
essentially its an attiny85 running 8 colour video signal in 48*48 resolution

I have got everything working just fine, using TIMER0_OVF_vect for all the video timing of Hsync and Vsync

I am also using TIMER0_COMPB_vect to give me the exact time to start rendering each line

the line is a bit jittery mainly cos there are other things executing and just a few clock cycles either way puts the picture out just a little.. jelly vision !!!

so what I was wondering...

can I put the attiny to sleep between TIMER0_OVF_vect and TIMER0_COMPB_vect ??

then when it wakes on the COMPB the line rendering should be spot on

Does anyone know anything about this ???
I am a bit new to sleep modes

Thanks in advance :slight_smile:

This may help Arduino Playground - ArduinoSleepCode

Speed up the processor (e.g. run it at 16 MHz instead of 8 MHz). Each clock cycle is shorter making the error smaller.

Idle mode is the only sleep option available. All the other modes will stop timer 0.

Hi there Coding Badly,

I am currently running at 32mhz, I realised i needed idle mode, followed the data sheet, but no success

i put this code at the end of my TIMER0_OF_vect routine

MCUCR = 1<<SE ; // set SE Sleep enable and set SM0/1 to IDLE
asm ("SLEEP\n\t");
MCUCR = 0; // clear SE sleep enable

without importing a library the assembly SLEEP command was the only thing I could find

Incidentally, I am not running in loop() & setUp()... I am just working in main() to get over some vector clash errors

I am currently running at 32 Mhz...

In that case you are going to have to do some combination of...

• Do less (remove some of those "other things")

• Trigger the TIMER0_COMPB early and walk to the target (wait for the timer count to be the target value with interrupts disabled)

• Put up with the jitter

• Offload driving the display to a second processor

Sleeping is only going to make the problem worse (the processor takes a several cycles to wake).

Thanks, I think I might try this one, its a shame it doesnt work as well as intended as I thought I had really hit a good idea using timer0 for Vsync, Hsync and render start timings, I have seen others use a couple of timers, but I wanted to fit it into one

Cheers