Jump to content
43oh

sensor interface with launchpad msp430 using energia


Recommended Posts

Hello!

I novice when it comes to programming in general and I would like to ask a question. I am building a project where a sensor has to present some values to the micro controller (Iam using msp430F5529 launchpad). I am using the Energia environment to program and I have gone through the online tutorials available which tell you how to use the adc and have the sensor interact with the micro. But the sensor is attached to the microcontroller power supply in all the circuits. What if the sensor has a separate power supply (say 0-5V) and I want the adc in the micro to convert the analogue values from the sensor to digital values. How can I achieve that using the Energia platform.

Secondly how would i go about reading that data and displaying it on a 7 segment display.

 

I would really appreciate your replies. Any geniuses out there who can help me??

 

Regards! 

Link to post
Share on other sites

Not a genius but I may be able to help a bit.  As long as you tie the grounds between the two power supplies together then the output of the sensor will be readable by the ADC in the microcontroller.  However, you may need to condition the signal from the sensor so that it doesn't swing below ground or above the 3.3V supply of the microcontroller.  This can be accomplished with a resistor divider or an op amp circuit.  What is the full output swing of your sensor?

 

With regard to your question on the display you may want to google something like "microcontroller interfacing with 7 segment display" or similar.  Should yield both circuits and code examples you can use.

Link to post
Share on other sites

There's unfortunately no generic one-size fits all answer. The answer to your first question about reading the sensor all depends on what the sensor outputs. This will determine whether or not you have to do any modification before you feed it into the 430, and will also determine whether you use an inbuilt reference voltage or external reference voltage. For example if the sensor will output 0-2v you can connect it straight up to an analog input port and use the 2v or 2.5v internal reference. But if it outputs 0-5v you will somehow need to reduce it. How you go about that will depend on the specific device. You may be able to get away with something as simple as 2 resistors as a voltage divider, or you may need an op-amp. Things that will determine which method you use include factors such as the output impedance of the sensor, the rate of change of the outputs, and the accuracy you are desiring.

 

Now, question 2, how to output to a 7 segment display. Once again, the answer is "it depends". Will you will be driving multiple digits? Does your display use multiplexing, or does it require each segment to be driven directly? Or does the display have its own controller that uses an spi, i2c or other interface?

 

There are many possibilities for both the sensor and the display that it is impossible to provide a generic answer. The Energia coding will be highly dependent on the hardware. The code to output to a multiplexed 4 digit display, will look nothing like the code to output to a 8 digit spi display.

 

 

Sent from my iPad using Tapatalk

Link to post
Share on other sites

Do you need to maintain galvanic isolation between the sensor and the launchpad?  Instead of attempting to level shift, it might be worth just adding an isolated ADC to the sensor package.  The analog side would accept the 5V supply and read 0 to 5V (assuming rail to rail) while the digital side would be powered from the launchpad's 3.3V supply.  Instead of using the ADC on the MSP430, you would read theis chip over I2C or SPI.  It's likely a simpler package (circuit-wise) and will likely have better performance than the ADC built into the MSP430.

Link to post
Share on other sites

Hello!
Thanks for all the replies. My sensor output values are from 0-11.101mV (its a load cell) and like some of you have pointed out an op-amp would be required. I have sorted that problem out. Thanks for that. Turns out the load cell being powered by a different power supply isnt a problem as long as the the grounds are tied together and the out put does not exceed 3.3V as @@dubnet pointed out. I have worked out a code for the display as well using the all knowing ''google''.
Cant thank you guys enough for your advice. I hope I get good grades now =D 
Just a quick question on the side. 
As far as my knowledge goes Energia programming is pretty much the same as programming for an ardiuno. If I want to convert the data sent in ACSII from the serial communication to bits how do I go about doing that. From some basic C knowledge I know we can use the atoi function for that. But how would one use that in Energia. I want to perform arithmetic operations on the ASCII value I send in which is going to be a numberical value between 0-255. any help what so ever would be greatly appreciated. @@dubnet, @@grahamf72, @@mbeals, thank you very much to all three of you!! life savers you are I tell you!

Link to post
Share on other sites

I made a circuit of 4 load cells using a INA129. I use 3.3V as excitation voltage and power for the G2452 - no problems. You can easily adjust the (maximum) output voltage of the INA129 by choosing an appropriate trim potentiometer as the gain resistor.

What kind of load cell are you using?

 

Edit: Added Image.

 

 

post-31435-0-56406600-1390480446_thumb.jpg

Link to post
Share on other sites

Hi Yosh

Thanks for the reply!
I am using LCMKD-5kN load cell. But the out put of the load cell is no longer a problem! I think I have that sorted out with a instrumentation amplifier to achieve the complete range available by the adc (0-3.3V). Also the load cell I am using requires an excitation of 5V very precisely how ever like the good folks in the thread have pointed it if the grounds are tied together it should not pose any problems.

