Jump to content
43oh

Aquarium Controller


Recommended Posts

Got it to load the code for a blinking LED, but I can't get the LED to blink. Again, I'm using the launchpad to program the 430 which is on a breadboard. CCS tells me that the code is loaded.

I've tested the LED and know that it works with the supplied voltage at VCC. I've moved the jumper wire to every pin and the only ones that make my LED light are VCC and the RST connection.

 

 

Disregard all above. I unplugged the launchpad from my USB port and plugged it back in and the LED is blinking now. Guess it just needed a reset. Gonna try the switch code again.

 

Same with the switch sample code. Wouldn't work until I unplugged the USB cable, waited a sec, then plugged it back in again. Must be a windows thing lol.

 

Glad I'm keeping this log now. Hopefully someone else will read this and will be able to fix their problem.

Link to post
Share on other sites

I could use a little help here figuring this one out.

So I'm running this code...

 

#include <msp430g2553.h>

int main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
// Setup the pins
P2DIR = 000111; //Set P2.0, P2.1, P2.2 to output direction

for (;;)  // This empty for-loop will cause the lines of code within to loop infinitely
{
// Turn on LEDs.
P2OUT = 000001;  //Turn on LED1 at pin2.0
__delay_cycles(1000000);  // Delay for 1sec
P2OUT = 000011;  //Turn on LED2 at pin2.1
__delay_cycles(1000000);  // SW Delay of 1M cycles at 1Mhz, Delay for 1sec
P2OUT = 000111;  //Turn on LED3 at pin2.2
__delay_cycles(1000000);  // SW Delay of 1M cycles at 1Mhz, Delay for 1sec

// Turn off LEDs
P2OUT = 000110;  //Turn off LED1 at pin2.0
__delay_cycles(1000000);  // SW Delay of 1M cycles at 1Mhz, Delay for 1sec
P2OUT = 000100;  //Turn off LED2 at pin2.1
__delay_cycles(1000000);  // SW Delay of 1M cycles at 1Mhz, Delay for 1sec
P2OUT = 000000;  //Turn off LED3 at pin2.2
__delay_cycles(1000000);  // SW Delay of 1M cycles at 1Mhz, Delay for 1sec

} //End for loop
} //End main
 

 

and pin 2.0 is working as it should, but pin 2.1 and 2.2 are not. Instead pin 2.3 is acting as pin 2.1

I've tested every other pin and nothing else is turning on LEDs except pins 2.0 and 2.3

How can this be if in my pin setup I made pin 2.3 an input? And no where in my code do I have 2.3 become active.

Link to post
Share on other sites

I wonder if an external RTC and ambient light sensor would be a worthwhile substitute for the push button.

 

RTC keeps time and the ambient light sensor (standing in for the push button) is only operable when the RTC says the time of day coincides with sunrise and sunset.

 

An RTC, a serial port, an EEprom with sunrise/set tables and a battery backup would be all you need.  Once you fire it up the first time, set the time/date over the UART and let it run.

Link to post
Share on other sites

 I unplugged the launchpad from my USB port and plugged it back in and the LED is blinking now. Guess it just needed a reset. Gonna try the switch code again.

 

Same with the switch sample code. Wouldn't work until I unplugged the USB cable, waited a sec, then plugged it back in again. Must be a windows thing lol.

 

Glad I'm keeping this log now. Hopefully someone else will read this and will be able to fix their problem.

This is a common/known issue. Annoying, happens sometimes under the osx too.

 

Just FYI,

 

About the code supplied by SirPatrick, it doesn't start from the minimum step till the maximum step.

It starts from servo_lut[0] = 661 and ends at servo_lut[180] =  arround 2640. 181 steps

So the noted duty cycle 0-100% is not managed.

 

The following

// Go to 0
Link to post
Share on other sites

Sorry for the delay in responses. Been real sick with the flu the past couple days so I barely got out of bed yet alone thought of this project. I'm going to spend a few hours now working on it again to get three pins worth of LEDs to light in sequence and I'll report what I come up with or what problems I run into.

Link to post
Share on other sites

I I tried a bunch of different things, but lastly I set P2DIR=00111111 so all pins where outputs. I then set P2OUT=00111111 so all pins should be on constantly, but only pins P2. and P2.3 light up LEDS so I'm assuming that somehow my chip got messed up. I'm going to test to see if they work as inputs but I'm assuming they won't.

 

