system
March 15, 2014, 3:16pm
1
Hi all,
First time posting here.
I'm making a simple POV display. I have all the hardware and code up and running fine. However, I am using a function to initialise an array, the values in each element is then output onto the LEDs.
My code is very basic for assigning values to the array:
void setPattern(){
LSB[0] = 0x08;
...
...
}
The problem is if I call PORTB = 0x08, the code will light the first LED of the display.
If I call PORTB = LSB[0] it lights a different LED even though both values are the same.
Does anybody have any suiggetsions as to why this is?
Any help would be appreciated.
I'm using an Arduinio Micro btw.
Thanks.
system
March 15, 2014, 3:19pm
2
The problem is if I call PORTB = 0x08, the code will light the first LED of the display.
If I call PORTB = LSB[0] it lights a different LED even though both values are the same.
Your snippet of code does NOT demonstrate this.
Does anybody have any suiggetsions as to why this is?
Yes. Your code is wrong.
system
March 15, 2014, 3:33pm
3
I'll post a larger sample of code so....
byte LSB[noFrames][PatternsLength];//output on PORTB - inner 5 LEDS
byte MSB[noFrames][PatternsLength];//output on PORTB - outer 6 LEDs
void setup(){
DDRB = 0xFF;//set PORTB as outputs
DDRF = 0xFF;//set PORTF as outputs
attachInterrupt(0, completeRotation, RISING);//trigger ISR when pin 3 sees rising edge
setPattern();//initialise frames
}//end setup
void setPattern(){
LSB[0][0] = 0x08; MSB[0][0] = 0x00;
LSB[0][1] = 0x08; MSB[0][1] = 0x00;
LSB[0][2] = 0x08; MSB[0][2] = 0x00;
LSB[0][3] = 0x08; MSB[0][3] = 0x00;
LSB[0][4] = 0x08; MSB[0][4] = 0x00;
I haven't bothered putting in the main loop here as it's not relevant but.
The point is, if I set PORTB to, lets say, 0x08;
or if I set it to LSB[0][0] the result is different.
The code here is incomplete but I'm looking for any suggestions as to why this could be the case.
The arrays are assigned the correct number of elements and all those basic things have been checked and double checked.
Thanks
system
March 15, 2014, 3:39pm
4
The code here is incomplete but I'm looking for any suggestions as to why this could be the case.
When you actually post code that compiles, we can try to replicate your problem. Meanwhile, good luck.
system
March 15, 2014, 3:48pm
5
Apologies,
I didn't think the code would need to be compiled, I figured it could be a known fault of some sort.
int r = 13;//pwm
int g = 3;
int b = 5;
long t1;//count variable
long const l = 151;
long const j = l+1;
int LSB[j];//vector to display on PORTB
int MSB[j];//vector to display on PORTF
int dt;//delay time between sectors
int i = 0;//index variable
//Interrupt service routine - triggered when full rotation is completed
//1 - Initialises index varibale and time counter
//2 - sets time between each secotr in the circle
void completeRotation(){
dt = t1/l;
i = 0;
t1 = 0;
}//end ISR for interrupt.0
//Setup ports and initial pattern to be displayed
void setup(){
DDRB = 0xFF;//set PORTB as outputs
DDRF = 0xFF;//set PORTF as outputs
setPattern();
digitalWrite(r, LOW);
digitalWrite(g, LOW);
digitalWrite(b, LOW);
attachInterrupt(0, completeRotation, RISING);
}//end setup
void loop(){
PORTB = 0XC0;
delay(500);
PORTB = LSB[14];
delay(500);
}//end loop
}//end loop
void setPattern(){
//A
MSB[0] = 0x00; LSB[0] = 0x20;
MSB[1] = 0x00; LSB[1] = 0xC0;
MSB[2] = 0x03; LSB[2] = 0x00;
MSB[3] = 0x11; LSB[3] = 0x00;
MSB[4] = 0x21; LSB[4] = 0x00;
MSB[5] = 0x11; LSB[5] = 0x00;
MSB[6] = 0x03; LSB[6] = 0x00;
MSB[7] = 0x00; LSB[7] = 0xC0;
MSB[8] = 0x00; LSB[8] = 0x20;
//B
MSB[9] = 0x33; LSB[9] = 0xE0;
MSB[10] = 0x21; LSB[10] = 0x20;
MSB[11] = 0x21; LSB[11] = 0x20;
MSB[12] = 0x21; LSB[12] = 0x20;
MSB[13] = 0x12; LSB[13] = 0xC0;
//C
MSB[14] = 0x13; LSB[14] = 0xC0;
MSB[15] = 0x20; LSB[15] = 0x20;
MSB[16] = 0x20; LSB[16] = 0x20;
MSB[17] = 0x20; LSB[17] = 0x20;
MSB[18] = 0x10; LSB[18] = 0x40;
//D
MSB[19] = 0x33; LSB[19] = 0xE0;
MSB[20] = 0x20; LSB[20] = 0x20;
MSB[21] = 0x20; LSB[21] = 0x20;
MSB[22] = 0x20; LSB[22] = 0x20;
MSB[23] = 0x13; LSB[23] = 0xC0;
//E
MSB[24] = 0x33; LSB[24] = 0xE0;
MSB[25] = 0x21; LSB[25] = 0x20;
MSB[26] = 0x21; LSB[26] = 0x20;
MSB[27] = 0x21; LSB[27] = 0x20;
//F
MSB[28] = 0x33; LSB[28] = 0xE0;
MSB[29] = 0x21; LSB[29] = 0x00;
MSB[30] = 0x21; LSB[30] = 0x00;
MSB[31] = 0x21; LSB[31] = 0x00;
//G
MSB[32] = 0x13; LSB[32] = 0xC0;
MSB[33] = 0x20; LSB[33] = 0x20;
MSB[34] = 0x20; LSB[34] = 0x20;
MSB[35] = 0x21; LSB[35] = 0x20;
MSB[36] = 0x11; LSB[36] = 0xC0;
//H
MSB[37] = 0x33; LSB[37] = 0xE0;
MSB[38] = 0x01; LSB[38] = 0x00;
MSB[39] = 0x01; LSB[39] = 0x00;
MSB[40] = 0x01; LSB[40] = 0x00;
MSB[41] = 0x33; LSB[41] = 0xE0;
//I
MSB[42] = 0x20; LSB[42] = 0x20;
MSB[43] = 0x20; LSB[43] = 0x20;
MSB[44] = 0x33; LSB[44] = 0xE0;
MSB[45] = 0x20; LSB[45] = 0x20;
MSB[46] = 0x20; LSB[46] = 0x20;
//J
MSB[47] = 0x20; LSB[47] = 0x60;
MSB[48] = 0x20; LSB[48] = 0x20;
MSB[49] = 0x33; LSB[49] = 0xE0;
MSB[50] = 0x20; LSB[50] = 0x00;
MSB[51] = 0x20; LSB[51] = 0x00;
//K
MSB[52] = 0x33; LSB[52] = 0xE0;
MSB[53] = 0x01; LSB[53] = 0x00;
MSB[54] = 0x02; LSB[54] = 0x80;
MSB[55] = 0x10; LSB[55] = 0x40;
MSB[56] = 0x20; LSB[56] = 0x20;
//L
MSB[57] = 0x33; LSB[57] = 0xE0;
MSB[58] = 0x00; LSB[58] = 0x20;
MSB[59] = 0x00; LSB[59] = 0x20;
MSB[60] = 0x00; LSB[60] = 0x20;
MSB[61] = 0x00; LSB[61] = 0x20;
//M
MSB[62] = 0x33; LSB[62] = 0xE0;
MSB[63] = 0x10; LSB[63] = 0x00;
MSB[64] = 0x02; LSB[64] = 0x00;
MSB[65] = 0x01; LSB[65] = 0x00;
MSB[66] = 0x02; LSB[66] = 0x00;
MSB[67] = 0x10; LSB[67] = 0x00;
MSB[68] = 0x33; LSB[68] = 0xE0;
//N
MSB[69] = 0x33; LSB[69] = 0xE0;
MSB[70] = 0x10; LSB[70] = 0x00;
MSB[71] = 0x02; LSB[71] = 0x00;
MSB[72] = 0x01; LSB[72] = 0x00;
MSB[73] = 0x00; LSB[73] = 0x80;
MSB[74] = 0x00; LSB[74] = 0x40;
MSB[75] = 0x33; LSB[75] = 0xE0;
//0
MSB[76] = 0x13; LSB[76] = 0xC0;
MSB[77] = 0x20; LSB[77] = 0x20;
MSB[78] = 0x20; LSB[78] = 0x20;
MSB[79] = 0X20; LSB[79] = 0x20;
MSB[80] = 0x20; LSB[80] = 0x20;
MSB[81] = 0x13; LSB[81] = 0xC0;
//P
MSB[82] = 0x33; LSB[82] = 0xE0;
MSB[83] = 0x21; LSB[83] = 0x00;
MSB[84] = 0x21; LSB[84] = 0x00;
MSB[85] = 0x21; LSB[85] = 0x00;
MSB[86] = 0x12; LSB[86] = 0x00;
//Q
MSB[87] = 0x13; LSB[87] = 0xC0;
MSB[88] = 0x20; LSB[88] = 0x20;
MSB[89] = 0x20; LSB[89] = 0x20;
MSB[90] = 0x20; LSB[90] = 0xA0;
MSB[91] = 0x13; LSB[91] = 0xE0;
MSB[92] = 0x00; LSB[92] = 0x20;
//R
MSB[93] = 0x33; LSB[93] = 0xE0;
MSB[94] = 0x21; LSB[94] = 0x00;
MSB[95] = 0x21; LSB[95] = 0x00;
MSB[96] = 0x12; LSB[96] = 0x80;
MSB[97] = 0x00; LSB[97] = 0x60;
//S
MSB[98] = 0x12; LSB[98] = 0x20;
MSB[99] = 0x21; LSB[99] = 0x20;
MSB[100] = 0x21; LSB[100] = 0x20;
MSB[101] = 0x21; LSB[101] = 0x20;
MSB[102] = 0x20; LSB[102] = 0xC0;
//T
MSB[103] = 0x20; LSB[103] = 0x00;
MSB[104] = 0x20; LSB[104] = 0x00;
MSB[105] = 0x33; LSB[105] = 0xE0;
MSB[106] = 0x20; LSB[106] = 0x00;
MSB[107] = 0x20; LSB[107] = 0x00;
//U
MSB[108] = 0x33; LSB[108] = 0xC0;
MSB[109] = 0x00; LSB[109] = 0x20;
MSB[110] = 0x00; LSB[110] = 0x20;
MSB[111] = 0x00; LSB[111] = 0x20;
MSB[112] = 0x33; LSB[112] = 0xC0;
MSB[113] = 0x00; LSB[113] = 0x20;
//V
MSB[114] = 0x30; LSB[114] = 0x00;
MSB[115] = 0x03; LSB[115] = 0x00;
MSB[116] = 0X00; LSB[116] = 0xC0;
MSB[117] = 0x00; LSB[117] = 0x20;
MSB[118] = 0x00; LSB[118] = 0xC0;
MSB[119] = 0x03; LSB[119] = 0x00;
MSB[120] = 0x30; LSB[120] = 0x00;
//W - THIS NEEDS TO BE CHECKED OUT
MSB[121] = 0x30; LSB[121] = 0x00;
MSB[122] = 0x03; LSB[122] = 0x00;
MSB[123] = 0X00; LSB[123] = 0xC0;
MSB[124] = 0x00; LSB[124] = 0x20;
MSB[125] = 0x00; LSB[125] = 0xC0;
MSB[126] = 0x30; LSB[126] = 0x00;
MSB[127] = 0x01; LSB[127] = 0x00;
MSB[128] = 0x01; LSB[128] = 0x00;
MSB[129] = 0x30; LSB[129] = 0x00;
MSB[130] = 0X00; LSB[130] = 0xC0;
MSB[131] = 0x00; LSB[131] = 0x20;
MSB[132] = 0x00; LSB[132] = 0xC0;
MSB[133] = 0x03; LSB[133] = 0x00;
MSB[134] = 0x30; LSB[134] = 0x00;
//X
MSB[135] = 0x20; LSB[135] = 0x20;
MSB[136] = 0X10; LSB[136] = 0x40;
MSB[137] = 0x02; LSB[137] = 0x80;
MSB[138] = 0x01; LSB[138] = 0x00;
MSB[139] = 0x02; LSB[139] = 0x80;
MSB[140] = 0x10; LSB[140] = 0x40;
MSB[141] = 0x20; LSB[141] = 0x20;
//Y
MSB[142] = 0X32; LSB[142] = 0x40;
MSB[143] = 0X01; LSB[143] = 0x20;
MSB[144] = 0x01; LSB[144] = 0x20;
MSB[145] = 0x01; LSB[145] = 0x20;
MSB[146] = 0x33; LSB[146] = 0xC0;
//Z
MSB[147] = 0x20; LSB[147] = 0x60;
MSB[148] = 0x20; LSB[148] = 0xA0;
MSB[149] = 0x21; LSB[149] = 0x20;
MSB[150] = 0x22; LSB[150] = 0x20;
MSB[151] = 0x30; LSB[151] = 0x20;
}//End setPattern
In the main loop PORTB outputs 0xC0 and then the value LSB[14] which is the same. but the port outputs different values for some reason.
Any possible explanation?
system
March 15, 2014, 4:08pm
6
long const l = 151;
long const j = l+1;
Why are you storing single byte values in 4 byte variables?
In the main loop PORTB outputs 0xC0 and then the value LSB[14] which is the same.
What Arduino are you running this on? How much free memory do you have? Again, why are you storing byte sized values in ints?
system
March 15, 2014, 4:17pm
7
I'm using long types as even though the code is only storing a single byte value it is going to be scaled to hold much larger values.
I've changed the second instance you mentioned to byte type.
I'm running it on an Arduino Micro and I have only used around 6Kbytes of a 28Kbyte maximum.
system
March 15, 2014, 4:41pm
8
How large do you think your LSB and MSB arrays are?
And check again how much memory your micro has (you should be worried about SRAM, not flash memory).
system
March 15, 2014, 4:46pm
9
Okay okay, I've changed the type of both arrays.