Using Timer2 to control the scanning of rows

The Dot Matrix Display (DMD) is a 32x16 array of high-brightness LEDs for visually striking effects. [Product Page]
Post Reply
aprada66
Posts:4
Joined:Sun Jul 30, 2017 3:03 pm
Using Timer2 to control the scanning of rows

Post by aprada66 » Mon Jul 31, 2017 1:45 am

Hi:

My project uses DMD library, and it uses timer1 as a pulses counter, then I used the Timer2 to control the scanning frecuency.

In SETUP:
TCCR2A = B00000000;
TCCR2B = B00000101;
TCNT2 = 0;
TIMSK2 = B00000010; //Timer2 interrupt enabled (each 2ms)
sei();

Timer2 Interrupt Service routine:
ISR(TIMER2_COMPA_vect) //Interruption every 2ms
{
dmd.scanDisplayBySPI();
}

aprada66
Posts:4
Joined:Sun Jul 30, 2017 3:03 pm

Re: Using Timer2 to control the scanning of rows

Post by aprada66 » Mon Jul 31, 2017 11:21 pm

BRIGHTNESS CONTROL ADDED

//In Setup:
TCCR2A = B00000000; //Normal port operation
TCCR2B = B00000101; //clk/128
TCNT2 = 0;
TIMSK2 = B00000010; //Timer2 interrupt enabled (each 2ms)


//Timer2 interrupt service routine:
ISR(TIMER2_COMPA_vect) //Interruption every 2ms
{
if(!digitalRead(PIN_DMD_nOE))//Display OFF?
{//Display ON every 2ms
TCNT2 = 255 - dmdBright;//dmdBright is a register with (1=min and 254=max)
dmdDelay++;
dmd.scanDisplayBySPI();
}
else
{//Display OFF according "dmdBright" value
TCNT2 = dmdBright + 1;//dmdBright is a register with (1=min and 254=max)
OE_DMD_ROWS_OFF();
}
}

Post Reply