Hey all!

First of all I'd like to say thanks to Bert van Dam and everyone, who
helped him write this language and his wonderful books about jal and
for making pic programming available to everyone which did not have an
education in electronics (such as me :) )

Back to business, I'm busy writing a library for the ds2450 in jal
using a part of the 1_wire.jal and a bit of myself. I got aquainted
with 1 wire devices after reading berts last book and got interested
in them.

I'm trying to read the a/d channels in 16-bit resolution but for some
reason I'm only receiving random (as it seems) bytes back. I was
wondering if someone has experience with this chip and could help me
with this. The configuration of the ds2450 goes well (tested by
reading back the written byte), only reading the a/d registers gives
strange values both in 8 bit or 16 bit values. I've absolutely turned
the datasheet inside out and searched for examples but i really have
no idea about what i'm doing wrong here.

Here is the main code i'm using for testing and is giving completely
random a/d outputs (its a shame it isnt possible to upload files):

<code main>
include 18f2450_bert
include 1_wire
include ds2450_1_wire

var byte crc1, crc2, mydata, cha1, cha2, chb1, chb2, chc1, chc2, chd1,
chd2

var bit led is pin_c6
pin_c6_direction = output

led = 0

--blink led to test crystal
for 6 loop
led = !led
delay_100ms(1)
end loop


   -- set voltage to vcc supplied
   MatchRom
   load_my_id(2)
   Send_ID
   d1w_write_byte(0x55) --write memory
   d1w_write_byte(0x1C) -- ta1
   d1w_write_byte(0x00) -- ta2
   d1w_write_byte(0x40) -- data
   d1w_read_byte(crc1) -- receive crc16
   d1w_read_byte(crc2)
   d1w_read_byte(mydata) -- receive data back from memory
   serial_sw_write(mydata)
   d1w_reset

   -- disable oc oa, enable 16bit ch A
   MatchRom
   load_my_id(2)
   Send_ID
   d1w_write_byte(0x55) --write memory
   d1w_write_byte(0x08) -- ta1
   d1w_write_byte(0x00) -- ta2
   d1w_write_byte(0x00) -- data
   d1w_read_byte(crc1) -- receive crc16
   d1w_read_byte(crc2)
   d1w_read_byte(mydata) -- receive data back from memory
   serial_sw_write(mydata)
   d1w_reset

   -- disable oc oa, enable 16bit ch B
   MatchRom
   load_my_id(2)
   Send_ID
   d1w_write_byte(0x55) --write memory
   d1w_write_byte(0x0A) -- ta1
   d1w_write_byte(0x00) -- ta2
   d1w_write_byte(0x00) -- data
   d1w_read_byte(crc1) -- receive crc16
   d1w_read_byte(crc2)
   d1w_read_byte(mydata) -- receive data back from memory
   serial_sw_write(mydata)
   d1w_reset

   -- disable oc oa, enable 16bit ch C
   MatchRom
   load_my_id(2)
   Send_ID
   d1w_write_byte(0x55) --write memory
   d1w_write_byte(0x0C) -- ta1
   d1w_write_byte(0x00) -- ta2
   d1w_write_byte(0x00) -- data
   d1w_read_byte(crc1) -- receive crc16
   d1w_read_byte(crc2)
   d1w_read_byte(mydata) -- receive data back from memory
   serial_sw_write(mydata)
   d1w_reset

   -- disable oc oa, enable 16bit ch D
   MatchRom
   load_my_id(2)
   Send_ID
   d1w_write_byte(0x55) --write memory
   d1w_write_byte(0x0E) -- ta1
   d1w_write_byte(0x00) -- ta2
   d1w_write_byte(0x00) -- data
   d1w_read_byte(crc1) -- receive crc16
   d1w_read_byte(crc2)
   d1w_read_byte(mydata) -- receive data back from memory
   serial_sw_write(mydata)
   d1w_reset

   -- set volt range to 5.12 ch A
   MatchRom
   load_my_id(2)
   Send_ID
   d1w_write_byte(0x55) --write memory
   d1w_write_byte(0x09) -- ta1
   d1w_write_byte(0x00) -- ta2
   d1w_write_byte(0x01) -- data
   d1w_read_byte(crc1) -- receive crc16
   d1w_read_byte(crc2)
   d1w_read_byte(mydata) -- receive data back from memory
   serial_sw_write(mydata)
   d1w_reset

   -- set volt range to 5.12 ch B
   MatchRom
   load_my_id(2)
   Send_ID
   d1w_write_byte(0x55) --write memory
   d1w_write_byte(0x0B) -- ta1
   d1w_write_byte(0x00) -- ta2
   d1w_write_byte(0x01) -- data
   d1w_read_byte(crc1) -- receive crc16
   d1w_read_byte(crc2)
   d1w_read_byte(mydata) -- receive data back from memory
   serial_sw_write(mydata)
   d1w_reset

   -- set volt range to 5.12 ch C
   MatchRom
   load_my_id(2)
   Send_ID
   d1w_write_byte(0x55) --write memory
   d1w_write_byte(0x0D) -- ta1
   d1w_write_byte(0x00) -- ta2
   d1w_write_byte(0x01) -- data
   d1w_read_byte(crc1) -- receive crc16
   d1w_read_byte(crc2)
   d1w_read_byte(mydata) -- receive data back from memory
   serial_sw_write(mydata)
   d1w_reset

   -- set volt range to 5.12 ch D
   MatchRom
   load_my_id(2)
   Send_ID
   d1w_write_byte(0x55) --write memory
   d1w_write_byte(0x0F) -- ta1
   d1w_write_byte(0x00) -- ta2
   d1w_write_byte(0x01) -- data
   d1w_read_byte(crc1) -- receive crc16
   d1w_read_byte(crc2)
   d1w_read_byte(mydata) -- receive data back from memory
   serial_sw_write(mydata)
   d1w_reset



