Jump to content

C coding help needed for new project

Recommended Posts

I know some of you C experts out there could whip up a sample program for my new project in probably minutes, even if not perfect I could use my limited skills to test and refine it.

I just ordered the Launchpad and hope to make a special application board. First of all I am much better at circuit soldering and debugging than I am at coding (very inexperienced, especially C++).. If I had some examples I could work with them and expand them I think. Its all the necessary setups and interrupts and such that I need to get past.


What I want one of the 'included' msp430's to do is Read two switches, setup appropriate timers, set LED's and also drive a relay.


Switch one - 4 position, OFF, 10 Min, 30 Min, 60 Min, --- this will determine the "Frequency" of the second (duration) timer.


Switch two - toggle off or on, represents 5 Min, or 10 Min, --- this will determine the "Duration" timer


LED one - shows that the Frequency timer is active (sw one not off)


LED two - shows that the Duration timer is active (in the middle of a cycle)


When the Duration timer is running, it controls the amount of time that an external relay is set.


The primary Voltage supply is a 12 volt lead acid battery, so I know that some sort of regulator circuit or voltage divider circuit will need to be designed to get the msp430 levels down to 3 volts.


Also needed will be an external FET or power transister tied to one of the output pins as driven by the Duration timer. This relay will be switching the original 12 volt levels to drive a pump.


Some questions come to mind such as -- should the switch positions be polled or interrupt driven? Is the watchdog needed? I am not too concerned about operating the msp430 at the most low levels and conserving power since I really don't think it would be a serious enough draw from the main source it it were on all the time.


Any/all ideas, coding examples, and input voltage dividing examples would be very much appreciated. thanks

Link to post
Share on other sites

Just an FYI- people will most likely not write any code for you if you ask......best to write what you think it whould be and we will point out how to correct it....another point is I use MSPGCC and what if you us CSS, you will still have to change the code to work for you too.

but lets get started with your project, - First you can do this either by polling or interrupt. This is your choice and depends on if you can be a few milliseconds off or not.

Second you will need a voltage regulator for your MPS430, a voltage divider will work, but it would be better and assure you of a more stable power source for your msp430. example regulator would be the 7803 (+3v) or 7805 (+5v) regulators


check this post for a great timer example viewtopic.php?f=9&t=181

Link to post
Share on other sites

Thanks for the reply, and you are right, I am working on my C program right now. I haven't decided whether to poll or not, timing is not critical nor is power consumption so which ever is easiest will probably work. I have already ordered a sample of an LTC3388EMSE-1#PBF from Linear since it sounded like it would do the job good for a regulator. I have found and collected a bunch of C++ coding examples and I plan on stealing a little code from where ever I can and piece together something and then start testing. thanks again

Link to post
Share on other sites


Your project sounds familiar. Are you going to use this in an automotive environment? Just curious. Since its 12 volt lead acid you can use many popular vehicle cell phone chargers to get well regulated 3 and 5 volts for the msp430. If the size of your project is no concern then you could always use a couple of "D" size batteries to power the msp430 instead of the 12 volt source used for the pump or even a small lipo setup to recharge from the 12volt. (the msp430 uses very little power and can be made to run a long time on a couple of D cells). Have you considered using 555 or 556 timers instead of the msp430? or do you need the processing capabilities to manage usage? This could be done with a multi-vibrator and schmidt trigger set up.

Polling at intervals the switch input may be the easiest implementation in your case noting that you said it is not time critical. That way there will be a slight delay (between when the time interval resets and the polling checks start again) after you set the button and the timer starts over with the correct input value.

A little more information about your project and what your design constraints can give us a better idea of where you are heading for us to give you feedback to steer you out of any set backs you may encounter along the way.


I hope this helps some way.

Link to post
Share on other sites

infrared, thanks for the interest.. I am making a "live-well aerator control system" for my fishing boat. When I take my boat to Minnesota each year (where I grew up) one of the more popular baits are a variety of live minnows. When I am up at a lake for a couple of weeks, the tendency is to leave the minnows in the boat's live tank overnight along with any late caught fish that I didn't want to clean that night. Rather than leave the tank pump on all night and drain my boat battery, I wanted a way to have the pump come on at selectable times and durations. I first looked at timer chips and op amps and a lot of discrete components, but someone suggested a micro-controller for the job and I looked into it and it seems like a better approach. I have it working on my breadboard except for the voltage regulator and I would like to see if I can make a simple LM117 or LM317 work for me. Going to radio shack today to see if I can find one.

Link to post
Share on other sites

the lm chips are a good choice although you can get 20 of them for what radio shack charges. A 7803 or 7805 is a better all around choice because it uses less external components compared to the lm chips. Also, in your circuit I would isolate the 12 volt relay from the msp430 in case the pump stalls or some other event burns the relay out and shorts it to the low voltage side which will burn the msp430 out as well.


Not trying to discourage your original plan (you know your setup and requirements better then anyone). But couldn't you design a 12v power supply to run off mains that you could tie in to your boats charging system (maybe at the battery compartment bring out a quick connect to plug a computer power supply that powers your live well aerator?). Or even a 120v mains aerator that sits along side the 12v one.

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.

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...