devilsnare 0 Posted June 4, 2011 Share Posted June 4, 2011 Hi so I coded a LED matrix for a heart shape because i had 24 Leds and 10 IO pins. I have most things working. it was successful about 90% of the tries when i had everything attached to my LaunchPad However, since i moved it to a board, about 95% of the time i turn it on, random LEDs light up fully and do not turn off or turn on twice when operating (i can tell because it's dimmer when it's normal operations and brighter when something is wrong). These LEDs that act off are completely random everytime i close my switch. Help? Any ideas what can be the problem? Here is my code. #include "msp430g2211.h" //P1.0 to P1.3 are rows //P1.4-P1.7 are col 1-4 //P2.6-P2.7 are col 5-6 void matrixMS (unsigned int); void delayMS (unsigned int); void matrix(); /*void main(void){ WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer P1DIR |= 0x41; // Set P1.0 to output direction for (; { volatile unsigned int i; // volatile to prevent optimization P1OUT ^= 0x41; // Toggle P1.0 using exclusive-OR i = 50000; // SW Delay do i--; while (i != 0); }; } */ unsigned int L[26]; unsigned int i,j,k,m,n; void main(void){ WDTCTL = WDTPW + WDTHOLD; P1SEL = 0; P2SEL = 0; P1DIR |= 0xFF; P2DIR |= 0xFF; P2OUT ^= 0xFF; P1OUT ^= 0xFF; for (k=0;k<25;k++){ L[k]= 1; } matrixMS(500); for (k=0;k<25;k++){ L[k]= 0; } matrixMS(500); for (;{ // do forever //start //sequence 1-flash 250MS delay for (m=0;m<10;m++){ for (k=0;k<25;k++){ L[k]= 1; } matrixMS(250); for (k=0;k<25;k++){ L[k]= 0; } matrixMS(250); } //end sequence 1-flash 250MS delay }//end forever loop }//end main class void matrix(void){ //toggle on then off of LED if set to activate if(L[1]==1){ P1OUT ^= 0x12; P1OUT ^= 0x12; } if(L[2]==1){ P1OUT ^= 0x6; P1OUT ^= 0x6; } if(L[3]==1){ P1OUT ^= 0xC; P1OUT ^= 0xC; } if(L[4]==1){ P1OUT ^= 0x24; P1OUT ^= 0x24; } if(L[5]==1){ P1OUT ^= 0x84; P1OUT ^= 0x84; } if(L[6]==1){ P1OUT ^= 0x4; P2OUT ^= 0x40; P1OUT ^= 0x4; P2OUT ^= 0x40; } if(L[7]==1){ P1OUT ^= 0x4; P2OUT ^= 0x80; P1OUT ^= 0x4; P2OUT ^= 0x80; } if(L[8]==1){ P1OUT ^= 0x1; P2OUT ^= 0x80; P1OUT ^= 0x1; P2OUT ^= 0x80; } if(L[9]==1){ P1OUT ^= 0x1; P2OUT ^= 0x40; P1OUT ^= 0x1; P2OUT ^= 0x40; } if(L[10]==1){ P1OUT ^= 0x81; P1OUT ^= 0x81; } if(L[11]==1){ P1OUT ^= 0x21; P1OUT ^= 0x21; } if(L[12]==1){ P1OUT ^= 0x9; P1OUT ^= 0x9; } if(L[13]==1){ P1OUT ^= 0x3; P1OUT ^= 0x3; } if(L[14]==1){ P1OUT ^= 0x42; P1OUT ^= 0x42; } if(L[15]==1){ P1OUT ^= 0x48; P1OUT ^= 0x48; } if(L[16]==1){ P1OUT ^= 0x60; P1OUT ^= 0x60; } if(L[17]==1){ P1OUT ^= 0xC0; P1OUT ^= 0xC0; } if(L[18]==1){ P1OUT ^= 0x40; P2OUT ^= 0x40; P1OUT ^= 0x40; P2OUT ^= 0x40; } if(L[19]==1){ P1OUT ^= 0x40; P2OUT ^= 0x80; P1OUT ^= 0x40; P2OUT ^= 0x80; } if(L[20]==1){ P1OUT ^= 0x10; P2OUT ^= 0x80; P1OUT ^= 0x10; P2OUT ^= 0x80; } if(L[21]==1){ P1OUT ^= 0x10; P2OUT ^= 0x40; P1OUT ^= 0x10; P2OUT ^= 0x40; } if(L[22]==1){ P1OUT ^= 0x90; P1OUT ^= 0x90; } if(L[23]==1){ P1OUT ^= 0x30; P1OUT ^= 0x30; } if(L[24]==1){ P1OUT ^= 0x18; P1OUT ^= 0x18; } } void matrixMS (unsigned int times){ //toggle LEDs constantly to make it look it constantly on times = times /100; for(i=0;i for(j=0;j<500;j++){ matrix(); } } } void delayMS(unsigned int times){ //program delay times = times/4; for(i=0;i for(j=0;j<1200;j++){ } } } Quote Link to post Share on other sites
nexusone1984 32 Posted June 4, 2011 Share Posted June 4, 2011 If it works on the Launchpad board and not project board. I would check your power supply, does it have enough current to drive the LED's and the MSP430? Also do you have filter capacitors or large enough ones to handle power spikes with the switching of the LED's on and off. Power spikes can make the MSP430 do weird things or too much load on the I/O pins. RobG 1 Quote Link to post Share on other sites
RobG 1,892 Posted June 4, 2011 Share Posted June 4, 2011 I second that Quote Link to post Share on other sites
EngIP 31 Posted June 4, 2011 Share Posted June 4, 2011 Your header is not for the right chip - 2211 doesn't have a port 2. Probably not the cause of your problem, but it's something to eliminate. Quote Link to post Share on other sites
oPossum 1,083 Posted June 4, 2011 Share Posted June 4, 2011 It has 2 I/O on port 2. Pins 12 and 13. EngIP 1 Quote Link to post Share on other sites
EngIP 31 Posted June 4, 2011 Share Posted June 4, 2011 I never noticed that! Thanks Quote Link to post Share on other sites
gordon 229 Posted June 4, 2011 Share Posted June 4, 2011 I am also thinking about adding something like this: RST --+---/\/\/\/--+- VCC | | | (this is the reset button) | ----- +---o o----+- GND | | +-----||-----+ with something like a 1..10uF tantalum capacitor. This is supposed to keep the MCU in reset a bit longer, possibly give the power rails a bit of a time to stabilize. @devilsnare: it is also a good idea to put a 0.1..10uF capacitor as close to the MCU as possible between VCC and GND. If you socket your chip, you can tangle it inside the socket so it doesn't take up space. (Quite naturally, I can't find a picture to illustrate this when I actually need one.) Edit: Found it. I saw it on our PhirePhly's blog, see ceramic capacitor inside a DIL socket. Quote Link to post Share on other sites
devilsnare 0 Posted June 4, 2011 Author Share Posted June 4, 2011 Did i mention am a complete amateur with no knowledge on electronics? But i have a 104 capacitor between VCC and GND and a 22K resistor from VCC to Reset I know the power source is fine because when it was on the Launchpad i unplugged USB and used the 3V power source to VCC and GND and it ran fine. Where and what else should put? Quote Link to post Share on other sites
gordon 229 Posted June 5, 2011 Share Posted June 5, 2011 104 is 0.1uF, which is OK-ish for putting it right near (i mean right near, as close as physically possible) the MSP's head between VCC and GND, but is way too small for generic buffer on the breadboard. For this latter purpose, you want electrolytic capacitors in the hundreds uF magnitude. Use them generously; I tend to put one in all four corners of the breadboard (assuming you have power connected to both sides of your board). The 0.1-10uF ceramic ones do wonders when put very-very close to the IC between the power pins. This you can do pretty much unconditionally for every IC you use. Sometimes it's not really needed, but it won't do harm either. You want to avoid tantalums here though (they won't harm either, but they may not deliver the desired effect). Observe polarity where applicable. (PS. can you please wrap your code posted above in tags?) Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.