forever loop
led = !led

-- start conversion
   MatchRom
   load_my_id(2)
   Send_ID
   d1w_write_byte(0x3C) --conversion
   d1w_write_byte(0x08) -- input select mask, all channels
   d1w_write_byte(0x00) -- read out control
   d1w_read_byte(crc1) -- receive crc16
   d1w_read_byte(crc2)

   d1w_reset

   delay_10ms(1) -- should be more than enough abt. 6 ms should be
reqd...


-- read ad ch A
   MatchRom
   load_my_id(2)
   Send_ID
   d1w_write_byte(0xAA) --read memory
   d1w_write_byte(0x06) -- ta1
   d1w_write_byte(0x00) -- ta2

   d1w_read_byte(chd1)
   d1w_read_byte(chd2)

   d1w_read_byte(crc1)
   d1w_read_byte(crc2)

   d1w_reset

   serial_sw_write(chd1)
   delay_1ms(1)
   serial_sw_write(chd2)

   delay_1s(1)


end loop
</code main>




This is the libary ds2450_1_wire which is still in devellopment of
course and a slightly modified version of library
ds18s22_1_wire.jal...




<code ds2450_1_wire.jal>

-- 1-wire bytes, data
var byte d1, d2, d3, d4, d5, d6, d7, d8, d9

-- 1-wire bytes, id number
var byte id1, id2, id3, id4, id5, id6, id7, id8, id9

-- calculated CRC vakue
var byte GOOD_crc


procedure d1w_read_byte_with_CRC( byte in nbre_byte ) is
   -- read a number of bytes and calculate the CRC value of
   -- the complete group
   var byte bb = 0, n = 0 , crcbyte = 0
   var bit  bb_bit0 at bb : 0
   var bit  crcbyte_bit0 at crcbyte : 0
   var bit  crcbyte_bit2 at crcbyte : 2
   var bit  crcbyte_bit3 at crcbyte : 3
   var bit  crcbyte_bit7 at crcbyte : 7
   var bit  crcbit

   for nbre_byte loop             -- 8 bytes for readrom ID, 9 bytes
