EmbeddedRelated.com
Forums
The 2024 Embedded Online Conference

Voltage Response Toggle C-Code

Started by jake76549 April 9, 2011
Hi,

I'm very new to the micro controller scene and have picked up the MSP430 LaunchPad to try some basic experiments. I went through the intro online class videos and learned upload code successfully.

Currently I'm trying to research some example code that will allow the MSP430G2231 to toggle the LEDs on the Launchpad based on certain voltage inputs. I'd like to hook up an amplified sensor and have the MSP430 toggle LEDs at pre-determined voltage settings the sensor would provide at given levels.

An example could be a touch sensor on a robot arm. If too much pressure is applied, the respective voltage output of the sensor to the micro controller would be above a determined value and cause the controller to toggle on an LED on the LaunchPad.

I'm not asking anyone to write all the code for me, just some examples and short cuts I can put together would be nice. Thanks!!!

Beginning Microcontrollers with the MSP430

The 2231 has an ADC so you can do the whole thing on the chip, like move
the threshold. And what are you thinking of using? Something like this?

http://www.robotshop.com/interlink-02-circular-fsr.html

Best, Dan.
Hi,

I have sample code for MSP430F2013. There is a different ADC on board
although. My application was an impedance meter with (max) 15 levels set
by defines. I think it is some 30 lines of code in total. With 25Hz
generator and a synchron rectifier. Your application should be some 20
lines shorter. I can send it to you if you wish but I do not the code
handy (I'm in NYC now). I'm back in my office by Thursday. So if you do
not have a solution until than drop me an email. Actually your application
has to initialize some kind of timer and in the interrupt routine
initialize the ADC, read the value, check the threshold and lite (or not)
the LED. The main routine is to set the timer, ADC params and let the uC
sleep.

Waldemar
I'm actually interested in a gas/air pressure sensor. The touch sensor was just an example. At the moment, I really just want to put together a bench setup that I can apply pressure and vacuum to the sensor and get a visual LED response. I'll set the setpoint in the code, and adjust it by editing the code. But that's my current problem, the code haha. Any done anything like this? I found an educational site that at one point went through this same experiment, but their files are no longer hosted on the site. Would have been nice to go through the class assignment and learn something.
Hi Jake,

The simplest way to have programmed response from an analog voltage is to use the ADC (analog to digital converter). Based on what ADC you have it will either be a 10 bit system or a 12 bit system (don't think the 2xxx have anything higher). With the most basic setup of the ADC, 0V input into the ADC will give you a value of 0 (or close to it) at V+ (assume 3V) it will give you about 1023 (for 10 bit) and 4095 (for 12 bit), thus 1.5V input will give you about 511 or 2047. If you do not know how to initialize the ADC either look at your example code provided by TI or learn to use the GRACE add-on to Code Composer Studio V4 (CCSv4). If you do not know if your ADC is 10 or 12 bit look at your data sheet it will tell you (GRACE will know which one it is too). This may seem like a very simple step, but learning to use resources and how to initialize peripherals in the MSP430 will make your life a lot easier.
Once you have the ADC values stored into a variable it is a simple:



If you do not know how to light an LED, again look at example code from TI or other online resources. It is better for you to learn it that way, than for us to just tell you.

Hope that gives you a better idea of what an ADC does, and how you could use it.

best regards,
Jake G.

PS: The example code should also show you how to sample the ADC not just initialize.
jake76549 wrote:
> I'm actually interested in a gas/air pressure sensor. The touch sensor was just an example. At the moment, I really just want to put together a bench setup that I can apply pressure and vacuum to the sensor and get a visual LED response. I'll set the setpoint in the code, and adjust it by editing the code. But that's my current problem, the code haha. Any done anything like this? I found an educational site that at one point went through this same experiment, but their files are no longer hosted on the site. Would have been nice to go through the class assignment and learn something.


Hi Jake,
I have not done the research. You will have to. Are you talking about
something like the MPX series sensors? I've played around with them a
bit. Most sensors work the same. The research; setting vref on the 14
pin device doesn't look doable. The RSA package, the data sheet I have
is not clear. (research...) If I were doing this, I'd be looking at the
2013. At that, it looks like if you set the analog voltages for the 2231
you loose accuracy:

(1) The external reference is used during conversion to charge and
discharge the capacitance array. The input capacitance, CI, is also the
dynamic load for an external reference during conversion. The dynamic
impedance of the reference supply should follow the
recommendations on analog-source impedance to allow the charge to settle
for 10-bit accuracy.
(2) The accuracy limits the minimum positive external reference voltage.
Lower reference voltage levels may be applied with reduced
accuracy requirements.
(3) Under this condition the external reference is internally buffered.
The reference buffer is active and requires the reference buffer supply
current IREFB. The current consumption can be limited to the sample and
conversion period with REBURST = 1.
(4) The accuracy limits the maximum negative external reference voltage.
Higher reference voltage levels may be applied with reduced
accuracy requirements.
(5) The accuracy limits the minimum external differential reference
voltage. Lower differential reference voltage levels may be applied with
reduced accuracy requirements.

See, that is where your journey starts. Back of the napkin, weigh your
expectations against the reality of your hardware. A low drift op amp to
buffer? More research. If you can't find the numbers in the specs, do
the experiments. Someone's posted code and off you go, good luck with
that...

Best, Dan.
So I've learned a bit more and found a good example or two. Basically threw the following code together to set both the red and green LED on the launchpad for a given input voltage to A1. If the input is less than 3V, the green LED will be illuminated, and if over 3V, the red LED will be illuminated. The only funny thing I noticed is the transition will take place at around .2V before and after the 3V set-point. Could this be because of 'dirty' fluctuating power from my manipulated wall-wart power supply? Feel free to comment on the code for any improvements you can see. Thanks!


The 2024 Embedded Online Conference