BasicMicroUK - Forums

www.basicmicro.co.uk
It is currently Sat Jan 20, 2018 7:53 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Problem porting code from BS2 for Melexis ML90614 IR sensor
PostPosted: Sat Jun 13, 2009 1:10 am 
Hello Happy People! A little brainteaser for you. Parallax has made available a rather nifty IR temp sensor package with a coprocessor to manage the serial comms. Using their code, I have been able to get the sensor to work on a basic stamp 2, no problem. Difficulty is in getting it to work on the Atom 28. I seemed to have tried everything and I only ever seem to get zeroes. Since this is Kelvin, ie. Absolute Zero, this is unlikely!

I have checked all the obvious things like power and continuity and have tried a lot of variations on timings, pauses (Atom faster than Basic Stamp 2), baudrates, differerent baudmodes, external and internal pullups. Still no joy.

More info on parallax site; melexis datasheets and parallax app note. (can't upload a pdf to this forum). Be happy to email you everything I have. If so, email me at rupert@ruperthart.com.

My head hurts from trying everything; am on version 102 of the code. Would be happy to provide a small reward for anybody who solves the problem. Will it be you?!?

Hope you can help.
Best regards,
Rupert

Below are 1. Basic Stamp 2 code and then 2. Basic Atom code.

1. Basic Stamp 2 Code (simplified from Parallax site; works fine using BS2):

' =========================================================================
'
' File....... MLX90614_Demo-Simple.BS2
' Purpose.... Demo Code for MLX90614 Infra Red Thermometer Module
' E-mail..... support@parallax.com
' Started....
' Updated.... 01 SEPT 2008
'
' {$STAMP BS2}
' {$PBASIC 2.5}
'
' =========================================================================

' -----[ Program Description ]---------------------------------------------
'
' This program demonstrates the MLX90614 Infra Red Themometer Module by
' reading the temperature, calculating C and K, and running a CRC check on
' the PEC value for data integrity.
'

' -----[ I/O Definitions ]-------------------------------------------------

Reset CON 1
Alarm CON 2
Sensor CON 3

' -----[ Constants ]-------------------------------------------------------

baud CON 84
xslave CON $5A 'slave address

' -----[ Variables ]-------------------------------------------------------

temperature VAR Word
tempL VAR temperature.LOWBYTE
tempH VAR temperature.HIGHBYTE
pec VAR Byte
Kelvin VAR Word
KelvinDec VAR Word
Celsius VAR Word
CelsiusDec VAR Word
w VAR Byte
x VAR Byte
y VAR Byte
z VAR Byte

' -----[ Initialization ]--------------------------------------------------

Init:
LOW Reset
INPUT Reset
DEBUG CLS, ' setup report screen
"MLX90614 Infra Red Thermometer", CR,
"=============================", CR,CR,
"Kelvin......... ", CR,
"Celsius........ ", CR,
"PEC test....... ", CR

' -----[ Program Code ]----------------------------------------------------

getTemperature:
SEROUT Sensor,baud,[0,"!TEMR",xslave,$07]
SERIN Sensor,baud,1000,PECfail,[tempL,tempH,pec]

checkPEC:
z=0
y = xslave<<1+0
GOSUB calculateCRC
y = $07
GOSUB calculateCRC
y = xslave<<1+1
GOSUB calculateCRC
y = tempL
GOSUB calculateCRC
y = tempH
GOSUB calculateCRC
IF z<>pec THEN PECfail
GOTO convertTemperatures

calculateCRC:
w=z^y
READ w,z
RETURN

convertTemperatures:
Kelvin = (temperature/100)*2
KelvinDec = temperature*2
IF (temperature*2) < 27315 THEN overWordsize
Celsius = (temperature/100*2)-273
CelsiusDec = (temperature*2)-27315
GOTO displayTemperatures

overWordsize:
Celsius = ((27315-(temperature*2))/100)
CelsiusDec = (27315-(temperature*2))
DEBUG CRSRXY, 23, 4,"-",DEC Celsius,".",DEC2 CelsiusDec, CLREOL

displayTemperatures:
DEBUG CRSRXY, 23, 3,DEC Kelvin,".",DEC1 KelvinDec,CLREOL
DEBUG CRSRXY, 23, 4,DEC Celsius,".",DEC2 CelsiusDec, CLREOL
DEBUG CRSRXY, 23, 5,"Pass",CLREOL
PAUSE 1000
GOTO getTemperature

PECfail:
DEBUG CRSRXY, 23, 3,CLREOL,CR
DEBUG CRSRXY, 23, 4,CLREOL,CR
DEBUG CRSRXY, 23, 5,"Fail",CLREOL,CR
PAUSE 500
GOTO getTemperature



2. Basic Micro Code for Atom 28. Can't get it to work.



'Basic Micro Atom 28


' =========================================================================

' -----[ I/O Definitions ]-------------------------------------------------

Reset CON 1
Alr CON 2
Sensor CON 3

' -----[ Variables ]-------------------------------------------------------

temperature VAR Word
tempL VAR temperature.LOWBYTE
tempH VAR temperature.HIGHBYTE
pec VAR Byte
slave VAR Byte


Main:
gosub Init
gosub gettemperature
end

Init:
LOW Reset
pause 1000
INPUT Reset
pause 50
return

getTemperature:
SEROUT Sensor,neo2400,[0,"!TEMR",$5A,$07]
pause 50

again:
SERIN Sensor,neo2400,1000,PECfail,[tempL,tempH,pec]
pause 40

displayTemperature:
serout s_out,i9600,[DEC temperature, " , ", dec pec, 10,13]

goto again
return

pecfail:
serout s_out,i9600,["pecfail", 10,13]
return


Top
  
 
 Post subject: Re: Problem porting code from BS2 for Melexis ML90614 IR sen
PostPosted: Thu Sep 09, 2010 3:57 pm 
Offline
Citizen

Joined: Mon Aug 30, 2010 2:06 am
Posts: 7
Did you ever get this to work? I am having the same problem. It will work on basic stamp quite well, but not on Atom 28. Just get zeros. Tried just about everything with no luck.


Top
 Profile  
 
 Post subject: Re: Problem porting code from BS2 for Melexis ML90614 IR sen
PostPosted: Thu Sep 09, 2010 5:43 pm 
Offline
Site Admin
User avatar

Joined: Thu Mar 01, 2001 7:00 pm
Posts: 1316
Location: Temecula, CA
Well, first I can tell you, you can't hust use the BS2 baud rate value. It's completely wrong. You need to find out what the baudmode is(9600bps, 2400bps etc) and then use the correct baud mode on our module. You say you are using an Atom 28. I am assuming thi sis NOT an AtomPro 28 though lots of people fail to correctly identify the module they use. Since you baud mode is definitly wrong you willl never get this code to do anything until that is fixed.

So your BS2 baud mode is 84. In the BS2 manual it says that means you are using 9600bps at 8N1 settings. So on the Atom or AtomPro use the i9600 predefined baudmode. If you want to calculate the numeric value for the baud mode you can but the work has already been done for you so I suggest using the i9600 baudmode. Note that the new beta manual defines how to calculate the numeric value for the baudmode. I don't see how you got 2400bps for your BS2 baud mode. Assuming a BS2 84 is 9600bps(1000000/9600)-20=84. Also NEO is completely wrong as well. BS2 is not using open drain I/Os and it's not using even parity. And n means non-inverted. Normal serial is inverted which is what the BS2 baudmode specifies. Thats how I get i9600.

Also I suggets you change the W variable to something else. What does W stand for? W is used in inline asm commands on an Atom module so you can have conflicts if you try using W as a variable. It probably will work but I suggest not tempting fate since you've already had a hard time.

_________________
Tech Support
Basic Micro - Robotic Technology Evolved


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

phpBB SEO