for read temp
      d1w_read_byte( bb )
      n = n + 1
      if n == 1 then d1 = bb end if
      if n == 2 then d2 = bb end if
      if n == 3 then d3 = bb end if
      if n == 4 then d4 = bb end if
      if n == 5 then d5 = bb end if
      if n == 6 then d6 = bb end if
      if n == 7 then d7 = bb end if
      if n == 8 then d8 = bb end if
      if n == 9 then d9 = bb end if

      -- calculate the CRC value, if this value is zero than
      -- the CRC is correct
      for 8 loop
         crcbit = crcbyte_bit0 ^ bb_bit0
         crcbyte = (crcbyte >> 1)
         crcbyte_bit7 = crcbit
         crcbyte_bit2 = crcbyte_bit2 ^ crcbit
         crcbyte_bit3 = crcbyte_bit3 ^ crcbit
         bb = (bb >> 1)
     end loop
   end loop

   if d5==0x_FF & d6==0x_FF & d7==0x_FF & d8==0x_FF & d9==0x_FF  then
      -- probe is not present, all read to 1 == 0x_FF
      -- set the CRC value to false, and reset temp with error scale
99°c
      crcbyte = 1
      d1=198
   end if

   GOOD_crc=crcbyte

end procedure



procedure Print_ID is
   -- print the ID number
serial_sw_write(id1) --send ID
serial_sw_write(id2)
serial_sw_write(id3)
serial_sw_write(id4)
serial_sw_write(id5)
serial_sw_write(id6)
serial_sw_write(id7)
serial_sw_write(id8)

end procedure



procedure Read_ID is
   -- read the unique ROM code (serial number) and
   -- check the CRC value
   d1w_reset
   d1w_write_byte( 0x33 )        -- read ID command
   d1w_read_byte_with_CRC( 8 )   -- juste 8 bytes for ID
   id1 = d1
   id2 = d2
   id3 = d3
   id4 = d4
   id5 = d5
   id6 = d6
   id7 = d7
   id8 = d8
   print_ID

   if GOOD_crc == 0 then
      serial_sw_write(0xbb)
   else
      serial_sw_write(0xcc)
   end if

end procedure



procedure Load_My_ID( byte in probe_number ) is

   -- ic3
   if probe_number == 1 then
      id1 = 0x20 -- ID 2011 20 0C 00 00 00 69
      id2 = 0x11
      id3 = 0x20
      id4 = 0x0C
      id5 = 0x00
      id6 = 0x00
      id7 = 0x00
      id8 = 0x69
   end if

   -- ic4
   if probe_number == 2 then
      id1 = 0x20 -- ID 20 1E 39 0A 00 00 00 CB
      id2 = 0x1E
      id3 = 0x39
      id4 = 0x0A
      id5 = 0x00
      id6 = 0x00
      id7 = 0x00
      id8 = 0xCB
   end if

end procedure



procedure MatchRom is
   d1w_reset
   d1w_write_byte( 0x55 )                         -- adress unique
probe
end procedure

procedure Send_ID is
   -- send ID
   d1w_write_byte( id1 )
   d1w_write_byte( id2 )
   d1w_write_byte( id3 )
   d1w_write_byte( id4 )
   d1w_write_byte( id5 )
   d1w_write_byte( id6 )
   d1w_write_byte( id7 )
   d1w_write_byte( id8 )
end procedure

</code ds2450_1_wire.jal>

The library 1_wire.jal is similar to the one distributed in the jal
pack from www.boekinfo.tk . In this code i'm only reading channel d
but the 'random factor' goes for all the channels and both ds2450's on
the board.

The hardware i'm using (have eagle drawings but no idea how to upload)
is a pic 18f2450 on a 20hmhz crystal with 20pf caps, a standard 7805
with caps and 100nf caps very close to the 7805, pic and ds2450's. All
is mounted on the same pcb so cable breaks is out of the question.
Also there are 1/10th  voltage dividers using 1k and 10k resistors
before the a/d inputs. the ds2450's are coupled to Vcc and this is
also set in the code.

If anyone could help me i'd be very thankful! of course when the code
is finished I will publish it here under public license!!!

best regards,

richard

-- 
You received this message because you are subscribed to the Google Groups 
"jallib" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/jallib?hl=en.

Reply via email to