Yep, P2.1 would not work as an input. Either there is something I'm missing or this chip is damaged. I'm limited on time and supplies right now so I'll have to make due with what I got.

Link to post
Share on other sites

OMG, I'm an idiot. This entire time I haven't been putting the pin directions in as a hexformat, so that's why the pins haven't been working. I just tried turning on all the P2 LEDs and they all work.

 

Note. When entering pin directions, it has to be in this format: 0xYY where YY is the hexdecimal. It will not accept it as binary like I thought it would.

 

I know, this sounds stupid to most, but I'm not a programmer, and the documentation I've read never said it had to be converted prior to typing it in code. But at least now I know, and maybe someone else will learn from my mistake.

Link to post
Share on other sites

Thank you abecedarian, I'll have to try that sometime as I prefer working with binary at this time rather than hex because it's easier to see what pins are doing what.

Although almost all sample code I've seen does it in hex so I'm assuming that is the norm so I'm going to force myself to learn it that way though.

 

As a reminder, when loading new code the previous pins that had LEDS on would flash right before the code finalized. Because I was running 6 LEDs, this caused a voltage drop from my USB so my compiler thought that the launchpad was unplugged and I got an error. If this happens, try ungrounding the LEDs so they don't pull any current until after the code has finished loading.

Link to post
Share on other sites

Been working on this for the better part of the day but I finally got some working code that I like. I had to do a lot of background research but this page helped me a lot with the code for the switch ISR (Interrupt Service Routine).

http://processors.wiki.ti.com/index.php/MSP430_LaunchPad_Interrupt_vs_Polling

 

I'm still not 100% understanding of what each line does but I do understand whats going on in the background and another reading from this page would probably help me get to 100%.

http://processors.wiki.ti.com/index.php/MSP430_LaunchPad_PushButton

 

So here is my working code. All it does so far is sit in low power mode waiting for someone to press a switch from low to high. It then turns on three LEDs, waits 10sec, then turns them off.  Next step is to work on the servo control again but I won't be able to get to that till Friday.

 

 

#include <msp430g2553.h> // My specific chip

void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
P2DIR |= 0x7; // Set P2.0, P2.1, P2.2, to output direction
P2OUT = 0x0; //Turn all P2 off
P1IE |= BIT3; // P1.3 interrupt enabled
P1IES |= BIT3; // P1.3 Hi/lo edge
P1IFG &= ~BIT3; // P1.3 IFG cleared

_BIS_SR(LPM4_bits + GIE); // Enter LPM4 w/interrupt
}

// Port 1 interrupt service routine
#pragma vector=PORT1_VECTOR
__interrupt void Port_1(void)
{

// Morning Sequence

P2OUT = 0x1;  //Turn on LED1
__delay_cycles(5000000);  // Delay for 5sec
P2OUT = 0x3;  //Turn on LED2
__delay_cycles(5000000);  // Delay for 5sec
P2OUT = 0x7;  //Turn on LED3
__delay_cycles(5000000);  // Delay for 5sec

// servo commands will go here

__delay_cycles(5000000);  // Delay for 5sec, but will be turned into 10hrs

 

// End of Day Sequence
P2OUT = 0x6;  //Turn off LED1
__delay_cycles(5000000);  // Delay for 5sec
P2OUT = 0x4;  //Turn off LED2
__delay_cycles(5000000);  // Delay for 5sec
P2OUT = 0x0;  //Turn off LED3
__delay_cycles(5000000);  // Delay for 5sec

P1IES ^= BIT3;
P1IFG &= ~BIT3; // P1.3 IFG cleared
}
 

Link to post
Share on other sites

Glad you are feeling better spoil, It is always good to get back to the hacking! Anywhoo, a few notes about your code. You shouldn't waste your time with writing the hexadecimal representations of the pins, instead use the predefined names (BIT0,BIT1,BIT2..etc). Also look into using boolean operators NOT,AND,XOR etc. 

 

 

To to turn on BIT1 on port 1 you can do

 

 

P1OUT |= BIT1;

 

 

Then to turn BIT1 off you would do

 

 

P1OUT &= ~(BIT1);

 

If you are toggling a bit inside of loop you can XOR it instead of explicitly turning it on and then off.

 

 

P1OUT ^= BIT1;
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...