PDA

View Full Version : Tilt Sensor Reading



sincity337
- 14th September 2010, 06:14
Hi Folks,

I've read and read and I am in need of some advice. I am completely green, and I would appreciate a push in the right direction. Here is what I am trying to do. I have an electronic tilt sensor that outputs a 4 byte HEX string on a RS232 line when an ASCII character is sent to it. For example, if I send it a "C" via a terminal program, it may respond with 85F (2143), the last byte isn't shown as it is a CR. To get an actual angle I need to do this: (2143-2048) * .0125. Which turns out to be 1.18°. BTW 2048 and .0125 are static variables.
I've only successfully been able to send the ASCII character from my pic to the tilt sensor and what I end up getting back is nonsense. I guess what I am having a hard time with is how I go about setting up my variables to be able to receive my 4 byte string (ignoring the last) and then correctly displaying it on my LCD.
Am I looking at setting up an array, naming the bytes in the array doing the math and then send those bytes out to the LCD?

Currently I am using a 16F877A on a LABX1 board.

I'm sorry, what I have so far is at work, as soon as I get back on Wednesday I can post what I have so far. It is ugly, and I welcome any constructive advice.
Please be patient, I haven't messed with any of this stuff in about 6 years, and even then the most I did were the examples from the RCG Research class!:o

rsocor01
- 14th September 2010, 06:50
sincity337,

It would be better if you post the datasheet of the tilt sensor. Without the datasheet it would be hard to help you :).

Robert

sincity337
- 14th September 2010, 08:24
Here is a link to the data sheet...

http://www.spectronsensors.com/appsheets/SSY0135%20-%20RS232%20%28MICRO-50%29%20Signal%20Conditioner%20Operating.pdf

rsocor01
- 14th September 2010, 08:57
I've only successfully been able to send the ASCII character from my pic to the tilt sensor and what I end up getting back is nonsense. I guess what I am having a hard time with is how I go about setting up my variables to be able to receive my 4 byte string (ignoring the last) and then correctly displaying it on my LCD.

What exactly are you getting back? Remember to display a number greater than 2048 you need to define the variable as a WORD (or LONG).

sincity337
- 18th September 2010, 20:17
Let me caveat this by saying I am a schlub and forgot to look and find out what version
of PBP I am running currently. I just received the upgrade disk for 2.60 yesterday, and will take it to work next week.

Here is a snippet of one of the variations of the code I have tried:



sd_tran VAR portC.6
sd_receive VAR portC.7

hexout VAR BYTE[4]
one VAR hexout[0]
two VAR hexout[1]
three VAR hexout[2]
four VAR hexout[3]

mainloop:
serout2 sd_tran, 32, ["C", 13, 10]
pause 200
serin2 sd_receive, 32, [hexout]
pause 200
LCDOUT $fe, 1, HEX one, HEX two, HEX three, HEX four
PAUSE 500
GOTO mainloop
END

What I get displayed on the LCD looks something like this 5F 00 00 00

What I am trying to do is display the actual hex string of characters that I get back from
the sensor. When connected to the computer via a terminal window, I usually get back something like "7AF", the last character is an ASCII "10" which get's dropped in the terminal window because it is a line feed. What I would like to display would be the whole four byte string, like "7AFA". Once I can do that, I know I can do the math to be able to get my angular number. I know it is a matter of telling PBP which bytes to to receive, store, retreive and display, but the correct way to do that is eluding me at the moment. I've tried various combination's of the SERIN2, LCDOUT, and BYTE or WORD variable to no avail. I keep getting very unlikely numbers.
Any assistance would be greatly appreciated.

aratti
- 19th September 2010, 09:58
sincity337

Remove the PAUSE 200 between serout2 and serin2. Pause in that place will delay the receiver and you will loose characters.

Cheers

Al.

sincity337
- 20th September 2010, 05:23
Thanks, I'll give that a shot, I appreciate it.