Question about the MLX90614
Hello to all...I have purchased one of the above infrared sensors from Parallax.· In playing round with the device, I can't seem to figure out what all the DATA statements are for, or where they came from or where they are called in the example code.· I see no, for example, READ PEC0, or READ PEC1........etc.· The example code isn't that really easy to understand.· This includes the x,y,z stuff?· I have looked thru the documentation and, maybe I missed something, but it appears that the ducumentation put out by the developer of the infrared device, by it self doesn't really explain the package that Parallax put out.· Please correct me if I am wrong on this.
DenO
DenO
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
w=z^y
READ w,z
RETURN
However, all the DATA statements have labels...PEC0...PEC1...PEC2...etc. Is w,z the address of the READ? Very confusing code writing, isn't it?
DenO
DenO
Thank you
Deno
'================[noparse][[/noparse]DEMO CODE BELOW THIS LINE]================
' =========================================================================
'
'·· 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}
'
' =========================================================================
'
[noparse][[/noparse] 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.
'
'
[noparse][[/noparse] I/O Definitions ]
Reset······· CON···· 1
Alarm······· CON···· 2
Sensor······ CON····3
'
[noparse][[/noparse] Constants ]
baud········ CON··· 84
xslave······ CON··· $35··························· 'slave address
'
[noparse][[/noparse] 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
Ferenhite··· VAR··· Byte
w··········· VAR··· Byte
x··········· VAR··· Byte
y··········· VAR··· Byte
z··········· VAR··· Byte
'
[noparse][[/noparse] EEPROM Data ]
PEC0·· DATA $00,$07,$0E,$09,$1C,$1B,$12,$15,$38,$3F,$36,$31,$24,$23,$2A,$2D
PEC1·· DATA $70,$77,$7E,$79,$6C,$6B,$62,$65,$48,$4F,$46,$41,$54,$53,$5A,$5D
PEC2·· DATA $E0,$E7,$EE,$E9,$FC,$FB,$F2,$F5,$D8,$DF,$D6,$D1,$C4,$C3,$CA,$CD
PEC3·· DATA $90,$97,$9E,$99,$8C,$8B,$82,$85,$A8,$AF,$A6,$A1,$B4,$B3,$BA,$BD
PEC4·· DATA $C7,$C0,$C9,$CE,$DB,$DC,$D5,$D2,$FF,$F8,$F1,$F6,$E3,$E4,$ED,$EA
PEC5·· DATA $B7,$B0,$B9,$BE,$AB,$AC,$A5,$A2,$8F,$88,$81,$86,$93,$94,$9D,$9A
PEC6·· DATA $27,$20,$29,$2E,$3B,$3C,$35,$32,$1F,$18,$11,$16,$03,$04,$0D,$0A
PEC7·· DATA $57,$50,$59,$5E,$4B,$4C,$45,$42,$6F,$68,$61,$66,$73,$74,$7D,$7A
PEC8·· DATA $89,$8E,$87,$80,$95,$92,$9B,$9C,$B1,$B6,$BF,$B8,$AD,$AA,$A3,$A4
PEC9·· DATA $F9,$FE,$F7,$F0,$E5,$E2,$EB,$EC,$C1,$C6,$CF,$C8,$DD,$DA,$D3,$D4
PEC10· DATA $69,$6E,$67,$60,$75,$72,$7B,$7C,$51,$56,$5F,$58,$4D,$4A,$43,$44
PEC11· DATA $19,$1E,$17,$10,$05,$02,$0B,$0C,$21,$26,$2F,$28,$3D,$3A,$33,$34
PEC12· DATA $4E,$49,$40,$47,$52,$55,$5C,$5B,$76,$71,$78,$7F,$6A,$6D,$64,$63
PEC13· DATA $3E,$39,$30,$37,$22,$25,$2C,$2B,$06,$01,$08,$0F,$1A,$1D,$14,$13
PEC14· DATA $AE,$A9,$A0,$A7,$B2,$B5,$BC,$BB,$96,$91,$98,$9F,$8A,$8D,$84,$83
PEC15· DATA $DE,$D9,$D0,$D7,$C2,$C5,$CC,$CB,$E6,$E1,$E8,$EF,$FA,$FD,$F4,$F3
'
[noparse][[/noparse] 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
'
[noparse][[/noparse] Program Code ]
getTemperature:
· SEROUT Sensor,baud,[noparse][[/noparse]0,"!TEMR",xslave,$07]
· SERIN Sensor,baud,1000,PECfail,[noparse][[/noparse]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
· Ferenhite = (9*Celsius)/5 + 32
· 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, DEC3 Ferenhite
· 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
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
Each time calculateCRC is called, the last value in z is used again, to calculate a final checksum. The checksum is calculated in excactly the same way in the sensor, so the checksum routine is just to ensure that data are transferred correctly.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Don't worry. Be happy
DenO