-
Arrays calling Arrays
My project is to determine the %moisture content of grain in storage. I’m using 1-Wire DS2438 and Honeywell HIH-4000 RH sensors inside of the grain. I have a number of sensors on each string. All devices are working good using individual SN to address each device. I have ample RAM but I’m running out of CODE space. To reduce the program size I need to be able to use an array of some kind to be called by a variable residing in the routine to address each 1-Wire device in secession so I can loop through a single routine rather than have multiple routines. Instead of using:
Code:
OWOUT DataPin, 1, [MatchRom,$26,$7A,$BA,$11,$01,$00,$00,$D8, ConvertV]
I would like to use:
Code:
OWOUT DataPin,1,[MatchRom, OW_Loop_VAR , ConvertV]
OW_Loop_var VAR BYTE [8]
OWbuffer1 VAR BYTE[8] ;SN first sensor
OWbuffer1[0]= $26
OWbuffer1[1]= $7A
OWbuffer1[2]= $BA
OWbuffer1[3]= $11
OWbuffer1[4]= $01
OWbuffer1[5]= $00
OWbuffer1[6]= $00
OWbuffer1[7]= $D8
OWbuffer2 VAR BYTE[8] ;SN second sensor
OWbuffer2[0]= $26
OWbuffer2[1]= $A7
OWbuffer2[2]= $AB
OWbuffer2[3]= $11
OWbuffer2[4]= $10
OWbuffer2[5]= $00
OWbuffer2[6]= $00
OWbuffer2[7]= $E8
OW_Loop_var = OWbuffer1
GOSUB OWroutine
OW_Loop_var = OWbuffer2
GOSUB OWroutine
OWrutine:
OWOUT DataPin,1,[MatchRom, OW_Loop_var , ConvertV]
It seems to me this would work. As a test I tried:
OWOUT DataPin,1,[MatchRom, OWbuffer1, ConvertV]
But it doesn’t work and I can’t seem to figure out how to make this happen. I’ve been reading posts on strings, arrays, EXT, and everything else I could find but I’ve seen nothing that resembles what I’m trying to do. Assistance please.
-
Hi,
I've never played with the 1-wire commands but according to the manual you should be able to use the STR modifier to send an array of bytes out. So, an educated guess is something like:
Code:
OWbuffer VAR BYTE[8] ;Array for outgoing data
'Assign values for sensor 1 to the array.
OWbuffer[0]= $26 : OWbuffer[1]= $7A
OWbuffer[2]= $BA : OWbuffer[3]= $11
OWbuffer[4]= $01 : OWbuffer[5]= $00
OWbuffer[6]= $00 : OWbuffer[7]= $D8
GOSUB OWRoutine 'Send it
'Assign values for sensor 2 to the array.
OWbuffer[0]= $26 : OWbuffer[1]= $A7
OWbuffer[2]= $AB : OWbuffer[3]= $11
OWbuffer[4]= $10 : OWbuffer[5]= $00
OWbuffer[6]= $00 : OWbuffer[7]= $E8
GOSUB OWRoutine 'Send it
END
OWRoutine:
OWOUT DataPin,1,[MatchRom, STR OWBuffer \8, ConvertV]
RETURN
This way you only have one "instance" of the OWOUT command which should save you a couple of words compared to having 26 of them (if that's what you currently have).
/Henrik.
-
Reply to Henrik
Henrik,
thanks for the reply. I've tried String modifiers to send 1-wire and it doesn't work. I use String modifiers to recieve data and it works fine. It seems the method should work in both directions.
OWIN DataPin, 2, [STR DSbuffer\9 ] this work fine - recieve data from 1-Wire device
OWOUT DataPin, 1, [MatchRom, STR OWbuffer\8, ConverV] doesn't work - send 1-Wire
OWOUT DataPin, 1, [MatchRom, $26, $....... .......$D8, ConvertV] this works - send 1-Wire
I'm not sure if the PBP comand can handle the string not enclosed in brakets. I'll keep working with this and get back to you. Thanks agin.
-
follow up
OK, I got it. A small error in the method I was using to set up the 1-Wire command. The STR modifier works fine. This will save a lot of code space. Hanrik, thanks for your reply which make me work on the STR method until I got it right!
-
Hi,
Great, I'm glad you got it going!
Another way might be to use the DATA statement to save the values for each sensor to onboard EEPROM and then use a FOR-NEXT loop to read them out and stuff them into the OWBuffer array. Depending on the number of sensor "strings" you have it probably save you even more code space - provided your chip has enough EEPROM space of course.
/Henrik.