any ideas on how to convert the sent ascii data to actual numerical values? because see the other half of my project is to send an 8bit pressure value from the computer and then use a control loop to adjust the pressure on the load cell using a linear actuator. Send data is easy but how can i convert the ASCII characters to binary and use the values for my control loop!
Thanks!

Regards

Link to post
Share on other sites

Are you planning on interfacing with the device through a terminal (like putty), or programatically (labview, python, etc).  If you don't require a user friendly CLI, you don't have to mess with ascii at all.  The serial line is just transmitting single bytes at a time.  The translation to ascii characters and line termination is just one way of interpreting that byte data.  If all you are sending the unit is an 8 bit update to the pressure, then just write that byte straight to the UART.  This also lets you update faster, as using ascii encoding, you would need 4 bytes (3 digits plus termination) to represent a single byte of data.  The only downside is that you won't have a friendly terminal to watch or interact with...although there are terminal programs (I like realTerm) that let you change to formatting and read/write in raw hex/dec/binary as well as ASCII

Link to post
Share on other sites

@@mbeals Hi thanks for the reply!
I think I did not phrase my question properly. See I need to send in a value to the ardriuno that make the pressure say for examply ''10'' where 10 represents 10kgs of pressure and then the control loop in the program compares this reference value to the error and readjusts a linear actuator shaft exerting pressure on the load cell to reach this new pressure value . Now using UART and the serial monitor I know I can send data to the ardiuno. But as far as my knowledge goes this data is in the form of ASCII characters. 
There are two things I need to do with this data. 1.Display this on a seven segment display to show that this is the desired value. and 2. use this value in my control loop to perform some arithmetic operations so i can adjust my pressure value accordingly. Now can I use this value directly? or do I need to convert it to some binary form before I can do that?

And as always thanks for the interest and replies. :)

Link to post
Share on other sites

ASCII is a method to transmit text strings.  Each character (including numbers) has a coresponding 8 bit value.  So if you want to transmit the number 255 over uart via ASCII encoding, you send the btye string:  0x32 0x35 0x35 0x0D where 0xD is the line term char...it tells the receiving software that you are done sending chars and to process everything it just received as one blob of text.

 

If you send the number as an ascii string, the MSP will just have a four element buffer, which the control logic can't really use.  You have to write code (usually an atoi() function ) to decompose the ascii chars back into numbers and assemble them into a single number.    What I'm suggesting is to skip the ASCII conversion all together and just send the 8bit number the control loop needs over the UART as it is.  It eliminates all the conversion code on the MSP as well as the RX buffer and processing code...saves lots of valuable ticks.   For the LCD, just convert the number to ASCII on the MSP430 for display.  As long as your refresh rate on the LCD is less than the recieve rate of the updates, you will come out on top. (comverting every 5th or every tenth number as opposed to every number).

 

Let me ask you this.... what is sending the pressure data to the MSP430?  Is it software you wrote?

Link to post
Share on other sites

@@mbeals ohhh right right!! now that makes sense.

 

No actually for the purposes of my project the sending pressure value will be be a user input. As far as my limited knowledge goes, I was thinking of manually inputting the 8bit value in to the serial monitor and then the code uses that value. But I have a strong feeling now that wont be right. After reading your thorough  explanation I think it might not be a good idea to do that. what do you think I should do? what would be the simplest way around this problem?
Thanks again!!

Link to post
Share on other sites

I mean how do I send in an 8 bit value for my program. it just needs to be some 8 bit value defined by the user. so what would be the simplest way to achieve that? take this analogy for example. i use a key pad to punch in the value of the required pressure. Now instead of the key pad lets have a computer. and I need to input the value in the computer and the thats where the msp430 takes it reference value from to begin executing the control loop. i hope that was clearer?

Link to post
Share on other sites
 I was thinking of manually inputting the 8bit value in to the serial monitor and then the code uses that value.

 

 

Okay.  So it sounds like you want to interface with a generic serial terminal (Putty, minicom, etc) and not write a custom piece of software for the computer side of things.  It also sounds like a fairly low update rate to the MSP (if the user is hand typing things in).   In this case just do the string conversion on the MSP.   You might be able to use the implementation of atoi() in stdlib...if not it is a simple enough function to write.  Then you just need some code to buffer the incoming characters.  There are lots of examples here on this forum if you look, but the basic flow is to create a global array then use the UART rx interrupt to push incoming chars into the array.  Have it watch for the line term char ('\n') and set a flag when it sees it.  Your main loop looks for the flag on every loop and if it sees it, processes the buffer as a new pressure value and clears the flag.

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