Hello again,
in an attempt to speed up my LED matrix code I'm trying to use the digitalWriteFaster library but it appears to be crashing my board, which it an IteadMaple clone and uses a 103RBT6 chip and I'm using the REV3+ flash board setting in the IDE version 0.0.12.
Here is my code which is full of extra bits as I'm trying to test as much of my code as possible.
[code]
#include <digitalWriteFaster.h>
#define LED_RATE 10000 // 2800 is best rate
volatile int tar[]={16,16,32,64,128,256,512,1024,2048};
volatile byte bam;
const byte NUM_COLS=10;
const byte NUM_ROWS=10;
byte Matrix[NUM_ROWS][NUM_COLS];
const byte HB=14; // heartbeat LED
// CONNECTOR PINOUTS
const byte SDI = 23; //pin 2 on the tlc5917 MISO
const byte CLK = 25; //pin 3 on the tlc5917 SCLK
const byte LE =27; //pin 4 on the tlc5917 SS set LOW to latch data
const byte OE=29; //pin 13 on the tlc5917 OE set LOW to enable chip
// Positive Power
//Not Connected
const byte CLK64=31; // clock pin for row chip
const byte DATA64=32; //data pin for row chip and MOSFETS
/*
RIGHT MSGEQ7 ANALOG OUT D2
LEFT MSGEQ7 ANALOG OUT D3
RIGHT STROBE D32
LEFT STROBE D30
Not Connected
Negative Connection
RIGHT RESET D33
LEFT RESET D31
*/
const byte lanalogPin = 15; // read from multiplexer using analog input 0
const byte lstrobePin = 16; // strobe is attached to digital pin 30
const byte lresetPin = 17; // reset is attached to digital pin 31
const byte ranalogPin = 18; // read from multiplexer using analog input 1
const byte rstrobePin = 19; // strobe is attached to digital pin 32
const byte rresetPin = 20; // reset is attached to digital pin 33
HardwareTimer timer(3); // for ISR
void setup()
{
// Serial.begin(9600);
pinMode(13, OUTPUT);
pinMode(HB, OUTPUT);
pinMode(SDI, OUTPUT);
pinMode(CLK, OUTPUT);
pinMode(LE, OUTPUT);
pinMode(OE,OUTPUT);
//pinMode(SRCLR,OUTPUT);
pinMode(DATA64,OUTPUT);
pinMode(CLK64,OUTPUT);
pinMode(lanalogPin, INPUT_ANALOG);
pinMode(lstrobePin, OUTPUT);
pinMode(lresetPin, OUTPUT);
pinMode(ranalogPin, INPUT_ANALOG);
pinMode(rstrobePin, OUTPUT);
pinMode(rresetPin, OUTPUT);
// initialize Timer
// Pause the timer while we're configuring it
timer.pause();
// Set up period
timer.setPrescaleFactor(LED_RATE); // in microseconds
// Set up an interrupt on channel 1
timer.setChannel1Mode(TIMER_OUTPUT_COMPARE);
timer.setCompare(TIMER_CH1, 1); // Interrupt 1 count after each update
timer.setOverflow(1280);
timer.attachCompare1Interrupt(upDate);
// Refresh the timer's count, prescale, and overflow
timer.refresh();
// Start the timer counting
timer.resume();
}
void loop()
{
Matrix[random(9)][random(9)]=random(255);
delay(100);
}
void upDate(void)
{
digitalWriteFaster(HB,LOW);
digitalWriteFaster(13,LOW);
// move data from array to shift register chips
// START OF PWM ROUTINE
digitalWriteFaster(CLK64,LOW); // goto first row of LEDs
digitalWriteFaster(DATA64,LOW);
digitalWriteFaster(CLK64,HIGH);
for(byte rowCtr=0;rowCtr<NUM_ROWS;rowCtr++) // write a whole page of LEDs
{
for(byte y=0;y<NUM_COLS;y++)
{
for(byte x=0;x<3;x++)
{
digitalWriteFaster(CLK,LOW);
/* if(bitRead(Matrix[rowCtr][y],bam)==1) // turn on LED?
{
digitalWriteFaster(SDI,HIGH);
}
else
{
digitalWriteFaster(SDI,LOW);
}*/
digitalWriteFaster(CLK,HIGH);
} // end x
} // end y
digitalWriteFaster(LE,LOW);
digitalWriteFaster(LE,HIGH); // latch data
digitalWriteFaster(LE,LOW);
digitalWriteFaster(OE,HIGH);
digitalWriteFaster(OE,LOW);// turn on LEDs for the max time
// Select next row of LEDs
digitalWriteFaster(CLK64,LOW);
digitalWriteFaster(DATA64,HIGH);
digitalWriteFaster(CLK64,HIGH);
}// end rowCtr
/* if(++bam>7) // change frequency of ISR for next page write
{
bam=0;
}
timer.setOverflow(tar[bam]);*/
digitalWriteFaster(HB,HIGH);
digitalWriteFaster(13,HIGH);
} // end ISR routine
[code]
It works fine when I change the digitalWriteFaster to digitalWrite, the ISR takes .36ms to complete and there is a gap of 177ms between ISR calls so it's not tripping over it's own feet. I could learn how to write to the pins directly but I thought the library would save me the time.
Cheers
Mike