Dallas DS2450 sample code
Kas
Posts: 19
Hi
The Dallas DS2450 is a quad ADC using the 1wire protocol
Analog Inputs can be converted in Digital Output
this chip has built in alarms
A search on DS2450 brought very few usable info, beyond N&V82 article from Jon
I spent many hours on this device and wish to bring my contribution to this comunity.
This demo program
·- measure mV on Ch-D
·- display value and alarms on the PC
·- report alarms through 2 LEDs on the board
'
' {$STAMP BS2p}
' {$PBASIC 2.5}
'1-wire Dallas DS2450 (see datasheet p16)
'Set-up CH-D FOR 12 bits, 5.12V range, alarm thresholds of 2.0V (64h)and 3.0V (96h)
'turn on CH-A output if low alarm and CH-B output if high alarm.
'4.7K pullup on OWpin
'LED with 4.7k Ohm 5v pullup on DS2450 CH-A (pin 5) and CH-B (pin 6)
'100k Ohm pot on CH-D (pin 8) to vary voltage input from 0 to 5V (voltage divider)
OWpin················ PIN·· 15······················· ' One Wire pin
OW_NoRst············· CON·· %0000···················· ' no Reset
OW_FERst············· CON·· %0001···················· ' Front-End Reset
OW_BERst············· CON·· %0010···················· ' Back-End Reset
OW_BitMode··········· CON·· %0100···················· ' Bit mode comm
OW_HighSpd··········· CON·· %1000···················· ' Hi speed mode
ReadROM·············· CON·· $33······················ ' read ID, serial num, CRC
MatchROM············· CON·· $55······················ ' look for specific device
ODMatchROM··········· CON·· $69······················ ' overdrive match rom
SkipROM·············· CON·· $CC······················ ' skip rom (one device)
SearchROM············ CON·· $F0······················ ' search
ReadMem·············· CON·· $AA······················ ' read memory
WriteMem············· CON·· $55······················ ' write memory
Convert·············· CON·· $3C······················ ' do conversion
NoDevice············· CON·· %11······················ ' no device present
inp·················· VAR·· Byte(2)·················· ' input variable
volt················· VAR·· Word····················· ' measured value
SetLowLED············ VAR·· Byte····················· ' Low LED command
SetHiLED············· VAR·· Byte····················· ' Hi LED command
AlarmStatus·········· VAR·· Byte····················· ' alarm byte
afl·················· VAR·· AlarmStatus.BIT4········· ' Alarm Flag Low
afh·················· VAR·· AlarmStatus.BIT5········· ' Alarm Flag Hi
void················· VAR·· Byte····················· ' void variable
'
[noparse][[/noparse] Main ]
'
GOSUB SetUpChannels
GOSUB SetAlarmLevel
DO
· GOSUB GetInput
· GOSUB CheckAlarms
· GOSUB SetLEDs
· PAUSE 100
LOOP
'
[noparse][[/noparse] Subroutines ]
'
SetUpChannels:
'CH-A and CH-B: Digital Output configuration
' $C0=11000000 OE=1 (enable output) 0C=1(output control)
'CH-D: 12 bits 5.1V Analog Input, alarms enabled
' $0C=00001100 RC3=1 RC2=1 >> 12 bits resolution
' $OD=00001101 IR=1 (Input Range 5.1V), AEL=1 AEH=1 (Alarm Enable)
· OWOUT OWpin, OW_FERst, [noparse][[/noparse]SkipROM,WriteMem,$08,$00,$C0]·············· ' $C0 adr$08 (CH-A)
· OWOUT OWpin, OW_FERst, [noparse][[/noparse]SkipROM,WriteMem,$0A,$00,$C0]·············· ' $C0 adr$0A (CH-B)
· OWOUT OWpin, OW_FERst, [noparse][[/noparse]SkipROM,WriteMem,$0E,$00,$0C]·············· ' $0C adr$0E (CH-D)
· OWOUT OWpin, OW_FERst, [noparse][[/noparse]SkipROM,WriteMem,$0F,$00,$0D]·············· ' $0D adr$0F (CH-D)
RETURN
SetAlarmLevel:
'CH-D: Set alarm Low 2V ($64), Hi 3V ($96)
' adr$16=Low alarm, adr$17=Hi alarm
· OWOUT OWpin, OW_FERst, [noparse][[/noparse]SkipROM,WriteMem,$16,$00,$64]·············· ' $64 adr$16 (CH-D)
· OWIN OWpin, OW_NoRst, [noparse][[/noparse]void,void,void]····························· ' <CRC16> + $64
· OWOUT OWpin, OW_NoRst, [noparse][[/noparse]$96]······································· ' $96 adr$17
· OWIN OWpin, OW_NoRst, [noparse][[/noparse]void,void,void]····························· ' <CRC16> + $96
RETURN
Getinput:
· OWOUT OWpin, OW_FERst, [noparse][[/noparse]SkipROM,Convert,$08,$40]··················· ' Convert CH-D, SetB SetC
· OWIN OWpin, OW_NoRst, [noparse][[/noparse]void, void]································· ' <CRC16>
· PAUSE 5···························································· ' delay to convert
· OWOUT OWpin, OW_FERst, [noparse][[/noparse]SkipROM,ReadMem,$06,$00]··················· ' measure mV (CH-D)
· OWIN OWpin, OW_BERst, [noparse][[/noparse]inp(0),inp(1)]······························ ' status data
· Volt=((((inp(1)*256)+inp(0))/256)*5)*4
· DEBUG HOME, DEC4 volt," mV"
RETURN
CheckAlarms:
· OWOUT OWpin, OW_FERst, [noparse][[/noparse]SkipROM,ReadMem,$0f,$00]··················· ' alarms (CH-D)
· OWIN OWpin, OW_BERst, [noparse][[/noparse]AlarmStatus,void,void]······················ ' status data + <CRC16>
· IF afl=1 THEN······················································ ' AlarmStatus.BIT4=1
··· SetLowLED=$C0 : SetHiLED=$80····································· ' Low alarm
··· DEBUG "·· ** Low alarm· **"
· ELSEIF afh=1 THEN·················································· ' AlarmStatus.BIT5=1
··· SetLowLED=$80 : SetHiLED=$C0····································· ' Hi alarm
··· DEBUG "·· ** Hi alarm· **"
· ELSE
··· SetLowLED=$C0 : SetHiLED=$C0····································· ' No alarm
··· DEBUG REP " "\20
· ENDIF
RETURN
SetLEDs:
'Alarm LED update (CH-A & CH-B)
· OWOUT OWpin, OW_FERst & OW_BERst, [noparse][[/noparse]SkipROM,WriteMem,$08,$00,SetLowLED]· ' SetLowLED adr$08 (CH-A)
· OWIN OWpin, OW_NoRst, [noparse][[/noparse]void,void,void]································· ' <CRC16> + SetLowLED
· OWOUT OWpin, OW_FERst, [noparse][[/noparse]SkipROM,WriteMem,$0A,$00,SetHiLED]············· ' SetHiLED· adr$0A (CH-B)
· OWIN OWpin, OW_BERst, [noparse][[/noparse]void,void,void]································· ' <CRC16> + SetHiLED
'Clear Alarm Flags
· OWOUT OWpin, OW_FERst, [noparse][[/noparse]SkipROM,WriteMem,$0F,$00,$0D]·················· '$0D adr$0F (CH D)
· OWIN OWpin, OW_BERst, [noparse][[/noparse]void,void,void]································· ' <CRC16> + $0D
RETURN
'
Circuit implementation is straightforward see picture;
DS2450 was soldered on a SOIC to DIP converter
Enjoy·
Yves
Post Edited (Kas) : 6/28/2008 5:17:45 AM GMT
The Dallas DS2450 is a quad ADC using the 1wire protocol
Analog Inputs can be converted in Digital Output
this chip has built in alarms
A search on DS2450 brought very few usable info, beyond N&V82 article from Jon
I spent many hours on this device and wish to bring my contribution to this comunity.
This demo program
·- measure mV on Ch-D
·- display value and alarms on the PC
·- report alarms through 2 LEDs on the board
'
' {$STAMP BS2p}
' {$PBASIC 2.5}
'1-wire Dallas DS2450 (see datasheet p16)
'Set-up CH-D FOR 12 bits, 5.12V range, alarm thresholds of 2.0V (64h)and 3.0V (96h)
'turn on CH-A output if low alarm and CH-B output if high alarm.
'4.7K pullup on OWpin
'LED with 4.7k Ohm 5v pullup on DS2450 CH-A (pin 5) and CH-B (pin 6)
'100k Ohm pot on CH-D (pin 8) to vary voltage input from 0 to 5V (voltage divider)
OWpin················ PIN·· 15······················· ' One Wire pin
OW_NoRst············· CON·· %0000···················· ' no Reset
OW_FERst············· CON·· %0001···················· ' Front-End Reset
OW_BERst············· CON·· %0010···················· ' Back-End Reset
OW_BitMode··········· CON·· %0100···················· ' Bit mode comm
OW_HighSpd··········· CON·· %1000···················· ' Hi speed mode
ReadROM·············· CON·· $33······················ ' read ID, serial num, CRC
MatchROM············· CON·· $55······················ ' look for specific device
ODMatchROM··········· CON·· $69······················ ' overdrive match rom
SkipROM·············· CON·· $CC······················ ' skip rom (one device)
SearchROM············ CON·· $F0······················ ' search
ReadMem·············· CON·· $AA······················ ' read memory
WriteMem············· CON·· $55······················ ' write memory
Convert·············· CON·· $3C······················ ' do conversion
NoDevice············· CON·· %11······················ ' no device present
inp·················· VAR·· Byte(2)·················· ' input variable
volt················· VAR·· Word····················· ' measured value
SetLowLED············ VAR·· Byte····················· ' Low LED command
SetHiLED············· VAR·· Byte····················· ' Hi LED command
AlarmStatus·········· VAR·· Byte····················· ' alarm byte
afl·················· VAR·· AlarmStatus.BIT4········· ' Alarm Flag Low
afh·················· VAR·· AlarmStatus.BIT5········· ' Alarm Flag Hi
void················· VAR·· Byte····················· ' void variable
'
[noparse][[/noparse] Main ]
'
GOSUB SetUpChannels
GOSUB SetAlarmLevel
DO
· GOSUB GetInput
· GOSUB CheckAlarms
· GOSUB SetLEDs
· PAUSE 100
LOOP
'
[noparse][[/noparse] Subroutines ]
'
SetUpChannels:
'CH-A and CH-B: Digital Output configuration
' $C0=11000000 OE=1 (enable output) 0C=1(output control)
'CH-D: 12 bits 5.1V Analog Input, alarms enabled
' $0C=00001100 RC3=1 RC2=1 >> 12 bits resolution
' $OD=00001101 IR=1 (Input Range 5.1V), AEL=1 AEH=1 (Alarm Enable)
· OWOUT OWpin, OW_FERst, [noparse][[/noparse]SkipROM,WriteMem,$08,$00,$C0]·············· ' $C0 adr$08 (CH-A)
· OWOUT OWpin, OW_FERst, [noparse][[/noparse]SkipROM,WriteMem,$0A,$00,$C0]·············· ' $C0 adr$0A (CH-B)
· OWOUT OWpin, OW_FERst, [noparse][[/noparse]SkipROM,WriteMem,$0E,$00,$0C]·············· ' $0C adr$0E (CH-D)
· OWOUT OWpin, OW_FERst, [noparse][[/noparse]SkipROM,WriteMem,$0F,$00,$0D]·············· ' $0D adr$0F (CH-D)
RETURN
SetAlarmLevel:
'CH-D: Set alarm Low 2V ($64), Hi 3V ($96)
' adr$16=Low alarm, adr$17=Hi alarm
· OWOUT OWpin, OW_FERst, [noparse][[/noparse]SkipROM,WriteMem,$16,$00,$64]·············· ' $64 adr$16 (CH-D)
· OWIN OWpin, OW_NoRst, [noparse][[/noparse]void,void,void]····························· ' <CRC16> + $64
· OWOUT OWpin, OW_NoRst, [noparse][[/noparse]$96]······································· ' $96 adr$17
· OWIN OWpin, OW_NoRst, [noparse][[/noparse]void,void,void]····························· ' <CRC16> + $96
RETURN
Getinput:
· OWOUT OWpin, OW_FERst, [noparse][[/noparse]SkipROM,Convert,$08,$40]··················· ' Convert CH-D, SetB SetC
· OWIN OWpin, OW_NoRst, [noparse][[/noparse]void, void]································· ' <CRC16>
· PAUSE 5···························································· ' delay to convert
· OWOUT OWpin, OW_FERst, [noparse][[/noparse]SkipROM,ReadMem,$06,$00]··················· ' measure mV (CH-D)
· OWIN OWpin, OW_BERst, [noparse][[/noparse]inp(0),inp(1)]······························ ' status data
· Volt=((((inp(1)*256)+inp(0))/256)*5)*4
· DEBUG HOME, DEC4 volt," mV"
RETURN
CheckAlarms:
· OWOUT OWpin, OW_FERst, [noparse][[/noparse]SkipROM,ReadMem,$0f,$00]··················· ' alarms (CH-D)
· OWIN OWpin, OW_BERst, [noparse][[/noparse]AlarmStatus,void,void]······················ ' status data + <CRC16>
· IF afl=1 THEN······················································ ' AlarmStatus.BIT4=1
··· SetLowLED=$C0 : SetHiLED=$80····································· ' Low alarm
··· DEBUG "·· ** Low alarm· **"
· ELSEIF afh=1 THEN·················································· ' AlarmStatus.BIT5=1
··· SetLowLED=$80 : SetHiLED=$C0····································· ' Hi alarm
··· DEBUG "·· ** Hi alarm· **"
· ELSE
··· SetLowLED=$C0 : SetHiLED=$C0····································· ' No alarm
··· DEBUG REP " "\20
· ENDIF
RETURN
SetLEDs:
'Alarm LED update (CH-A & CH-B)
· OWOUT OWpin, OW_FERst & OW_BERst, [noparse][[/noparse]SkipROM,WriteMem,$08,$00,SetLowLED]· ' SetLowLED adr$08 (CH-A)
· OWIN OWpin, OW_NoRst, [noparse][[/noparse]void,void,void]································· ' <CRC16> + SetLowLED
· OWOUT OWpin, OW_FERst, [noparse][[/noparse]SkipROM,WriteMem,$0A,$00,SetHiLED]············· ' SetHiLED· adr$0A (CH-B)
· OWIN OWpin, OW_BERst, [noparse][[/noparse]void,void,void]································· ' <CRC16> + SetHiLED
'Clear Alarm Flags
· OWOUT OWpin, OW_FERst, [noparse][[/noparse]SkipROM,WriteMem,$0F,$00,$0D]·················· '$0D adr$0F (CH D)
· OWIN OWpin, OW_BERst, [noparse][[/noparse]void,void,void]································· ' <CRC16> + $0D
RETURN
'
Circuit implementation is straightforward see picture;
DS2450 was soldered on a SOIC to DIP converter
Enjoy·
Yves
Post Edited (Kas) : 6/28/2008 5:17:45 AM GMT
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
I appreciate viewing the code within the post without any download.
If I want to keep it for future reference, a "copy paste" is an easy task
The chip is just soldered on the adaptor
Yves