The UK Home Automation Archive

Archive Home
Group Home
Search Archive


Advanced Search

The UKHA-ARCHIVE IS CEASING OPERATIONS 31 DEC 2024


[Message Prev][Message Next][Thread Prev][Thread Next][Message Index][Thread Index]

Re: [OT] Some pic asm code help



Hi Stephen

Loaded your code but  still no joy ..it gave me a reading of around 3mV
...??/

I dont understand how your code shifts the  bits from the MSB byte DS_DATA1
into the LSB byte DS_DATA0....

Thanks for your help

Frank

----- Original Message -----
From: "Stephen McGarry" <Selfbuild@xxxxxxx>
To: <ukha_d@xxxxxxx>
Sent: Monday, September 10, 2007 5:57 AM
Subject: Re: [ukha_d] [OT] Some pic asm code help


>I see an immediate problem in the code as you are SUBTRACING the mask
not
>ANDing !
> and you can make the rotates a lot simpler... (without firing up my
> simulator and checking)
>
> HTH Stephen
>
> Try this :-
>
> CEL2760
> ;rotate both (don't worry about carrys into MSB as you will mask
later)
> rrf DS_DATA1,1 ;shift down MSB and move bit into carry
> rrf DS_DATA0,1 ;then move it into the LSB and move it down
> rrf DS_DATA1,1 ;and again
> rrf DS_DATA0,1
> rrf DS_DATA1,1 ;and again
> rrf DS_DATA0,1
>
> btfss DS_DATA1,4 ;check sign status
> goto mask_up_nib ;
>
> comf DS_DATA1,1 ;yes , 2,s compliment
> comf DS_DATA0,1 ;invert and
> incf DS_DATA0,1 ;add 1
>
> btfsc C_bit ;
> incf DS_DATA1,1 ;
>
> mask_up_nib
> movlw 0fh ;mask out rubbish
> andwf DS_DATA1,1
>
> cely return ;
>
> Frank Mc Alinden wrote:
>>
>>
>> Hi Ian
>>
>> I forgot to rotate the MSB so those values in my last post are way
>> out....
>> try these MSB D2h .....LSB BBh................MSB D1h.....LSB F0h
>>
>> Heres a copy of my current code which is suppose to convert the
raw dat
>> to
>> 16 bit
>>
>> Thanks agian
>> Frank
>>
>> CEL2760
>>
>> bcf neg ;clear negative flag
>> btfss DS_DATA1,7 ;negative ? if yes , skip next
>> goto cel2 ;no
>>
>> bsf neg ;set negative flag
>>
>> cel2 ;rotate LSB
>>
>> bcf C_bit ;clear carry flag
>> rrf DS_DATA0,1 ;Data0 holds LSB data (0F)
>>
>> bcf C_bit ;clear carry flag
>> rrf DS_DATA0,1 ;
>>
>> bcf C_bit ;clear carry flag
>> rrf DS_DATA0,1
>>
>> ;SHIFT AND ROTATE MSB
>>
>> chec_msb_bit0
>> btfss DS_DATA1,0 ;Check MSB Byte bit 0
>> goto set_lsb_5_lo ;
>> bsf DS_DATA0,5 ;set bit 5 of lsb byte
>> goto chec_msb_1 ;
>>
>> set_lsb_5_lo
>> bcf DS_DATA0,5 ;
>>
>> chec_msb_1
>>
>> btfss DS_DATA1,1 ;Check MSB Byte bit 1
>> goto set_lsb_6_lo ;
>> bsf DS_DATA0,6 ;set bit 6 of lsb byte
>> goto chec_msb_2 ;
>>
>> set_lsb_6_lo
>> bcf DS_DATA0,6 ;
>>
>> chec_msb_2
>> btfss DS_DATA1,2 ;Check MSB Byte bit 2
>> goto set_lsb_7_lo ;
>> bsf DS_DATA0,7 ;set bit 7 of lsb byte
>> goto shift_data1 ;
>>
>> set_lsb_7_lo
>> bcf DS_DATA0,7 ;
>>
>> shift_data1
>>
>> bcf DS_DATA1,0 ;
>> bcf DS_DATA1,1 ;
>> bcf DS_DATA1,2 ;
>>
>> bcf C_bit ;clear carry flag
>> rrf DS_DATA1,1 ;
>>
>> bcf C_bit ;clear carry flag
>> rrf DS_DATA1,1 ;
>>
>> bcf C_bit ;clear carry flag
>> rrf DS_DATA1,1 ;
>>
>> btfss neg ;check sign status
>> goto mask_up_nib ;
>>
>> comf DS_DATA1,1 ;yes , 2,s compliment
>>
>> comf DS_DATA0,1 ;yes , 2,s compliment
>> incf DS_DATA0,1 ;
>>
>> btfsc C_bit ;
>> incf DS_DATA1,1 ;
>>
>> mask_up_nib
>>
>> movlw 0fh ;mask upper nibble
>> subwf DS_DATA1,1 ;
>>
>> cely return ;
>>
>> ----- Original Message -----
>> From: "Ian Davidson" <ian@xxxxxxx
>> <mailto:ian%40galeforce9.co.uk>>
>> To: <ukha_d@xxxxxxx <mailto:ukha_d%40yahoogroups.com>>
>> Sent: Sunday, September 09, 2007 6:45 PM
>> Subject: RE: [ukha_d] [OT] Some pic asm code help
>>
>>  > Hi Frank
>>  >
>>  > As a first test I would read the device and output the
actual raw word
>>  > value you read. Then manually convert this. This will prove
if you are
>>  > actually reading the correct value and converting wrong or
if the raw
>>  > value is wrong in the first place. If you want to post the
raw values
>> I
>>  > can convert them here and let you know what I get the result
to be.
>>  >
>>  > Ok just reading your post again.
>>  >
>>  > I can see where this is going wrong. You need to do the
rotating
>> first.
>>  > If you don't then when you add the 1 and later rotate you
rotate it
>>  > straight off the end. In your case the bit 0 position starts
at bit 3
>> so
>>  > instead of adding 1 you would have to add 8 but it is easier
just to
>>  > rotate first then do the complementing. Also treat the two
bytes as
>> one
>>  > value so when you complement and add 1 only add 1 to the
LSB. The only
>>  > other point to watch out for is after you complement you can
mask off
>>  > the top nibble of the MSB as after rotating the first three
are not
>> used
>>  > and the next is just the sign bit which is not part of the
2's
>>  > complement.
>>  >
>>  > I hope that made sense it far easier to talk it than write
it!
>>  >
>>  > Ian D
>>  >
>>  >
>>  > -----Original Message-----
>>  > From: ukha_d@xxxxxxx <mailto:ukha_d%40yahoogroups.com>
>> [mailto:ukha_d@xxxxxxx <mailto:ukha_d%40yahoogroups.com>]
On
>> Behalf
>>  > Of Frank Mc Alinden
>>  > Sent: 09 September 2007 08:31
>>  > To: Ian
>>  > Subject: Re: [ukha_d] [OT] Some pic asm code help
>>  >
>>  > Hi Ian
>>  >
>>  > Firstly thanks for your feedback much appreciated...
>>  >
>>  > What i have done is this firstly is test bit 7 of the MSB 0E
and if it
>>  > is
>>  > set i compliment each byte and add 1 to each of them...??
>>  >
>>  > I then rotate right the LSB register OF 3 times each time
clearing the
>>  > carry flag........
>>  >
>>  > I then shift bits 0,1,2 of the MSB into bits 5,6 +7 of the
LSB and
>>  > rotate
>>  > the MSB 3 times.........???
>>  >
>>  > With the result im using existing sub routines that i use to
convert
>>  > the
>>  > ds18s20 results into temperature readings....
>>  >
>>  > The results im getting do not tally up with readings im
getting using
>>  > another device (opnode) which also has moisture sensors
attached to
>>  > it.........
>>  >
>>  > The moisture sensors use an external resistor so the range
should go
>>  > from
>>  > +64mV to -64mV
>>  >
>>  > Thanks again
>>  > Frank
>>  >
>>  >
>>  > ----- Original Message -----
>>  > From: "Ian Davidson" <ian@xxxxxxx
>> <mailto:ian%40galeforce9.co.uk>>
>>  > To: <ukha_d@xxxxxxx <mailto:ukha_d%40yahoogroups.com>>
>>  > Sent: Sunday, September 09, 2007 12:11 PM
>>  > Subject: RE: [ukha_d] [OT] Some pic asm code help
>>  >
>>  >
>>  >> Hi Frank
>>  >>
>>  >> I've not used that ic before but looking at the data
sheet it works
>>  > like
>>  >> this.
>>  >>
>>  >> The value you read from the ic will be a word value. It
is left
>>  >> justified so you need to rotate the value right three
times to get
>> the
>>  >> LSB into the bit 0 position.
>>  >>
>>  >> Say you read
>>  >> 00000000 01010000
>>  >>
>>  >> By rotating it 3 times it will become
>>  >> 00000000 00001010
>>  >>
>>  >> Now you need to test bit 12, in the example it is a zero
which means
>>  > the
>>  >> number is a positive number. You can therefore just use
that number
>> in
>>  >> this case decimal 10. If you are using the internal
resistor then the
>>  >> resolution is 0.625mA. 10 x 0.625mA is 6.25mA which is
the current
>> the
>>  >> device is seeing.
>>  >>
>>  >> Now if bit 12 was a 1
>>  >>
>>  >> I.e.
>>  >> 00011111 11110110
>>  >> Then that is a negative number. In two complement you
need to invert
>>  > all
>>  >> the bits and add one for all the bits below bit 12 so
>>  >>
>>  >> 00000000 00001001
>>  >>
>>  >> Add 1
>>  >>
>>  >> 00000000 00001010
>>  >>
>>  >> Which is 10 decimal times by 0.625mA equals -6.25mA
>>  >>
>>  >> I hope that made sense Frank.
>>  >>
>>  >> Ian D
>>  >>
>>  >>
>>  >> -----Original Message-----
>>  >> From: ukha_d@xxxxxxx <mailto:ukha_d%40yahoogroups.com>
>> [mailto:ukha_d@xxxxxxx <mailto:ukha_d%40yahoogroups.com>]
On
>> Behalf
>>  >> Of Frank Mc Alinden
>>  >> Sent: 08 September 2007 23:45
>>  >> To: Ian
>>  >> Subject: [ukha_d] [OT] Some pic asm code help
>>  >>
>>  >> Hi Guys
>>  >>
>>  >> Sorry for the OT post but im hoping some of the pic
coders can help
>>  >> me....Im
>>  >> trying to add support for the Hobby Boards moisture
sensor to my
>> Probe
>>  >> system and im stuck trying to write some code to convert
the readings
>>  >> from
>>  >> the "current registers (OE +OF) " of the
DS2760...(The mositure
>> sensor
>>  >> uses
>>  >> the current sense) ...I can read the DS2760 and get the
values i just
>>  >> cant
>>  >> work out how to convert it to mVolts.......Any help much
>>  >> appreciated......If
>>  >> i get this sorted i will then have a crack at their
Humidity
>>  >> sensor.......
>>  >> Heres a link to the hobby boards sensor and the DS2760
PDF
>>  >> http://datasheets.maxim-ic.com/en/ds/DS2760.pdf
>> <http://datasheets.maxim-ic.com/en/ds/DS2760.pdf>
>>  >>
>>  >>
>>  >
>> http://www.hobby-boards.com/catalog/product_info.php?cPath=22&products_i
>> <http://www.hobby-boards.com/catalog/product_info.php?cPath=22&products_i>
>>  >> d=70
>>  >>
>>  >> Thanks
>>  >> Frank
>>  >> www.armaghelectrical.com.au
>>  >>
>>  >>
>>  >>
>>  >>
>>  >>
>>  >>
>>  >>
>>  >>
>>  >>
>>  >>
>>  >>
>>  >>
>>  >>
>>  >>
>>  >
>>  >
>>  >
>>  >
>>  >
>>  >
>>  >
>>  >
>>  >
>>  >
>>  >
>>  >
>>  >
>>  >
>>
>>
>
>
>
>
>
>
>



UKHA_D Main Index | UKHA_D Thread Index | UKHA_D Home | Archives Home

Comments to the Webmaster are always welcomed, please use this contact form . Note that as this site is a mailing list archive, the Webmaster has no control over the contents of the messages. Comments about message content should be directed to the relevant mailing list.