PDA

View Full Version : Serin serout problem



Pages : [1] 2

lerameur
- 22nd December 2006, 13:21
Hello,
nice to see the site back up.

I am almost finish my little project now. I have diffculty sending mutliple item on serout and receiving them on another chip using serin. I think its the way i type the command, the program does compile , but do not work.;
here is the two codes of line:
Sending Pic:
serout2 portb.2, n2400, [encoded22.HighBYTE, encoded22.LowBYTE, encoded11.HighBYTE, encoded11.LowBYTE ]

Receiving Pic:
serin portB.3, n2400,[ encoded22.HighBYTE, encoded22.LowBYTE, encoded11.HighBYTE, encoded11.LowBYTE]

after that i want to make the thing wireless. I have been trying to make the qualifier work in the serin command with no luck. I think this is needed because I will need to send some premamble to the receiving chip before the data right ??

Ken

skimask
- 22nd December 2006, 13:51
---------------------------------------------------------------
serout2 portb.2, n2400, [encoded22.HighBYTE, encoded22.LowBYTE, encoded11.HighBYTE, encoded11.LowBYTE ]
---------------------------------------------------------------


SEROUT, not SEROUT2. Check your PBP manual for the explanation.

lerameur
- 22nd December 2006, 15:54
yes in fact I tried both and it do not work.
I think my problem might be in the receiving end. when I do an lcd out without the serin command, the LCDout works, as soon I add the serin command, I only see black squares on the LCDout. So I think the serin command is not good.
BUT if I just put

serin portB.3, n2400,[ encoded22.HighBYTE, encoded22.LowBYTE, encoded11.HighBYTE, encoded11.LowBYTE]

lcdout $FE,1
LCDOUT "datain: ", BIN 5
lcdout $FE,$C0, "datain2: ", bin encoded22.HighBYTE
Pause 500

is there something else I should be putting in for serin ?

k

rhino
- 22nd December 2006, 16:46
You might have to provide some more of your code to troubleshoot and maybe a schematic. I believe what Skimask is referring to is SEROUT2 requires mode number instead of a mnemonic such as "n2400".


Mode is used to specify the baud rate and operating parameters of the
serial transfer. The low order 13 bits select the baud rate. Bit 13 selects
parity or no parity. Bit 14 selects inverted or true level. Bit 15 selects
whether it is driven or open.
The baud rate bits specify the bit time in microseconds - 20. To find the
value for a given baud rate, use the equation:
(1000000 / baud) - 20

t2400 = 396
n2400 = 16780

lerameur
- 22nd December 2006, 16:48
By the way , the LCD is there basically to tell me what is goign on .
anyway , here is the complete program :
sending:

' Picbasic Pro program to read DS1820 1-wire temperature sensor
' and display temperature on LCD
' FOR SENDING SERIAL
INCLUDE "modedefs.bas"
DEFINE OSC 20 'use external 20mhz crystal

CMCON = 7 : ANSEL = 0 : ADCON1 = 7
' Define LCD pins
DEFINE LCD_DREG PORTA ' Set LCD Data port
DEFINE LCD_DBIT 0 ' Set starting Data bit (0 or 4) if 4-bit bus

DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit

DEFINE LCD_EREG PORTB ' Set LCD Enable port
DEFINE LCD_EBIT 0 ' Set LCD Enable bit

DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
DEFINE LCD_LINES 2 ' Set number of lines on LCD

TRISB.2 =0
TRISB.3 =1
DQ var PortB.4
temp var word
'27
temperature var word
count_remain var byte
count_per_c var byte
counter var byte
tempc var word
dataout var word
dataout2 var word
datain var word
array var word
encoded1 var word
encoded2 var word
encoded22 var word
encoded11 var word


loop:
owout DQ,1,[$cc]
owout DQ,0,[$44]
Pause 500
owout DQ,1,[$cc]
owout DQ,0,[$be]
owin DQ, 0, [temperature.LOwBYTE, temperature.Highbyte, Skip 4, count_remain, count_per_c]
'50
temperature = ((( temperature >> 1) *100)- 25) + (((count_per_c - count_remain) * 100) / count_per_c)
tempc = (((temperature *9) / 5)+3200)
dataout = temperature / 100
dataout2 = temperature

encoded1 =temperature.LowBYTE
encoded2 =temperature.HighBYTE

For counter=0 TO 7
IF encoded1.0[counter]=0 Then
encoded11.0[counter*2]=0
encoded11.0[counter*2+1]=1
Else
encoded11.0[counter*2]=1
encoded11.0[counter*2+1]=0
EndIF
Next counter

For counter=0 TO 7
IF encoded2.0[counter]=0 Then
encoded22.0[counter*2]=0
encoded22.0[counter*2+1]=1
Else
encoded22.0[counter*2]=1
encoded22.0[counter*2+1]=0
EndIF
Next counter
lcdout $FE,1
LCDOUT BIN temperature , ".", dec (temperature / 10)," ",$DF,"C"
lcdout $FE,$C0, bin encoded22.HighBYTE , ".", bin encoded2," ",$DF,"F"
serout portb.2, n2400, [encoded22.HighBYTE, encoded22.LowBYTE, encoded11.HighBYTE, encoded11.LowBYTE ]
goto loop

End


AND RECEIVING:
' Picbasic Pro program to read DS1820 1-wire temperature sensor
' and display temperature on LCD
' FOR Receiving SERIAL
INCLUDE "modedefs.bas"
DEFINE OSC 20 'use external 20mhz crystal

CMCON = 7 : ANSEL = 0 : ADCON1 = 7
' Define LCD pins
DEFINE LCD_DREG PORTA ' Set LCD Data port
DEFINE LCD_DBIT 0 ' Set starting Data bit (0 or 4) if 4-bit bus

DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit

DEFINE LCD_EREG PORTB ' Set LCD Enable port
DEFINE LCD_EBIT 0 ' Set LCD Enable bit

DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
DEFINE LCD_LINES 2 ' Set number of lines on LCD
'22
datain2 var word
datain var word
dataout var word
counter var byte
temperature var word
encoded1 var word
encoded2 var word
encoded11 var word
encoded22 var word

pause 500

loop:
'36
serin portB.3, n2400,[ encoded22.HighBYTE, encoded22.LowBYTE, encoded11.HighBYTE, encoded11.LowBYTE]

lcdout $FE,1
LCDOUT "datain: ", BIN 5
lcdout $FE,$C0, "datain2: ", bin encoded22.HighBYTE , ".", dec datain2," ",$DF,"C"
Pause 500

For counter=0 TO 7 'decoding
encoded1.0[counter]=encoded11.0[counter*2]
encoded2.0[counter]=encoded22.0[counter*2]
Next counter

temperature= encoded1 ' putting back together as the original temperature
For counter=0 TO 7
temperature.0[counter+8]=encoded2.0[counter+8]
Next counter

goto loop

End

rhino
- 22nd December 2006, 18:37
If you're not using a Qualifier, I think you need to use Serin2. Maybe you can use it without the qualifier... I don't know.


SERIN Pin,Mode,{Timeout,Label,}{[Qual...],}{Item...}
‘ Wait until the character
serially on Pin1 and put
SERIN 1,N2400,[“A”],B0

....The list of data items to be received may be preceded by one or more
qualifiers enclosed within brackets. SERIN must receive these bytes in
exact order before receiving the data items.



SERIN2 DataPin{\FlowPin},Mode,{ParityLabel,}{Timeout,Labe l,}[Item...]
‘ Wait until the character “A” is received
serially on Pin1 and put next character into B0
SERIN2 1,16780,[WAIT(“A”),B0]

Either way, I'd try to send a qualifier down. Either the Serin format or as noted in the manual with Serin2.

skimask
- 22nd December 2006, 18:46
AND RECEIVING:
.......................................
pause 500

lcdout $FE,1 - put this above your main loop, you don't need to 'home' the LCD, you already do that with $FE,$C0.

loop:
'36
serin portB.3, n2400,[ encoded22.HighBYTE, encoded22.LowBYTE, encoded11.HighBYTE, encoded11.LowBYTE]

LCDOUT "datain: ", BIN 5 ------------- ???? what's this for?

lcdout $FE,$C0, "datain2: ", bin encoded22.HighBYTE , ".", dec datain2," ",$DF,"C" ---------- where is datain2 getting set at?

Pause 500

For counter=0 TO 7 'decoding
encoded1.0[counter]=encoded11.0[counter*2]
encoded2.0[counter]=encoded22.0[counter*2]
Next counter

temperature= encoded1 ' putting back together as the original temperature
For counter=0 TO 7
temperature.0[counter+8]=encoded2.0[counter+8]
Next counter

goto loop

End




No LCD_RWREG or LCD_RWBIT defines in either transmit or receive sections.

Add:
DEFINE LCD_COMMANDUS 2500
DEFINE LCD_DATAUS 250
to both sections.

Increase initial pause to 1000 or higher as needed.

Where is datain2 getting it's value from?

You don't do your decoding/etc until after you've displayed it. Change that around.

Check the listing above for other notes.

lerameur
- 22nd December 2006, 22:29
LCDOUT "datain: ", BIN 5 ------------- ???? what's this for?
I was just testing my LCDout

lcdout $FE,$C0, "datain2: ", bin encoded22.HighBYTE , ".", dec datain2," ",$DF,"C" ---------- where is datain2 getting set at?
Past program , forgot to remove it, was just using the first line for LCDout


In the receiving chip, nothing is happening, its going in but not recognizing it.
This is the code I have, nothing is going to the lcd screen. If I remove the SERIN line, then the LCDOUT work, but gives me all 1. (thats normal its not seeing anything)
How do i output this on the lcd ?
It seems that i cannot use the command SERIN and LCDOUT in the same program...


serin portB.2, n2400,[ encoded22.HighBYTE, encoded22.LowBYTE, encoded11.HighBYTE, encoded11.LowBYTE]

LCDOUT "d: ", BIN encoded22.HighBYTE ,".",bin encoded22.LowBYTE ---------------------not outputting what i want
lcdout $FE,$C0, "datain2: ", bin encoded22.HighBYTE , ".", bin encoded22.HighBYTE," ",$DF,"C"
Pause 500

skimask
- 23rd December 2006, 07:34
'TRANSMIT
INCLUDE "modedefs.bas"
DEFINE OSC 20 'use external 20mhz crystal
CMCON = 7 : ANSEL = 0 : ADCON1 = 7
DEFINE LCD_DREG PORTA ' Set LCD Data port
DEFINE LCD_DBIT 0 ' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
DEFINE LCD_EREG PORTB ' Set LCD Enable port
DEFINE LCD_EBIT 0 ' Set LCD Enable bit
DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
DEFINE LCD_LINES 2 ' Set number of lines on LCD

DEFINE LCD_RWREG ----------------DEFINE YOUR RW REGISTER
DEFINE LCD_RWBIT ----------------DEFINE YOUR RW REGISTER

trisb.2 = 0 : trisb.3 = 1 : dq var portb.4 : temp var word : tempf var word
pause 2500

loop:
lcdout $fe , $c0 , "Getting..."
owout DQ , 1 , [ $cc ] : owout DQ , 0 , [ $44 ] : Pause 500
owout DQ , 1 , [ $cc ] : owout DQ , 0 , [ $be ]
owin DQ , 0 , [ temp.LOWBYTE , temp.HIGHBYTE , skip 6 ]
tempf = temp * 9 : tempf = tempf / 5 : tempf = tempf + 32
lcdout $fe , $c0 , "Displaying"
lcdout $fe , $80 , "Tc=" , DEC temp , "C,Tf=" , DEC tempf , "F.."
lcdout $fe , $c0 , "Sending..." : serout portb.2 , n2400 , [ temp, tempf ]
lcdout $fe , $c0 , "Data Sent."
goto loop
End


'RECEIVE
INCLUDE "modedefs.bas"
DEFINE OSC 20 'use external 20mhz crystal
CMCON = 7 : ANSEL = 0 : ADCON1 = 7
DEFINE LCD_DREG PORTA ' Set LCD Data port
DEFINE LCD_DBIT 0 ' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
DEFINE LCD_EREG PORTB ' Set LCD Enable port
DEFINE LCD_EBIT 0 ' Set LCD Enable bit
DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
DEFINE LCD_LINES 2 ' Set number of lines on LCD

DEFINE LCD_RWREG ----------------DEFINE YOUR RW REGISTER
DEFINE LCD_RWBIT ----------------DEFINE YOUR RW REGISTER

temp var word : tempf var word : pause 2500
loop:
lcdout $fe , $c0 , "Waiting..."
serin portB.3 , n2400 , 1000 , loop , [ temp , tempf ]
lcdout $fe , $c0 , "Received.." : lcdout $fe , $c0 , "Displaying"
lcdout $fe , $80 , "Tc=" , DEC temp , "C,Tf=" , DEC tempf , ".."
lcdout $fe , $c0 , "Displayed."
goto loop
End



Little steps like I told you before...
Get the basics working. Add in the temperature correction code after you get the basic temperature displayed. Blow on the element, make it change, get it 'in the ballpark'. Forget about the encoding/decoding. If you can't get temp to be displayed as it is without the wireless, how are you going to get it to work with the wireless? Magic? Me thinks not...
Make your LCD work for you. Notice I added a bunch of lines telling me what the PIC is doing. Use them often!
And you had your C to F conversion backwards, and there was no way your original program was going to work. You had your decoding happening after you displayed the results. If you're going to send the whole code, send the whole code.
Post back when this works. If it doesn't work, you've got other problems, hardware.

lerameur
- 23rd December 2006, 13:28
about the LCD_RWREG, I stuck my lcd pin to ground, so it should always be write function.

I still get the same problem , The lcdout do not display the inpuT from serin. tHE LCD shows on the second line : 'Waiting...'
It seems to me that the as soon as it sees the serin command it skips all the lcdout afterward, and loops again.

skimask
- 23rd December 2006, 22:06
about the LCD_RWREG, I stuck my lcd pin to ground, so it should always be write function.

I still get the same problem , The lcdout do not display the inpuT from serin. tHE LCD shows on the second line : 'Waiting...'
It seems to me that the as soon as it sees the serin command it skips all the lcdout afterward, and loops again.

LCD_RWBIT....ok, understood. I'd define it anyways to an unused pin just to keep PBP from thinking otherwise.

Screwed up a bit overall. You can't send words thru a bytewide serial port!

Try this instead:


'TRANSMIT
INCLUDE "modedefs.bas"
DEFINE OSC 20 'use external 20mhz crystal
CMCON = 7 : ANSEL = 0 : ADCON1 = 7
DEFINE LCD_DREG PORTA ' Set LCD Data port
DEFINE LCD_DBIT 0 ' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
DEFINE LCD_EREG PORTB ' Set LCD Enable port
DEFINE LCD_EBIT 0 ' Set LCD Enable bit
DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
DEFINE LCD_LINES 2 ' Set number of lines on LCD

trisb.2 = 0 : trisb.3 = 1 : dq var portb.4 : temp var word : tempf var word
pause 2500

loop:
lcdout $fe , $c0 , "Getting..."
owout DQ , 1 , [ $cc ] : owout DQ , 0 , [ $44 ] : Pause 500
owout DQ , 1 , [ $cc ] : owout DQ , 0 , [ $be ]
owin DQ , 0 , [ temp.LOWBYTE , temp.HIGHBYTE , skip 6 ]
tempf = temp * 9 : tempf = tempf / 5 : tempf = tempf + 32
lcdout $fe , $c0 , "Displaying"
lcdout $fe , $80 , "Tc=" , DEC temp , "C,Tf=" , DEC tempf , "F.."
lcdout $fe , $c0 , "Sending..."
serout portb.2 , n2400 , [ temp.highbyte , temp.lowbyte ]
serout portb.2 , n2400 , [ tempf.highbyte , tempf.lowbyte ]
lcdout $fe , $c0 , "Data Sent."
goto loop
End


'RECEIVE
INCLUDE "modedefs.bas"
DEFINE OSC 20 'use external 20mhz crystal
CMCON = 7 : ANSEL = 0 : ADCON1 = 7
DEFINE LCD_DREG PORTA ' Set LCD Data port
DEFINE LCD_DBIT 0 ' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
DEFINE LCD_EREG PORTB ' Set LCD Enable port
DEFINE LCD_EBIT 0 ' Set LCD Enable bit
DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
DEFINE LCD_LINES 2 ' Set number of lines on LCD

temp var word : tempf var word : pause 2500
loop:
lcdout $fe , $c0 , "Waiting..."
serin portB.3 , n2400 , 1000 , loop , [ temp.highbyte , temp.lowbyte , tempf.highbyte , tempf.lowbyte ]
lcdout $fe , $c0 , "Received.." : lcdout $fe , $c0 , "Displaying"
lcdout $fe , $80 , "Tc=" , DEC temp , "C,Tf=" , DEC tempf , ".."
lcdout $fe , $c0 , "Displayed."
goto loop
End

lerameur
- 23rd December 2006, 22:41
The same thing is happeneing as before,
the LCD is just showing 'Waiting ... ' on the receiving unit
And I can see on the scope a signal coming in on portB3

ken

skimask
- 23rd December 2006, 22:46
The same thing is happeneing as before,
the LCD is just showing 'Waiting ... ' on the receiving unit

ken

Anything showing up on the first line? Something like:
Tc=100C,Tf=212 or anything similar?

lerameur
- 23rd December 2006, 22:54
the first line of the receiving unit is blank
the second: waiting ....

k

skimask
- 23rd December 2006, 23:05
the first line of the receiving unit is blank
the second: waiting ....

k


What does the transmitter lcd display?

lerameur
- 23rd December 2006, 23:08
TC=46c, Tf=114f
getting...

skimask
- 23rd December 2006, 23:18
TC=46c, Tf=114f
getting...

Ok, obviously the temp sensor code is working fine, and the receiver code is 'working'.

Check your wiring again. This should be working just fine. I just built up the same thing (during the last 10 minutes), 2 PIC16F628A's, exact code, simulated the one-wire temp sensor in the transmit section with some dummy values, added a button to change the number when pressed.
Both transmit and receive sections worked fine.
Are both sections on the same power and ground lines?

Use this code. Again, make the LCD work for you....

'TRANSMIT
INCLUDE "modedefs.bas"
DEFINE OSC 20 'use external 20mhz crystal
CMCON = 7 : ANSEL = 0 : ADCON1 = 7
DEFINE LCD_DREG PORTA ' Set LCD Data port
DEFINE LCD_DBIT 0 ' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
DEFINE LCD_EREG PORTB ' Set LCD Enable port
DEFINE LCD_EBIT 0 ' Set LCD Enable bit
DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
DEFINE LCD_LINES 2 ' Set number of lines on LCD
try1 var byte : output portb.2 : input portb.3 : dq var portb.4 : temp var word : tempf var word
pause 2500

loop:
try1 = try1 + 1
lcdout $fe , $c0 , "Getting..." , DEC3 try1 , "," , DEC3 try2
owout DQ , 1 , [ $cc ] : owout DQ , 0 , [ $44 ] : Pause 500
owout DQ , 1 , [ $cc ] : owout DQ , 0 , [ $be ]
owin DQ , 0 , [ temp.LOWBYTE , temp.HIGHBYTE , skip 6 ]
tempf = temp * 9 : tempf = tempf / 5 : tempf = tempf + 32
lcdout $fe , $c0 , "Displaying" , DEC3 try1 , "," , DEC3 try2
lcdout $fe , $80 , "Tc=" , DEC temp , "C,Tf=" , DEC tempf , "F.."
lcdout $fe , $c0 , "Sending..." , DEC3 try1 , "," , DEC3 try2
serout portb.2 , n2400 , [ temp.highbyte , temp.lowbyte ]
serout portb.2 , n2400 , [ tempf.highbyte , tempf.lowbyte ]
lcdout $fe , $c0 , "Data Sent." , DEC3 try1 , "," , DEC3 try2
goto loop
End




'RECEIVE
INCLUDE "modedefs.bas"
DEFINE OSC 20 'use external 20mhz crystal
CMCON = 7 : ANSEL = 0 : ADCON1 = 7
DEFINE LCD_DREG PORTA ' Set LCD Data port
DEFINE LCD_DBIT 0 ' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
DEFINE LCD_EREG PORTB ' Set LCD Enable port
DEFINE LCD_EBIT 0 ' Set LCD Enable bit
DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
DEFINE LCD_LINES 2 ' Set number of lines on LCD

'try1 = count of times waiting for bytes, try2 = count of bytes received
try1 var byte : try2 var byte : temp var word : tempf var word : input portb.3 : pause 2500

loop:
lcdout $fe , $c0 , "Waiting..." , DEC3 try1 , "," , DEC3 try2
try1 = try1 + 1
serin portB.3 , n2400 , 1000 , loop , [ temp.highbyte , temp.lowbyte , tempf.highbyte , tempf.lowbyte ]
try2 = try2 + 2
lcdout $fe , $c0 , "Received.." , DEC3 try1 , "," , DEC3 try2
lcdout $fe , $c0 , "Displaying" , DEC3 try1 , "," , DEC3 try2
lcdout $fe , $80 , "Tc=" , DEC temp , "C,Tf=" , DEC tempf , ".."
lcdout $fe , $c0 , "Displayed." , DEC3 try1 , "," , DEC3 try2
goto loop
End

lerameur
- 23rd December 2006, 23:29
yes they are on the same vdd and ground,
I just tried seperating them by putting the sedning end on a battery but no diferent.
Also the receiving, here is only one wire that is going in , the other wires are used for the LCD, obviously, the lcd works. I am putting the scope on the incoming port adn there is a signal in . The signal is sent every 500ms, Maybe that is too slow ?? and the receiving cant see it ..

ken

skimask
- 23rd December 2006, 23:36
yes they are on the same vdd and ground,
I just tried seperating them by putting the sedning end on a battery but no diferent.
Also the receiving, here is only one wire that is going in , the other wires are used for the LCD, obviously, the lcd works. I am putting the scope on the incoming port adn there is a signal in . The signal is sent every 500ms, Maybe that is too slow ?? and the receiving cant see it ..

ken




Which is why:
serin portB.3 , n2400 , 1000 , loop , [ temp.highbyte , temp.lowbyte , tempf.highbyte , tempf.lowbyte ]

It sits in a tight loop for 1000 ms waiting for anything to come across the serial lines. If nothing happens for 1000 ms, it jumps back to 'loop', which almost immediately goes back into the waiting loop. It's not going to miss anything.

Is the try1 counter going up by one about once a second on both ends?

lerameur
- 23rd December 2006, 23:54
try counter , what is that ?
I just moved the circuit to somewhere else on the breadboard, no changes

k

skimask
- 24th December 2006, 00:07
try counter , what is that ?
I just moved the circuit to somewhere else on the breadboard, no changes

k

3 or 4 posts ago, I changed the code, added a couple of counters...
making the lcd work for you!

lerameur
- 24th December 2006, 00:17
aa ok , i see that, my compiler does not recognize the 'dec3' command
picbasic pro 2.46

skimask
- 24th December 2006, 00:24
aa ok , i see that, my compiler does not recognize the 'dec3' command
picbasic pro 2.46

I'm running 2.46, using it just fine, no space between dec and 3. Just replace it with DEC and see what happens.

lerameur
- 24th December 2006, 00:42
ok, working now, Try2 was not initialized

the sending counter works, but is about incrementing once every .5 seconds
With temperature showing on the first line
The second lcd (receiving) nothing on the first line , and the counter is not counting, The counter starts when the wire (input) is disconnected
but NO Tc anf Tf
k

skimask
- 24th December 2006, 01:12
ok, working now, Try2 was not initialized

the sending counter works, but is about incrementing once every .5 seconds
With temperature showing on the first line
The second lcd (receiving) nothing on the first line , and the counter is not counting, The counter starts when the wire (input) is disconnected
but NO Tc anf Tf
k




Which PIC are you using?
And while we're at it, try changing the receiving PIC receiving line over to portb.2 and change the references. Who knows...maybe you blew out a pin.

lerameur
- 24th December 2006, 01:13
I have not changed Pic16f88

I also tried f84a, same thing
I dont have much in the 6 series, more in the 18,

skimask
- 24th December 2006, 01:18
I have not changed Pic16f88

I also tried f84a, same thing
I dont have much in the 6 series, more in the 18,




Have you got PGM pulled low for your programmer?

lerameur
- 24th December 2006, 01:23
dont know, I am using this programmer:

http://www.olimex.com/dev/pic-mcp-usb.html

skimask
- 24th December 2006, 01:36
dont know, I am using this programmer:

http://www.olimex.com/dev/pic-mcp-usb.html

Move the serial input port on the receiver from RB3 to RB2 and change the program as required.

lerameur
- 24th December 2006, 01:48
nothing, i tried that before, acually I tried all the ports (B), same thing.

k

skimask
- 24th December 2006, 01:51
nothing, i tried that before, acually I tried all the ports (B), same thing.

k



Post your receiver code again (since I think we can assume that the transmitter side is working fine)

and try switching to t2400 on the receiving side for the heck of it. If it doesn't work, change it back.

lerameur
- 24th December 2006, 02:10
I took a picture of both circuit
receiving on the left
http://www3.sympatico.ca/lerameur/

its the exacte code you gave me :

'RECEIVE
INCLUDE "modedefs.bas"
DEFINE OSC 20 'use external 20mhz crystal
CMCON = 7 : ANSEL = 0 : ADCON1 = 7
DEFINE LCD_DREG PORTA ' Set LCD Data port
DEFINE LCD_DBIT 0 ' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
DEFINE LCD_EREG PORTB ' Set LCD Enable port
DEFINE LCD_EBIT 0 ' Set LCD Enable bit
DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
DEFINE LCD_LINES 2 ' Set number of lines on LCD

'try1 = count of times waiting for bytes, try2 = count of bytes received
try1 var byte : try2 var byte : temp var word : tempf var word : input portb.3 : pause 2500

loop:
lcdout $fe , $c0 , "Waiting..." , DEC3 try1 , "," , DEC3 try2
try1 = try1 + 1
serin portB.3 , n2400 , 1000 , loop , [ temp.highbyte , temp.lowbyte , tempf.highbyte , tempf.lowbyte ]
try2 = try2 + 2
lcdout $fe , $c0 , "Received.." , DEC3 try1 , "," , DEC3 try2
lcdout $fe , $c0 , "Displaying" , DEC3 try1 , "," , DEC3 try2
lcdout $fe , $80 , "Tc=" , DEC temp , "C,Tf=" , DEC tempf , ".."
lcdout $fe , $c0 , "Displayed." , DEC3 try1 , "," , DEC3 try2
goto loop
End

skimask
- 24th December 2006, 02:22
I took a picture of both circuit
receiving on the left
http://www3.sympatico.ca/lerameur/

its the exacte code you gave me :

'RECEIVE
INCLUDE "modedefs.bas"
DEFINE OSC 20 'use external 20mhz crystal
CMCON = 7 : ANSEL = 0 : ADCON1 = 7
DEFINE LCD_DREG PORTA ' Set LCD Data port
DEFINE LCD_DBIT 0 ' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
DEFINE LCD_EREG PORTB ' Set LCD Enable port
DEFINE LCD_EBIT 0 ' Set LCD Enable bit
DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
DEFINE LCD_LINES 2 ' Set number of lines on LCD

'try1 = count of times waiting for bytes, try2 = count of bytes received
try1 var byte : try2 var byte : temp var word : tempf var word : input portb.3 : pause 2500

loop:
lcdout $fe , $c0 , "Waiting..." , DEC3 try1 , "," , DEC3 try2
try1 = try1 + 1
serin portB.3 , n2400 , 1000 , loop , [ temp.highbyte , temp.lowbyte , tempf.highbyte , tempf.lowbyte ]
try2 = try2 + 2
lcdout $fe , $c0 , "Received.." , DEC3 try1 , "," , DEC3 try2
lcdout $fe , $c0 , "Displaying" , DEC3 try1 , "," , DEC3 try2
lcdout $fe , $80 , "Tc=" , DEC temp , "C,Tf=" , DEC tempf , ".."
lcdout $fe , $c0 , "Displayed." , DEC3 try1 , "," , DEC3 try2
goto loop
End

The picture at the site is messed up. Scale it down or something.
Have you tried switching the pins/code over to RB2?
Have you tried changing the receiver to t2400?

Change
serin portB.3 , n2400 , 1000 , loop , [ temp.highbyte , temp.lowbyte , tempf.highbyte , tempf.lowbyte ]

to
serin portB.2 , n2400 , 100 , loop , [ temp.highbyte , temp.lowbyte , tempf.highbyte , tempf.lowbyte ]

Now you should see try1 increment fast, like 10 times per second.
Wait on it for a couple of minutes. If it only increases about once a minute or so, something is wrong with your oscillator, it's running on the internal backup failsafe oscillator.

I thought you said DEC3 doesn't work?

lerameur
- 24th December 2006, 02:36
the site is ok now,

the counter goes up ten times as fast

I change to t2400 and n 2400 , no change,

bth crytals are clocking 20 Mhz,

also I have been swaping pic, i am using 2 pic16f88, so they can be both ****ed up, and I have a third one, with no change,
I just tried a brand new pic88, no changes, i swapped the crytals between the two circuits too!

I thought you said DEC3 doesn't work? yes I thought, it was because try2 was not initialized, and it happend only where dec3 was, . The other program was compiling

skimask
- 24th December 2006, 02:47
the site is ok now,

the counter goes up ten times as fast

I change to t2400 and n 2400 , no change,

bth crytals are clocking 20 Mhz,

also I have been swaping pic, i am using 2 pic16f88, so they can be both ****ed up, and I have a third one, with no change,
I just tried a brand new pic88, no changes, i swapped the crytals between the two circuits too!

I thought you said DEC3 doesn't work? yes I thought, it was because try2 was not initialized, and it happend only where dec3 was, . The other program was compiling

What is that big yellow wire for? The one that looks like it's going over the top of the picture? Either that or zoom back out just a little bit more for your picture....

lerameur
- 24th December 2006, 02:49
that is the data, serout going to the input pin of the other circuit

i also tried an f648a, nothing on the lcd
k

lerameur
- 24th December 2006, 03:39
I just flip the circuit around, I mean take the receiving chip put it in the sending circuit and flip the other chip around, Then I just plug in the input wire to the new receiving chip.
Same output as before. The receiving LCD just sits there

skimask
- 24th December 2006, 04:12
that is the data, serout going to the input pin of the other circuit


i also tried an f648a, nothing on the lcd
k

Ok, I'm back...the relatives showed up for a bit...had to deal with them...

Your programs:
Transmit side - output is on RB2, correct?
Receive side - input on RB3, correct?

And the big yellow wire is the data wire right?

lerameur
- 24th December 2006, 04:40
yes that sit,
Its hard to belive it works on your end.

thats ok , i was watching mad tv...

skimask
- 24th December 2006, 04:41
yes that sit,
Its hard to belive it works on your end.

Well, do me a favor....
Take that big yellow wire, follow it to the PIC on the right.
Consult your datasheet, and tell me what pin it goes to.

Then take that same big fat yellow wire, follow it to the PIC on the left, consult your datasheet, tell me what pin that goes to....and fix it!

lerameur
- 24th December 2006, 04:56
in the picture I had just finish trying all the B ports., It was in RB6, which was the last of the port I tried
the sending IS on RB2
and Receiving is on RB3

go back to the web site i posted a new picture

skimask
- 24th December 2006, 04:59
in the picture I had just finish trying all the B ports., It was in RB6, which was the last of the port I tried
the sending IS on RB2
and Receiving is on RB3

Then put up a fresh picture and change your receiver to portb.2

lerameur
- 24th December 2006, 05:10
Ok so now both receiver and transmitter are on portb.2
the picture is up

would the problem be in the software, is the pic16f88 special and need extra attention ?

skimask
- 24th December 2006, 05:26
Ok so now both receiver and transmitter are on portb.2
the picture is up

would the problem be in the software, is the pic16f88 special and need extra attention ?

It does...but I think I'm onto something....
On the receiver PIC, it shows:
Waiting...127,22
The 127 is the number of times it's tried to receive data but timed out, the 22 is the number of times it's actually received 4 bytes of data and dropped thru to the display section.
Post your receiver code as it stands again.
Something is amiss. If the serial port wasn't receiving anything (i.e. the serin statement always timed out and went back to loop, the 22 should remain a 0).

lerameur
- 24th December 2006, 05:31
for the receiving code, as soon as I open the power supply I get a different number
trial1: Waiting... 111,22
trial2: Waiting... 111,21
trial3: Waiting... 127,22
trial4: Waiting... 107,21
.....
when I leave the power off for a while, it seems to come back to Waiting... 111,22 when the power is turned on

once the number is there , it stays, it do not move, NO increment.



'RECEIVE
INCLUDE "modedefs.bas"
DEFINE OSC 20 'use external 20mhz crystal
CMCON = 7 : ANSEL = 0 : ADCON1 = 7
DEFINE LCD_DREG PORTA ' Set LCD Data port
DEFINE LCD_DBIT 0 ' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
DEFINE LCD_EREG PORTB ' Set LCD Enable port
DEFINE LCD_EBIT 0 ' Set LCD Enable bit
DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
DEFINE LCD_LINES 2 ' Set number of lines on LCD

'try1 = count of times waiting for bytes, try2 = count of bytes received
try1 var byte : try2 var byte : temp var word : tempf var word : input portb.3 : pause 2500

loop:
lcdout $fe , $c0 , "Waiting..." , DEC3 try1 , "," , DEC3 try2
try1 = try1 + 1
serin portB.2 , n2400 , 1000 , loop , [ temp.highbyte , temp.lowbyte , tempf.highbyte , tempf.lowbyte ]
try2 = try2 + 2
lcdout $fe , $c0 , "Received.." , DEC3 try1 , "," , DEC3 try2
lcdout $fe , $c0 , "Displaying" , DEC3 try1 , "," , DEC3 try2
lcdout $fe , $80 , "Tc=" , DEC temp , "C,Tf=" , DEC tempf , ".."
lcdout $fe , $c0 , "Displayed." , DEC3 try1 , "," , DEC3 try2
goto loop
End



'TRANSMIT
INCLUDE "modedefs.bas"
DEFINE OSC 20 'use external 20mhz crystal
CMCON = 7 : ANSEL = 0 : ADCON1 = 7
DEFINE LCD_DREG PORTA ' Set LCD Data port
DEFINE LCD_DBIT 0 ' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
DEFINE LCD_EREG PORTB ' Set LCD Enable port
DEFINE LCD_EBIT 0 ' Set LCD Enable bit
DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
DEFINE LCD_LINES 2 ' Set number of lines on LCD
try1 var byte : output portb.2 : input portb.3 : dq var portb.4 : temp var word : tempf var word
pause 2500
try2 var byte
loop:
try1 = try1 + 1
lcdout $fe , $c0 , "Getting..." , DEC3 try1 , "," , DEC3 try2

owout DQ , 1 , [ $cc ] : owout DQ , 0 , [ $44 ] : Pause 500
owout DQ , 1 , [ $cc ] : owout DQ , 0 , [ $be ]
owin DQ , 0 , [ temp.LOWBYTE , temp.HIGHBYTE , skip 6 ]
tempf = temp * 9 : tempf = tempf / 5 : tempf = tempf + 32
lcdout $fe , $c0 , "Displaying" , DEC3 try1 , "," , DEC3 try2
lcdout $fe , $80 , "Tc=" , DEC temp , "C,Tf=" , DEC tempf , "F.."
lcdout $fe , $c0 , "Sending..." , DEC3 try1 , "," , DEC3 try2
serout portb.2 , n2400 , [ temp.highbyte , temp.lowbyte ]
serout portb.2 , n2400 , [ tempf.highbyte , tempf.lowbyte ]
lcdout $fe , $c0 , "Data Sent." , DEC3 try1 , "," , DEC3 try2
goto loop
End

skimask
- 24th December 2006, 05:40
'RECEIVE
INCLUDE "modedefs.bas"
DEFINE OSC 20 'use external 20mhz crystal
CMCON = 7 : ANSEL = 0 : ADCON1 = 7
DEFINE LCD_DREG PORTA ' Set LCD Data port
DEFINE LCD_DBIT 0 ' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
DEFINE LCD_EREG PORTB ' Set LCD Enable port
DEFINE LCD_EBIT 0 ' Set LCD Enable bit
DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
DEFINE LCD_LINES 2 ' Set number of lines on LCD

'try1 = count of times waiting for data, try2 = count of bytes received
try1 var byte : try2 var byte : temp var word : tempf var word : input portb.2 : pause 2500
try1 = 0 : try2 = 0

loop:
lcdout $fe , $c0 , "Waiting.." , DEC3 try1 , "," , DEC3 try2
try1 = try1 + 1
serin portB.2 , n2400 , 1000 , loop , [ temp.highbyte , temp.lowbyte , tempf.highbyte , tempf.lowbyte ]
try2 = try2 + 4
lcdout $fe , $c0 , "Received." , DEC3 try1 , "," , DEC3 try2 : pause 100
lcdout $fe , $c0 , "Display.." , DEC3 try1 , "," , DEC3 try2 : pause 100
lcdout $fe , $80 , "Tc=" , DEC3 temp , "C,Tf=" , DEC3 tempf , ".." : pause 100
lcdout $fe , $c0 , "Shown...." , DEC3 try1 , "," , DEC3 try2 : pause 100
goto loop
End



'TRANSMIT
INCLUDE "modedefs.bas"
DEFINE OSC 20 'use external 20mhz crystal
CMCON = 7 : ANSEL = 0 : ADCON1 = 7
DEFINE LCD_DREG PORTA ' Set LCD Data port
DEFINE LCD_DBIT 0 ' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
DEFINE LCD_EREG PORTB ' Set LCD Enable port
DEFINE LCD_EBIT 0 ' Set LCD Enable bit
DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
DEFINE LCD_LINES 2 ' Set number of lines on LCD
try1 var byte : try2 var byte : output portb.2 : input portb.3
dq var portb.4 : temp var word : tempf var word
pause 2500
try1 = 0 : try2 = 0

loop:
try1 = try1 + 1
lcdout $fe , $c0 , "Getting.." , DEC3 try1 , "," , DEC3 try2
owout DQ , 1 , [ $cc ] : owout DQ , 0 , [ $44 ] : Pause 500
owout DQ , 1 , [ $cc ] : owout DQ , 0 , [ $be ]
owin DQ , 0 , [ temp.LOWBYTE , temp.HIGHBYTE , skip 6 ]
tempf = temp * 9 : tempf = tempf / 5 : tempf = tempf + 32
lcdout $fe , $c0 , "Display.." , DEC3 try1 , "," , DEC3 try2
lcdout $fe , $80 , "Tc=" , DEC3 temp , "C,Tf=" , DEC tempf , "F."
lcdout $fe , $c0 , "Sending.." , DEC3 try1 , "," , DEC3 try2
serout portb.2 , n2400 , [ temp.highbyte , temp.lowbyte ]
serout portb.2 , n2400 , [ tempf.highbyte , tempf.lowbyte ]
try2 = try2 + 4 : lcdout $fe , $c0 , "Sent....." , DEC3 try1 , "," , DEC3 try2
goto loop



Try those code chunks. I get the feeling that the lcd at the receiver end might have been overwriting itself, thereby blanking out the data or something. I also added a couple of pauses in there so you could see what was going on. Also, you didn't set the receiver port to an input (I know serin says it does this for you, but I never trust stuff like that).

lerameur
- 24th December 2006, 05:49
I tried setting Trisb.2 before and it did ot hnage anythimg so I put it rightback.
Ok now , the sending side, there is an incrementation, and for the first time try2 is incrementing, and it does so by 4.

On the receiver side, first line; empty, second line: 'Waiting... 000,000'

I also added these twoline:
DEFINE LCD_COMMANDUS 2500
DEFINE LCD_DATAUS 250
but no luck either

lerameur
- 24th December 2006, 06:03
I'm off to bed , be back tomorrow morning

skimask
- 24th December 2006, 06:06
On the receiver side, first line; empty, second line: 'Waiting... 000,000'


It's not incrementing at all on the receiving side? Try1 should be going up about once a second.


Add:
DEFINE CHAR_PACING 16667

to the transmit program's defines at the beginning. Maybe the receiver is missing characters 'cause they're coming too fast with the software based serin command. If that fixes it, it'll probably work with a value much less than 16667, but it's a start.

lerameur
- 24th December 2006, 06:13
NO incrementation on the receiver. The same with all zeros all the time
what about using the serin2 command ??

with the new define, I can see glitches of 'Sending...' on the second line of the sending side. But most often it is on like before, 'Getting...'

skimask
- 24th December 2006, 06:23
NO incrementation on the receiver. The same with all zeros all the time
what about using the serin2 command ??

with the new define, I can see glitches of 'Sending...' on the second line of the sending side. But most often it is on like before, 'Getting...'

Transmit side - sounds like it's doing like it should.

Receive side - try this one:

'RECEIVE
INCLUDE "modedefs.bas"
DEFINE OSC 20 'use external 20mhz crystal
CMCON = 7 : ANSEL = 0 : ADCON1 = 7
DEFINE LCD_DREG PORTA ' Set LCD Data port
DEFINE LCD_DBIT 0 ' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
DEFINE LCD_EREG PORTB ' Set LCD Enable port
DEFINE LCD_EBIT 0 ' Set LCD Enable bit
DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
DEFINE LCD_LINES 2 ' Set number of lines on LCD

'try1 = count of times waiting for data, try2 = count of bytes received
try1 var byte : try2 var byte : temp var word : tempf var word : input portb.2 : pause 2500
try1 = 0 : try2 = 0

loop:
lcdout $fe , $c0 , "Waiting.." , DEC3 try1 , "," , DEC3 try2
try1 = try1 + 1 : temp = 0 : tempf = 0
serin portB.2 , n2400 , [ temp.highbyte , temp.lowbyte , tempf.highbyte , tempf.lowbyte ]
if temp + tempf > 0 then try2 = try2 + 1 'if temp+tempf are not 0 then data received
lcdout $fe , $c0 , "Received." , DEC3 try1 , "," , DEC3 try2 : pause 100
lcdout $fe , $c0 , "Display.." , DEC3 try1 , "," , DEC3 try2 : pause 100
lcdout $fe , $80 , "Tc=" , DEC3 temp , "C,Tf=" , DEC3 tempf , ".." : pause 100
lcdout $fe , $c0 , "Shown...." , DEC3 try1 , "," , DEC3 try2 : pause 100
goto loop
End

lerameur
- 24th December 2006, 06:26
absolutely no changes :(

skimask
- 24th December 2006, 06:29
absolutely no changes :(

On the receiver side...
Change the word 'Waiting..' to
'Wait 4 it'
and see what happens

lerameur
- 24th December 2006, 06:32
O my I changed to this
serin portB.2 , t2400 , [ temp.highbyte , temp.lowbyte , tempf.highbyte , tempf.lowbyte ]

now the temp is showing up on first line, BUT is it showing zeros,
incrementation on try, try2 fixed at 0

check the web page also, for output on lcd

also:
On the receiver side...
Change the word 'Waiting..' to
'Wait 4 it'
and see what happens ----------- Only the display changed

skimask
- 24th December 2006, 06:44
O my I changed to this
serin portB.2 , t2400 , [ temp.highbyte , temp.lowbyte , tempf.highbyte , tempf.lowbyte ]

now the temp is showing up on first line, BUT is it showing zeros,
incrementation on try, try2 fixed at 0

check the web page also, for output on lcd

also:
On the receiver side...
Change the word 'Waiting..' to
'Wait 4 it'
and see what happens ----------- Only the display changed

receiver side change - That's what I was wondering. I had a case a couple days ago where I thought it was programming, but the PGD wire had come loose from my board, so it wasn't actually programming, even though it didn't report any errors (and I had my verify turned off!).

Changing to t2400 is going to do exactly what you saw. But it doesn't fix anything. Leave it at n2400, or try changing both sides to t2400.

And try putting a small resistor inline with the big yellow wire, about 100 ohms or so. Without it, it's almost like a direct short from power to ground from one PIC to another. I should've caught this earlier.

lerameur
- 24th December 2006, 06:48
I will leave is at n2400 then
also, are you saying my pgd wire is messed up ??
I am not sure what it is ? it is programming the sending side.., I am not sure what you meant

The 100 ohm resistor did not do anything .

skimask
- 24th December 2006, 06:55
I will leave is at n2400 then
also, are you saying my pgd wire is messed up ??
I am not sure what it is ? it is programming the sending side.., I am not sure what you meant

The 100 ohm resistor did not do anything .

Yes, try changing both sides to t2400 instead of n2400.
You must be pulling the chips out and programming them. Changing the 'Waiting...' was just a quick way to make sure the PIC was actually being reprogrammed.

I didn't expect the 100 ohm resistor to change anything, it's just a good idea from a 'safety' standpoint, saves PICs from blowing themselves up.


And this is going to sound a bit wierd, but I'm wondering if SERIN and SEROUT don't like to deal with temp.highbyte and would rather deal with a byte value instead. Give me a couple of minutes to rewrite the programs and I'll post them in a couple of minutes.

lerameur
- 24th December 2006, 06:58
I didn't expect the 100 ohm resistor to change anything, it's just a good idea from a 'safety' standpoint, saves PICs from blowing themselves up.[/QUOTE]
ok too much current, I get it

no changes with t2400 on both chips

Ok I changed the speed to 9600.
I get the temperature showing on the receiving ship, but its showing zeros.
also the increment try do not increment , But when i disconnect the wire, it increments every 0.5 sec

skimask
- 24th December 2006, 07:06
'RECEIVE
INCLUDE "modedefs.bas"
DEFINE OSC 20 'use external 20mhz crystal
CMCON = 7 : ANSEL = 0 : ADCON1 = 7
DEFINE LCD_DREG PORTA ' Set LCD Data port
DEFINE LCD_DBIT 0 ' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
DEFINE LCD_EREG PORTB ' Set LCD Enable port
DEFINE LCD_EBIT 0 ' Set LCD Enable bit
DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
DEFINE LCD_LINES 2 ' Set number of lines on LCD
DEFINE LCD_COMMANDUS 2500
DEFINE LCD_DATAUS 250

'try1 = count of times waiting for data, try2 = count of bytes received
try1 var byte : try2 var byte : temp var word : tempf var word
temp1 var byte : temp2 var byte : temp3 var byte : temp4 var byte
input portb.2 : pause 2500
try1 = 0 : try2 = 0

loop:
lcdout $fe , $c0 , "Waiting.." , DEC3 try1 , "," , DEC3 try2
try1 = try1 + 1 : temp = 0 : tempf = 0
serin portB.2 , t2400 , [ temp1 , temp2 , temp3 , temp4 ]
temp.highbyte = temp1 : temp.lowbyte = temp2 : tempf.highbyte = temp3 : tempf.lowbyte = temp4
if temp + tempf > 0 then try2 = try2 + 1 'if temp+tempf are not 0 then data received
lcdout $fe , $c0 , "Received." , DEC3 try1 , "," , DEC3 try2 : pause 100
lcdout $fe , $c0 , "Display.." , DEC3 try1 , "," , DEC3 try2 : pause 100
lcdout $fe , $80 , "Tc=" , DEC3 temp , "C,Tf=" , DEC3 tempf , ".." : pause 100
lcdout $fe , $c0 , "Shown...." , DEC3 try1 , "," , DEC3 try2 : pause 100
goto loop
End







'TRANSMIT
INCLUDE "modedefs.bas"
DEFINE OSC 20 'use external 20mhz crystal
CMCON = 7 : ANSEL = 0 : ADCON1 = 7
DEFINE LCD_DREG PORTA ' Set LCD Data port
DEFINE LCD_DBIT 0 ' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
DEFINE LCD_EREG PORTB ' Set LCD Enable port
DEFINE LCD_EBIT 0 ' Set LCD Enable bit
DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
DEFINE LCD_LINES 2 ' Set number of lines on LCD
DEFINE LCD_COMMANDUS 2500
DEFINE LCD_DATAUS 250
DEFINE CHAR_PACING 16667

try1 var byte : try2 var byte : output portb.2 : input portb.3
dq var portb.4 : temp var word : tempf var word
temp1 var byte : temp2 var byte : temp3 var byte : temp4 var byte
pause 2500
try1 = 0 : try2 = 0

loop:
try1 = try1 + 1
lcdout $fe , $c0 , "Getting.." , DEC3 try1 , "," , DEC3 try2
owout DQ , 1 , [ $cc ] : owout DQ , 0 , [ $44 ] : Pause 500
owout DQ , 1 , [ $cc ] : owout DQ , 0 , [ $be ]
owin DQ , 0 , [ temp.LOWBYTE , temp.HIGHBYTE , skip 6 ]
tempf = temp * 9 : tempf = tempf / 5 : tempf = tempf + 32
lcdout $fe , $c0 , "Display.." , DEC3 try1 , "," , DEC3 try2
lcdout $fe , $80 , "Tc=" , DEC3 temp , "C,Tf=" , DEC tempf , "F."
lcdout $fe , $c0 , "Sending.." , DEC3 try1 , "," , DEC3 try2
temp1 = temp.highbyte : temp2 = temp.lowbyte
serout portb.2 , t2400 , [ temp1 , temp2 ]
temp3 = tempf.highbyte : temp4 = tempf.lowbyte
serout portb.2 , t2400 , [ temp3 , temp4 ]
try2 = try2 + 4 : lcdout $fe , $c0 , "Sent....." , DEC3 try1 , "," , DEC3 try2
goto loop



If that works, then great. I don't know why it works. The PBP manual says the other way should work, but I seem to remember running into this problem before and had to do the same thing, I can't remember what I was doing though.

lerameur
- 24th December 2006, 07:12
sorry, still showing zeros at the receiving end, with nothing on the first line

skimask
- 24th December 2006, 07:18
Then try this code for both TX and RX sides:

'RECEIVE
INCLUDE "modedefs.bas"
DEFINE OSC 20 'use external 20mhz crystal
CMCON = 7 : ANSEL = 0 : ADCON1 = 7
DEFINE LCD_DREG PORTA ' Set LCD Data port
DEFINE LCD_DBIT 0 ' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
DEFINE LCD_EREG PORTB ' Set LCD Enable port
DEFINE LCD_EBIT 0 ' Set LCD Enable bit
DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
DEFINE LCD_LINES 2 ' Set number of lines on LCD
DEFINE LCD_COMMANDUS 2500
DEFINE LCD_DATAUS 250

'try1 = count of times waiting for data, try2 = count of bytes received
try1 var byte : try2 var byte : temp var word : tempf var word
temp1 var byte : temp2 var byte : temp3 var byte : temp4 var byte
input portb.2 : pause 2500
try1 = 0 : try2 = 0

loop:
lcdout $fe , $c0 , "Waiting.." , DEC3 try1 , "," , DEC3 try2
try1 = try1 + 1 : temp = 0 : tempf = 0
serin portB.2 , t2400 , [ temp1 , temp2 , temp3 , temp4 ]
temp1 = 3 : temp2 = 120 'hardcode receiver to display 888 in tempc space
temp.highbyte = temp1 : temp.lowbyte = temp2 : tempf.highbyte = temp3 : tempf.lowbyte = temp4
if temp + tempf > 0 then try2 = try2 + 1 'if temp+tempf are not 0 then data received
lcdout $fe , $c0 , "Received." , DEC3 try1 , "," , DEC3 try2 : pause 100
lcdout $fe , $c0 , "Display.." , DEC3 try1 , "," , DEC3 try2 : pause 100
lcdout $fe , $80 , "Tc=" , DEC3 temp , "C,Tf=" , DEC3 tempf , ".." : pause 100
lcdout $fe , $c0 , "Shown...." , DEC3 try1 , "," , DEC3 try2 : pause 100
goto loop
End







'TRANSMIT
INCLUDE "modedefs.bas"
DEFINE OSC 20 'use external 20mhz crystal
CMCON = 7 : ANSEL = 0 : ADCON1 = 7
DEFINE LCD_DREG PORTA ' Set LCD Data port
DEFINE LCD_DBIT 0 ' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
DEFINE LCD_EREG PORTB ' Set LCD Enable port
DEFINE LCD_EBIT 0 ' Set LCD Enable bit
DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
DEFINE LCD_LINES 2 ' Set number of lines on LCD
DEFINE LCD_COMMANDUS 2500
DEFINE LCD_DATAUS 250
DEFINE CHAR_PACING 16667

try1 var byte : try2 var byte : output portb.2 : input portb.3
dq var portb.4 : temp var word : tempf var word
temp1 var byte : temp2 var byte : temp3 var byte : temp4 var byte
pause 2500
try1 = 0 : try2 = 0

loop:
try1 = try1 + 1
lcdout $fe , $c0 , "Getting.." , DEC3 try1 , "," , DEC3 try2
owout DQ , 1 , [ $cc ] : owout DQ , 0 , [ $44 ] : Pause 500
owout DQ , 1 , [ $cc ] : owout DQ , 0 , [ $be ]
owin DQ , 0 , [ temp.LOWBYTE , temp.HIGHBYTE , skip 6 ]
tempf = temp * 9 : tempf = tempf / 5 : tempf = tempf + 32

tempf = 444 'hardcode transmitter to have 444 in tempf space

lcdout $fe , $c0 , "Display.." , DEC3 try1 , "," , DEC3 try2
lcdout $fe , $80 , "Tc=" , DEC3 temp , "C,Tf=" , DEC tempf , "F."
lcdout $fe , $c0 , "Sending.." , DEC3 try1 , "," , DEC3 try2
temp1 = temp.highbyte : temp2 = temp.lowbyte
serout portb.2 , t2400 , [ temp1 , temp2 ]
temp3 = tempf.highbyte : temp4 = tempf.lowbyte
serout portb.2 , t2400 , [ temp3 , temp4 ]
try2 = try2 + 4 : lcdout $fe , $c0 , "Sent....." , DEC3 try1 , "," , DEC3 try2
goto loop

lerameur
- 24th December 2006, 07:23
still no changes from previous. I just check the hardware, and seems to be ok, Cystal is oscillating at 20Mhz on both sides.

skimask
- 24th December 2006, 07:30
still no changes from previous. I just check the hardware, and seems to be ok, Cystal is oscillating at 20Mhz on both sides.

Could ya post another picture?

lerameur
- 24th December 2006, 07:33
actually I did, th e pic is back , i will do another one with the last circuit
I just tried sending a constant over, and displaying it on the receiving end and it still gives me zero, maybe breaking the program into even more basic ?

new PIC online

with this last program, both counters are working on both chips.

skimask
- 24th December 2006, 07:38
actually I did, th e pic is back , i will do another one with the last circuit
I just tried sending a constant over, and displaying it on the receiving end and it still gives me zero, maybe breaking the program into even more basic ?

Did you make the changes in post #61?

I saw the new picture. Let me think about this for a couple of minutes...


Is the sending pic on the left or the right? Could you mark them with something...piece of masking tape on the transmitting pic or something?

lerameur
- 24th December 2006, 07:44
Did you make the changes in post #61?

I saw the new picture. Let me think about this for a couple of minutes...
it updated now

lerameur
- 24th December 2006, 07:54
ok I am gpoing to bed now, see ya tomorrow

skimask
- 24th December 2006, 07:54
it updated now

3 more things to try to get this narrowed down...bear with me....

Try this out now:


'RECEIVE PIC

INCLUDE "modedefs.bas"
DEFINE OSC 20 'use external 20mhz crystal
CMCON = 7 : ANSEL = 0 : ADCON1 = 7
DEFINE LCD_DREG PORTA ' Set LCD Data port
DEFINE LCD_DBIT 0 ' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
DEFINE LCD_EREG PORTB ' Set LCD Enable port
DEFINE LCD_EBIT 0 ' Set LCD Enable bit
DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
DEFINE LCD_LINES 2 ' Set number of lines on LCD
DEFINE LCD_COMMANDUS 2500
DEFINE LCD_DATAUS 250

'try1 = count of times waiting for data, try2 = count of bytes received
try1 var byte : try2 var byte : temp var word : tempf var word
temp1 var byte : temp2 var byte : temp3 var byte : temp4 var byte
input portb.2 : pause 2500
try1 = 0 : try2 = 0

loop:
lcdout $fe , $c0 , "Waiting.." , DEC3 try1 , "," , DEC3 try2
try1 = try1 + 1 : temp = 0 : tempf = 0
serin portB.2 , t2400 , [ temp1 , temp2 , temp3 , temp4 ]
temp.highbyte = temp1 : temp.lowbyte = temp2 : tempf.highbyte = temp3 : tempf.lowbyte = temp4
if temp + tempf > 0 then try2 = try2 + 1 'if temp+tempf are not 0 then data received
lcdout $fe , $c0 , "Received." , DEC3 try1 , "," , DEC3 try2 : pause 100
lcdout $fe , $c0 , "Display.." , DEC3 try1 , "," , DEC3 try2 : pause 100
lcdout $fe , $80 , "Tc=" , DEC3 temp , "C,Tf=" , DEC3 tempf , "FR" : pause 100
lcdout $fe , $c0 , "Shown...." , DEC3 try1 , "," , DEC3 try2 : pause 100
goto loop
End











'TRANSMIT PIC

INCLUDE "modedefs.bas"
DEFINE OSC 20 'use external 20mhz crystal
CMCON = 7 : ANSEL = 0 : ADCON1 = 7
DEFINE LCD_DREG PORTA ' Set LCD Data port
DEFINE LCD_DBIT 0 ' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
DEFINE LCD_EREG PORTB ' Set LCD Enable port
DEFINE LCD_EBIT 0 ' Set LCD Enable bit
DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
DEFINE LCD_LINES 2 ' Set number of lines on LCD
DEFINE LCD_COMMANDUS 2500
DEFINE LCD_DATAUS 250
DEFINE CHAR_PACING 16667

try1 var byte : try2 var byte : output portb.2 : input portb.3
dq var portb.4 : temp var word : tempf var word
temp1 var byte : temp2 var byte : temp3 var byte : temp4 var byte
pause 2500
try1 = 0 : try2 = 0

loop:
try1 = try1 + 1
lcdout $fe , $c0 , "Getting.." , DEC3 try1 , "," , DEC3 try2
owout DQ , 1 , [ $cc ] : owout DQ , 0 , [ $44 ] : Pause 500
owout DQ , 1 , [ $cc ] : owout DQ , 0 , [ $be ]
owin DQ , 0 , [ temp.LOWBYTE , temp.HIGHBYTE , skip 6 ]
tempf = temp * 9 : tempf = tempf / 5 : tempf = tempf + 32

tempf = 444 'hardcode transmitter to have 444 in tempf space
temp = 888 'hardcode transmitter to have 888 in temp space
lcdout $fe , $c0 , "Display.." , DEC3 try1 , "," , DEC3 try2
lcdout $fe , $80 , "Tc=" , DEC3 temp , "C,Tf=" , DEC3 tempf , "FT"
lcdout $fe , $c0 , "Sending.." , DEC3 try1 , "," , DEC3 try2
temp1 = temp.highbyte : temp2 = temp.lowbyte
serout portb.2 , t2400 , [ temp1 , temp2 ]
temp3 = tempf.highbyte : temp4 = tempf.lowbyte
serout portb.2 , t2400 , [ temp3 , temp4 ]
try2 = try2 + 4 : lcdout $fe , $c0 , "Sent....." , DEC3 try1 , "," , DEC3 try2
goto loop

lerameur
- 24th December 2006, 07:57
o, I wil wait a bit,

the receing LCD shows only on the second line, with zerosss.

skimask
- 24th December 2006, 08:03
o, I wil wait a bit,

the receing LCD shows only on the second line, with zerosss.

Are you splitting that program up between the 2 PICs or programming the whole thing into one PIC?

lerameur
- 24th December 2006, 08:08
like on the picture, its 2 pics

i tried this thing but it do not work
loop:
lcdout $fe , $c0 , "Waiting.." , DEC3 try1 , "," , DEC3 try2
try1 = try1 + 1 : temp = 0 : tempf = 0
serin portB.2 , t2400 , [ temp1 , temp2 , temp3 , temp4 ]
if temp1 > temp2 then
Portb.4 =1 ------------putting a led here, maybe lcdout is confusing with serin
pause 500
portb.4=0
else
Portb.3 =1 -----------putting a led here
pause 500
portb.3=0
endif

goto loop
End

lerameur
- 24th December 2006, 08:13
Ok I am really going now to sleep, see ya later

skimask
- 24th December 2006, 08:13
like on the picture, its 2 pics

i tried this thing but it do not work
loop:
lcdout $fe , $c0 , "Waiting.." , DEC3 try1 , "," , DEC3 try2
try1 = try1 + 1 : temp = 0 : tempf = 0
serin portB.2 , t2400 , [ temp1 , temp2 , temp3 , temp4 ]
if temp1 > temp2 then
Portb.4 =1 ------------putting a led here, maybe lcdout is confusing with serin
pause 500
portb.4=0
else
Portb.3 =1 -----------putting a led here
pause 500
portb.3=0
endif

goto loop
End



I meant are you putting the transmit code into the transmit PIC and the receive code into the receive PIC, not the whole thing into both PICs...

lerameur
- 24th December 2006, 08:15
I meant are you putting the transmit code into the transmit PIC and the receive code into the receive PIC, not the whole thing into both PICs...


'TRANSMIT PIC = one pic

'RECEIVE PIC = another pic
dont worry, only the part that belongs there :)

skimask
- 24th December 2006, 08:23
I meant are you putting the transmit code into the transmit PIC and the receive code into the receive PIC, not the whole thing into both PICs...


'TRANSMIT PIC = one pic

'RECEIVE PIC = another pic
dont worry, only the part that belongs there :)

Ok, just checking because in that one picture it looked like both PICs had the same writing on them.

Now try this code:


'RECEIVE PIC

INCLUDE "modedefs.bas"
DEFINE OSC 20 'use external 20mhz crystal
CMCON = 7 : ANSEL = 0 : ADCON1 = 7
DEFINE LCD_DREG PORTA ' Set LCD Data port
DEFINE LCD_DBIT 0 ' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
DEFINE LCD_EREG PORTB ' Set LCD Enable port
DEFINE LCD_EBIT 0 ' Set LCD Enable bit
DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
DEFINE LCD_LINES 2 ' Set number of lines on LCD
DEFINE LCD_COMMANDUS 2500
DEFINE LCD_DATAUS 250

'try1 = count of times waiting for data, try2 = count of bytes received
try1 var byte : try2 var byte : temp var word : tempf var word
temp1 var byte : temp2 var byte : temp3 var byte : temp4 var byte
input portb.2 : pause 2500
try1 = 0 : try2 = 0

loop:
lcdout $fe , $c0 , "Waiting.." , DEC3 try1 , "," , DEC3 try2
try1 = try1 + 1 : temp = 0 : tempf = 0
serin portB.2 , t2400 , [ temp1 , temp2 , temp3 , temp4 ]
temp.highbyte = temp1 : temp.lowbyte = temp2 : tempf.highbyte = temp3 : tempf.lowbyte = temp4
if temp + tempf > 0 then try2 = try2 + 1 'if temp+tempf are not 0 then data received
lcdout $fe , $c0 , "Received." , DEC3 try1 , "," , DEC3 try2 : pause 100
lcdout $fe , $c0 , "Display.." , DEC3 try1 , "," , DEC3 try2 : pause 100
lcdout $fe , $80 , "Tc=" , DEC3 temp , "C,Tf=" , DEC3 tempf , "FR" : pause 100
lcdout $fe , $c0 , "Shown...." , DEC3 try1 , "," , DEC3 try2 : pause 100
goto loop
End











'TRANSMIT PIC

INCLUDE "modedefs.bas"
DEFINE OSC 20 'use external 20mhz crystal
CMCON = 7 : ANSEL = 0 : ADCON1 = 7
DEFINE LCD_DREG PORTA ' Set LCD Data port
DEFINE LCD_DBIT 0 ' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
DEFINE LCD_EREG PORTB ' Set LCD Enable port
DEFINE LCD_EBIT 0 ' Set LCD Enable bit
DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
DEFINE LCD_LINES 2 ' Set number of lines on LCD
DEFINE LCD_COMMANDUS 2500
DEFINE LCD_DATAUS 250
DEFINE CHAR_PACING 16667

try1 var byte : try2 var byte : output portb.2 : input portb.3
dq var portb.4 : temp var word : tempf var word
temp1 var byte : temp2 var byte : temp3 var byte : temp4 var byte
pause 2500
try1 = 0 : try2 = 0

loop:
try1 = try1 + 1
lcdout $fe , $c0 , "Getting.." , DEC3 try1 , "," , DEC3 try2
owout DQ , 1 , [ $cc ] : owout DQ , 0 , [ $44 ] : Pause 500
owout DQ , 1 , [ $cc ] : owout DQ , 0 , [ $be ]
owin DQ , 0 , [ temp.LOWBYTE , temp.HIGHBYTE , skip 6 ]
tempf = temp * 9 : tempf = tempf / 5 : tempf = tempf + 32

tempf = 444 'hardcode transmitter to have 444 in tempf space
temp = 888 'hardcode transmitter to have 888 in temp space
lcdout $fe , $c0 , "Display.." , DEC3 try1 , "," , DEC3 try2
lcdout $fe , $80 , "Tc=" , DEC3 temp , "C,Tf=" , DEC3 tempf , "FT"
lcdout $fe , $c0 , "Sending.." , DEC3 try1 , "," , DEC3 try2
temp1 = temp.highbyte : temp2 = temp.lowbyte
serout portb.2 , t2400 , [ temp1 , temp2 ]
temp3 = tempf.highbyte : temp4 = tempf.lowbyte
serout portb.2 , t2400 , [ temp3 , temp4 ]
try2 = try2 + 4 : lcdout $fe , $c0 , "Sent....." , DEC3 try1 , "," , DEC3 try2
goto loop



And post a fresh picture if you can

lerameur
- 24th December 2006, 13:22
ok , I'm back, still no changes,
picture up
The two leds there are from a previous program which instead of using lcdout, I was trying to make led blink.
but the picture was takien while your last program was working

lerameur
- 24th December 2006, 13:41
i tried this program for the reciver. The led blinks, If I added the serin , led would sit on high. There is definately a problem with serin command, It does not work with lcdout or simple led blinking

'RECEIVE PIC

INCLUDE "modedefs.bas"
DEFINE OSC 20 'use external 20mhz crystal
CMCON = 7 : ANSEL = 0 : ADCON1 = 7
DEFINE LCD_DREG PORTA ' Set LCD Data port
DEFINE LCD_DBIT 0 ' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
DEFINE LCD_EREG PORTB ' Set LCD Enable port
DEFINE LCD_EBIT 0 ' Set LCD Enable bit
DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
DEFINE LCD_LINES 2 ' Set number of lines on LCD
DEFINE LCD_COMMANDUS 2500
DEFINE LCD_DATAUS 250

'try1 = count of times waiting for data, try2 = count of bytes received
try1 var byte : try2 var byte : temp var word : tempf var word
temp1 var byte : temp2 var byte : temp3 var byte : temp4 var byte
input portb.2 : pause 2500
try1 = 0 : try2 = 0
trisb=%00000000
loop:
lcdout $fe , $c0 , "Waiting.." , DEC3 try1 , "," , DEC3 try2
try1 = try1 + 1 : temp = 0 : tempf = 0
'serin portB.2 , t2400 , [ temp1 , temp2 , temp3 , temp4 ]
Portb.4 =1 : pause 500 : portb.4=0
Portb.3 =1 : pause 500 : portb.3=0
goto loop
End


I also wanted to see if the chip was able to see the data coming in, so i tried this loop, and nothing is happening to the led:

loop:
serin portB.2 , t2400 , [ temp1 , temp2 , temp3 , temp4 ]
if temp1 > 0 then
Portb.4 =1 : pause 500 : portb.4=0
Portb.3 =1 : pause 500 : portb.3=0
endif

goto loop
End

lerameur
- 24th December 2006, 14:41
Ok now I used your pogram and changed the serin line :

serin portB.2 , t2400 , temp1 -----works

It takes in the value,IT is NOW working. BUT For some odd reason it do not take multiple input..

serin portB.2 , t2400 , [ temp1 , temp2 , temp3 , temp4 ] ------------- do not work

Archangel
- 25th December 2006, 00:43
Ok now I used your pogram and changed the serin line :

serin portB.2 , t2400 , temp1 -----works

It takes in the value,IT is NOW working. BUT For some odd reason it do not take multiple input..

serin portB.2 , t2400 , [ temp1 , temp2 , temp3 , temp4 ] ------------- do not work
Hi leramuer.
I think you need to store and retrieve those values in an array. I am not experienced enough to have confidence with this statement, but methinks it is so.
Anyone, ring in here with an opinion!
JS
edit:
try this
Temp var byte[4]
Temp[0] = n ' your first temp value
Temp[1] = n1 ' your second value
Temp[2] = n2 ' your third value
Temp[3] = n3 ' your fourth value
serout portB.2 , t2400,[# temp[0],# temp[1], # Temp[2], # Temp[3]]
it displays on my backpack display.
JS

lerameur
- 25th December 2006, 13:53
Merry Christmas to all

I just tried that , the information is not sending. Maybe I got the code wrong, but it till skipping over the lcdout

k

skimask
- 26th December 2006, 05:00
Ok now I used your pogram and changed the serin line :

serin portB.2 , t2400 , temp1 -----works

It takes in the value,IT is NOW working. BUT For some odd reason it do not take multiple input..

serin portB.2 , t2400 , [ temp1 , temp2 , temp3 , temp4 ] ------------- do not work



Ok, I'm back. In the last program I posted, I had the values hardcoded in the transmitter side, so since they displayed correctly, now try a couple of dummy values hardcoded in the receiver side. Try out these programs and let me know what happens....

Things I changed since the last programs posted a couple of days ago:

Removed the hardcoded '444' and '888' on the transmitter side

Added a hardcoded '444' and '888' on the receiver side.

On both the transmit and receive side, I split the serout and serin into 4 seperate lines, each sending (or receiving) one byte. I don't know if this will fix the problem or not.

I also added a couple of lines in there to 'sync' up the transmit and receive sides in the case that the receive side starts receiving in the middle of a transmission (which could happen). Very simple setup - 6 bytes are sent, 1st byte - $aa , 2nd-3rd-tempC, 4th-5th-tempF, 6th byte-$55. 1st and 6th byte should add up to $FF. If it doesn't, it was received in the wrong order is values are thrown out. (actually, the 2 numbers from the transmit side could be any pair, as long as they add up to $ff, the receiver will take it, which could mess up the values at the receiver if the right temperature combination comes along, but we'll stay with this for now)

If the receive side shows '444' and '888', remove the lines and comments, and try it again. It just might work...

Of course then again, over the past couple of days, you might've gotten it fixed, which would be a sweet deal overall...

Added a line to idle the transmit line high between characters. This might fix the whole problem...?(see next post)

'RECEIVE PIC

INCLUDE "modedefs.bas"
DEFINE OSC 20 'use external 20mhz crystal
CMCON = 7 : ANSEL = 0 : ADCON1 = 7
DEFINE LCD_DREG PORTA ' Set LCD Data port
DEFINE LCD_DBIT 0 ' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
DEFINE LCD_EREG PORTB ' Set LCD Enable port
DEFINE LCD_EBIT 0 ' Set LCD Enable bit
DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
DEFINE LCD_LINES 2 ' Set number of lines on LCD
DEFINE LCD_COMMANDUS 2500
DEFINE LCD_DATAUS 250

'try1 = count of times waiting for data, try2 = count of bytes received
try1 var byte : try2 var byte : temp var word : tempf var word
temp1 var byte : temp2 var byte : temp3 var byte : temp4 var byte
leader var byte : trailer var byte
input portb.2 : pause 2500
try1 = 0 : try2 = 0

loop:
lcdout $fe , $c0 , "Waiting.." , DEC3 try1 , "," , DEC3 try2 : try1 = try1 + 1
temp = 0 : tempf = 0 : leader = 0 : trailer = 0 'clear out old values
temp1 = 0 : temp2 = 0 : temp3 = 0 : temp4 = 0 'clear out old values
serin portb.2 , t2400 , [ leader ] 'get leader byte
serin portb.2 , t2400 , [ temp1 ]:serin portb.2 , t2400 , [ temp2 ] 'get data
serin portb.2 , t2400 , [ temp3 ]:serin portb.2 , t2400 , [ temp4 ] 'get data
serin portb.2 , t2400 , [ trailer ] 'get trailer byte

'remove the line below if 444 and 888 show up on the LCD
temp1 = 1 : temp2 = 188 : temp3 = 3 : temp4 = 120
'remove the line above if 444 and 888 show up on the LCD

if ( leader + trailer ) <> $ff then 'if leader + trailer doesn't add up right...
lcdout $fe , $c0 , "No Sync..", DEC3 try1 , "," , DEC3 try2
pause 200 : goto loop 'try again
endif

temp.highbyte = temp1 : temp.lowbyte = temp2 'put the received values
tempf.highbyte = temp3 : tempf.lowbyte = temp4 'where they need to be
if temp + tempf > 0 then try2 = try2 + 1 'if temp+tempf are not 0 then data received
lcdout $fe , $c0 , "Received." , DEC3 try1 , "," , DEC3 try2 : pause 100
lcdout $fe , $c0 , "Display.." , DEC3 try1 , "," , DEC3 try2 : pause 100
lcdout $fe , $80 , "Tc=" , DEC3 temp , "C,Tf=" , DEC3 tempf , "FR" : pause 100
lcdout $fe , $c0 , "Shown...." , DEC3 try1 , "," , DEC3 try2 : pause 100
goto loop
End











'TRANSMIT PIC

INCLUDE "modedefs.bas"
DEFINE OSC 20 'use external 20mhz crystal
CMCON = 7 : ANSEL = 0 : ADCON1 = 7
DEFINE LCD_DREG PORTA ' Set LCD Data port
DEFINE LCD_DBIT 0 ' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
DEFINE LCD_EREG PORTB ' Set LCD Enable port
DEFINE LCD_EBIT 0 ' Set LCD Enable bit
DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
DEFINE LCD_LINES 2 ' Set number of lines on LCD
DEFINE LCD_COMMANDUS 2500
DEFINE LCD_DATAUS 250
DEFINE CHAR_PACING 33333

try1 var byte : try2 var byte : output portb.2 : high portb.2 : input portb.3
dq var portb.4 : temp var word : tempf var word
temp1 var byte : temp2 var byte : temp3 var byte : temp4 var byte
pause 2500
try1 = 0 : try2 = 0

loop:
lcdout $fe , $c0 , "Getting.." , DEC3 try1 , "," , DEC3 try2 : try1 = try1 + 1
owout DQ , 1 , [ $cc ] : owout DQ , 0 , [ $44 ] : Pause 500
owout DQ , 1 , [ $cc ] : owout DQ , 0 , [ $be ]
owin DQ , 0 , [ temp.LOWBYTE , temp.HIGHBYTE , skip 6 ]
tempf = temp * 9 : tempf = tempf / 5 : tempf = tempf + 32
lcdout $fe , $c0 , "Display.." , DEC3 try1 , "," , DEC3 try2
lcdout $fe , $80 , "Tc=" , DEC3 temp , "C,Tf=" , DEC3 tempf , "FT"
lcdout $fe , $c0 , "Sending.." , DEC3 try1 , "," , DEC3 try2
high portb.2 : serout portb.2, t2400 , [ $aa ] 'send a leader byte
temp1 = temp.highbyte : temp2 = temp.lowbyte
high portb.2 : serout portb.2 , t2400 , [ temp1 ]
high portb.2 : serout portb.2 , t2400 , [ temp2 ] 'send data
temp3 = tempf.highbyte : temp4 = tempf.lowbyte
high portb.2 : serout portb.2 , t2400 , [ temp3 ]
high portb.2 : serout portb.2 , t2400 , [ temp4 ] 'send data
high portb.2 : serout portb.2 , t2400 , [ $ff ] 'send a trailer byte
high portb.2 : try2 = try2 + 4 : lcdout $fe , $c0 , "Sent....." , DEC3 try1 , "," , DEC3 try2
goto loop

skimask
- 26th December 2006, 05:09
Something else I just found...
http://www.picbasic.co.uk/forum/showthread.php?t=1944&highlight=idle+state

You might have to add a bit of code to manually toggle the pin before/after transmitting...not sure... I'll look into it more tomorrow. This may have been the problem I was having before (long time ago) when I switched over to using the actual PIC hardware serial modules.

lerameur
- 26th December 2006, 17:56
HI, NO I have not found the problem . I was about to order some pic16f648a, you told it worked with these chips.

I tried your program , the No sync appears at every increment,
so guess there is a problem with the trailer or leader bit.

k

skimask
- 26th December 2006, 18:49
HI, NO I have not found the problem . I was about to order some pic16f648a, you told it worked with these chips.

I tried your program , the No sync appears at every increment,
so guess there is a problem with the trailer or leader bit.

k

I wouldn't order any '648's or '628's, the 'F88 should be just fine.

What does the display read? Does it show the hardcoded 444 and 888? Did you try removing that? Also, get rid of the pauses in the receiver code, or at least drop them down a bit, cut them in half or so.

JUST SAW THIS: In the transmit code, the trailer byte should be a $55, not $ff. That'll probably fix it now. The fact that you said it shows 'No Sync' at 'EVERY INCREMENT' is the key thing, it shows that the loop is going thru the SERIN commands now.

lerameur
- 26th December 2006, 20:39
The display never showed the 444 or 888.
I posted a new picture.
I tried removing the pauses, putting them at half the pause you had them, also changed the trailer byte to $55 ..same effect.

skimask
- 26th December 2006, 21:55
The display never showed the 444 or 888.
I posted a new picture.
I tried removing the pauses, putting them at half the pause you had them, also changed the trailer byte to $55 ..same effect.

Ok, let's try the silly simple and build back up... I guess we gotta figure out where this whole thing is failing at. If this don't work......I dunno....


'RECEIVE PIC

INCLUDE "modedefs.bas"
DEFINE OSC 20 'use external 20mhz crystal
CMCON = 7 : ANSEL = 0 : ADCON1 = 7
DEFINE LCD_DREG PORTA ' Set LCD Data port
DEFINE LCD_DBIT 0 ' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
DEFINE LCD_EREG PORTB ' Set LCD Enable port
DEFINE LCD_EBIT 0 ' Set LCD Enable bit
DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
DEFINE LCD_LINES 2 ' Set number of lines on LCD
DEFINE LCD_COMMANDUS 2500
DEFINE LCD_DATAUS 250

temp var word : temp1 var word : input portb.2

loop:
serin portb.2 , t2400 , [ temp ]
lcdout $fe , $80 , DEC3 temp
temp1 = temp1 + 1
lcdout $fe , $c0 , DEC5 temp1
goto loop
End











'TRANSMIT PIC

INCLUDE "modedefs.bas"
DEFINE OSC 20 'use external 20mhz crystal
CMCON = 7 : ANSEL = 0 : ADCON1 = 7
DEFINE LCD_DREG PORTA ' Set LCD Data port
DEFINE LCD_DBIT 0 ' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
DEFINE LCD_EREG PORTB ' Set LCD Enable port
DEFINE LCD_EBIT 0 ' Set LCD Enable bit
DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
DEFINE LCD_LINES 2 ' Set number of lines on LCD
DEFINE LCD_COMMANDUS 2500
DEFINE LCD_DATAUS 250
DEFINE CHAR_PACING 33333

temp var byte : temp1 var word : output portb.2

loop:
temp = temp + 1
serout portb.2 , t2400 , [ temp ]
lcdout $fe , $80 , DEC3 temp
temp1 = temp1 + 1
lcdout $fe , $c0 , DEC5 temp1
goto loop

lerameur
- 26th December 2006, 22:04
ok, the sending pic increment both on line 1 and two
the receiving end displays a constant 535 on the 1st line and 49102 on the second line


problem still persist

lerameur
- 26th December 2006, 22:51
ok here it is :

THIS DO NOT WORK;
loop:
serin portb.2 , n2400 , [ temp]
lcdout $fe , $80 , DEC temp
pause 200
goto loop
End



THIS WORKS;;
loop:
serin portb.2 , n2400 , temp
lcdout $fe , $80 , DEC temp
pause 200
goto loop
End

AS soon as I put the square brackt , the display is messed up

skimask
- 27th December 2006, 03:50
ok here it is :

THIS DO NOT WORK;
loop:
serin portb.2 , n2400 , [ temp]
lcdout $fe , $80 , DEC temp
pause 200
goto loop
End



THIS WORKS;;
loop:
serin portb.2 , n2400 , temp
lcdout $fe , $80 , DEC temp
pause 200
goto loop
End

AS soon as I put the square brackt , the display is messed up




You are abso-freekin-lutely right!!!!!!!!!! My fonts have been messed up this whole time on my pdf viewer!!!!!!!! In the PBP manual, it shows what looks like brackets around the 'item', when there really isn't any brackets!!!!!!! AND...when I looked at the project I was saying that worked just fine, it doesn't have brackets either!!!!!!! Freekin''''amazing....I should've caught this days ago!!!!!

Let's go back, but not as far...
Working on another post/program that should work 100% all the way this time.

(damn, I could seriously kick my own ass right now)....
I'll have it posted here in a few minutes...

skimask
- 27th December 2006, 04:06
SERIN doesn't use brackets!!!!!!
SEROUT DOES use brackets!!!!!!
(My installation of Acrobat reader's fonts got screwed up at my end sometime in the past, that's what been messing it up. With the brackets in place, serin has been waiting for qualifiers this whole time, not actual data!)

'RECEIVE PIC

INCLUDE "modedefs.bas"
DEFINE OSC 20 'use external 20mhz crystal
CMCON = 7 : ANSEL = 0 : ADCON1 = 7
DEFINE LCD_DREG PORTA ' Set LCD Data port
DEFINE LCD_DBIT 0 ' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
DEFINE LCD_EREG PORTB ' Set LCD Enable port
DEFINE LCD_EBIT 0 ' Set LCD Enable bit
DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
DEFINE LCD_LINES 2 ' Set number of lines on LCD
DEFINE LCD_COMMANDUS 2500
DEFINE LCD_DATAUS 250

temp var word : tempf var word
leader var byte : trailer var byte : count var byte
temp1 var byte : temp2 var byte : temp3 var byte : temp4 var byte
input portb.2 : pause 1000

loop:
lcdout $fe , $c0 , "Waiting......" , DEC3 count
temp = 0 : tempf = 0
leader = 0 : trailer = 0 : count = 0
temp1 = 0 : temp2 = 0 : temp3 = 0 : temp4 = 0
serin portb.2 , t2400 , leader 'get leader byte
serin portb.2 , t2400 , temp1
serin portb.2 , t2400 , temp2
serin portb.2 , t2400 , temp3
serin portb.2 , t2400 , temp4
serin portb.2 , t2400 , count
serin portb.2 , t2400 , trailer

if ( leader + trailer ) <> $ff then 'if leader + trailer doesn't add up right...
lcdout $fe , $c0 , "Out of Sync..", DEC3 count : goto loop
endif

temp.highbyte = temp1
temp.lowbyte = temp2
tempf.highbyte = temp3
tempf.lowbyte = temp4
lcdout $fe , $c0 , "Received....." , DEC3 count
lcdout $fe , $80 , "Tc=" , DEC3 temp , "C,Tf=" , DEC3 tempf , "F."
goto loop
End











'TRANSMIT PIC

INCLUDE "modedefs.bas"
DEFINE OSC 20 'use external 20mhz crystal
CMCON = 7 : ANSEL = 0 : ADCON1 = 7
DEFINE LCD_DREG PORTA ' Set LCD Data port
DEFINE LCD_DBIT 0 ' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
DEFINE LCD_EREG PORTB ' Set LCD Enable port
DEFINE LCD_EBIT 0 ' Set LCD Enable bit
DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
DEFINE LCD_LINES 2 ' Set number of lines on LCD
DEFINE LCD_COMMANDUS 2500
DEFINE LCD_DATAUS 250
DEFINE CHAR_PACING 33333

count var byte
output portb.2 : high portb.2 : input portb.3 : dq var portb.4
temp var word : tempf var word
temp1 var byte : temp2 var byte : temp3 var byte : temp4 var byte
pause 1500

loop:
lcdout $fe , $c0 , "Getting......" , DEC3 count
owout DQ , 1 , [ $cc ]
owout DQ , 0 , [ $44 ]
Pause 500
owout DQ , 1 , [ $cc ]
owout DQ , 0 , [ $be ]
owin DQ , 0 , [ temp.LOWBYTE , temp.HIGHBYTE , skip 6 ]
tempf = temp * 9 : tempf = tempf / 5 : tempf = tempf + 32
lcdout $fe , $c0 , "Display......" , DEC3 count
lcdout $fe , $80 , "Tc=" , DEC3 temp , "C,Tf=" , DEC3 tempf , "F."
lcdout $fe , $c0 , "Sending......" , DEC3 count
serout portb.2, t2400 , [ $aa ] 'send a leader byte
temp1 = temp.highbyte : temp2 = temp.lowbyte
serout portb.2 , t2400 , [ temp1 ]
serout portb.2 , t2400 , [ temp2 ] 'send data
temp3 = tempf.highbyte : temp4 = tempf.lowbyte
serout portb.2 , t2400 , [ temp3 ]
serout portb.2 , t2400 , [ temp4 ] 'send data
serout portb.2 , t2400 , [ count ] 'send count
serout portb.2 , t2400 , [ $ff ] 'send a trailer byte
lcdout $fe , $c0 , "Sent....." , DEC3 try1 , "," , DEC3 try2
count = count + 1
goto loop


And that should do it!!!

lerameur
- 27th December 2006, 11:11
in the transmit code you have this line:
lcdout $fe , $c0 , "Sent....." , DEC3 try1 , "," , DEC3 try2

what is try1 and try2 from ???

I just tried it,

even with that line out, it still dont show me the temperature on the receiving end

I think the word count is a reserved word.
changed to counter

The receiver is just showing waiting... and the counter

skimask
- 27th December 2006, 13:35
in the transmit code you have this line:
lcdout $fe , $c0 , "Sent....." , DEC3 try1 , "," , DEC3 try2

what is try1 and try2 from ???

I just tried it,

even with that line out, it still dont show me the temperature on the receiving end

I think the word count is a reserved word.
changed to counter

The receiver is just showing waiting... and the counter

Yep, forgot to take out the try1 and try2.
And I thought I had the problem fixed all the way around...
Got a new picture up?

skimask
- 27th December 2006, 13:49
Going to try something different. Since you are reading the temperature at the transmit end and it's in C, there's practically no chance it'll go above 255 C, so how about simplifying the problem greatly, and just sending one byte across the serial link. Do the C -> F conversion at the receiver end. One byte sent, no header/leader/trailer/counter bytes needed, no nothing....
I'll get the new program up in a minute or two...

skimask
- 27th December 2006, 13:53
'RECEIVE PIC

'same includes and defines as the other versions

temp var word : tempf var word : count var byte
input portb.2 : pause 1000

loop:
count = count + 1 : lcdout $fe , $c0 , "Waiting......" , DEC3 count
serin portb.2 , t2400 , temp
tempf = temp * 9 : tempf = tempf / 5 : tempf = tempf + 32
lcdout $fe , $80 , "Tc=" , DEC3 temp , "C,Tf=" , DEC3 tempf , "F."
lcdout $fe , $c0 , "Received....." , DEC3 count
goto loop
End






'TRANSMIT PIC

'same includes and defines as the other versions

count var byte : temp var word : output portb.2 : high portb.2
input portb.3 : dq var portb.4 : pause 1000

loop:
lcdout $fe , $c0 , "Getting......" , DEC3 count
owout DQ , 1 , [ $cc ] : owout DQ , 0 , [ $44 ] : Pause 500
owout DQ , 1 , [ $cc ] : owout DQ , 0 , [ $be ]
owin DQ , 0 , [ temp.LOWBYTE , temp.HIGHBYTE , skip 6 ]
lcdout $fe , $80 , "Tc=" , DEC3 temp
lcdout $fe , $c0 , "Sending......" , DEC3 count
serout portb.2 , t2400 , [ temp.lowbyte ]
count = count + 1
goto loop

If it doesn't work, try putting a 'high portb.2' in front of the serout statement.

lerameur
- 27th December 2006, 14:26
that works :)
Then again it is only one 8 bit sending/receiving, I need four in the serout, but it is a good step.

skimask
- 27th December 2006, 14:33
that works :)
Then again it is only one 8 bit sending/receiving, I need four in the serout, but it is a good step.

So it does work, completely, as intended? Temperature is sent over and all that?

Why do you need 4 bytes to go over the link? You can keep doing the math at the receiving end and like I said, temp probably wouldn't ever get above 255C?


Oh...I forgot about the wireless link that was supposed to be there in the first place....
Re-post what you have for code....

lerameur
- 27th December 2006, 14:42
the code I have is the code you have on top a couple of posts ago, I am trying to add multiple items to it though

'receiving:
INCLUDE "modedefs.bas"
DEFINE OSC 20 'use external 20mhz crystal
CMCON = 7 : ANSEL = 0 : ADCON1 = 7
DEFINE LCD_DREG PORTA ' Set LCD Data port
DEFINE LCD_DBIT 0 ' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
DEFINE LCD_EREG PORTB ' Set LCD Enable port
DEFINE LCD_EBIT 0 ' Set LCD Enable bit
DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
DEFINE LCD_LINES 2 ' Set number of lines on LCD
DEFINE LCD_COMMANDUS 2500
DEFINE LCD_DATAUS 250


temp var word : temp1 var word : tempf var word : counter var byte
input portb.2 : pause 1000

loop:
counter = counter + 1 : lcdout $fe , $c0 , "Waiting......" , DEC3 counter
serin portb.2 , t2400 , temp
serin portb.2 , t2400 , temp1
tempf = temp * 9 : tempf = tempf / 5 : tempf = tempf + 32
lcdout $fe , $80 , "Tc=" , DEC3 temp , "C,Tf=" , DEC3 temp1 , "F."
lcdout $fe , $c0 , "Received....." , DEC3 counter
goto loop
End

'TRANSMIT PIC

INCLUDE "modedefs.bas"
DEFINE OSC 20 'use external 20mhz crystal
CMCON = 7 : ANSEL = 0 : ADCON1 = 7
DEFINE LCD_DREG PORTA ' Set LCD Data port
DEFINE LCD_DBIT 0 ' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
DEFINE LCD_EREG PORTB ' Set LCD Enable port
DEFINE LCD_EBIT 0 ' Set LCD Enable bit
DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
DEFINE LCD_LINES 2 ' Set number of lines on LCD
DEFINE LCD_COMMANDUS 2500
DEFINE LCD_DATAUS 250
DEFINE CHAR_PACING 33333

counter var byte : temp var word : output portb.2 : high portb.2
input portb.3 : dq var portb.4 : pause 1000

loop:
lcdout $fe , $c0 , "Getting......" , DEC3 counter
owout DQ , 1 , [ $cc ] : owout DQ , 0 , [ $44 ] : Pause 500
owout DQ , 1 , [ $cc ] : owout DQ , 0 , [ $be ]
owin DQ , 0 , [ temp.LOWBYTE , temp.HIGHBYTE , skip 6 ]
lcdout $fe , $80 , "Tc=" , DEC3 temp
lcdout $fe , $c0 , "Sending......" , DEC3 counter
serout portb.2 , t2400 , [ temp.lowbyte, temp.highbyte ]
counter = counter + 1
goto loop

skimask
- 27th December 2006, 14:46
[QUOTE=lerameur;30072]the code I have is the code you have on top a couple of posts ago, I am trying to add multiple items to it though

I'm modifying it a bit (adding the manchester encoding stuff) so you can hook up the wireless modules and try it with one byte. Should be easier to add more data after the wireless it working with byte, then to make sure multiple bytes work without the wireless....that's my thought anyways...

lerameur
- 27th December 2006, 15:15
you can look at the first post I have manchester encoding there and it works

skimask
- 27th December 2006, 15:22
you can look at the first post I have manchester encoding there and it works

It probably does work, but I threw this together....unless I made some silly mistakes, this should work with (and without) the wireless modules, in fact it should work just fine with the wire still attached. Maybe it wouldn't be a bad idea to test it out that way also...



'RECEIVE PIC

'same includes and defines as the other versions

temp var word : tempf var word : counter var byte
templo var byte : temphi var byte : input portb.2
converts var byte[15] : convtemp var byte
converts[0]=$55 : converts[1]=$56 : converts[2]=$59 : converts[3]=$5a
converts[4]=$65 : converts[5]=$66 : converts[6]=$69 : converts[7]=$6a
converts[8]=$95 : converts[9]=$96 : converts[10]=$99 : converts[11]=$9a
converts[12]=$a5 : converts[13]=$a6 : converts[14]=$a9 : converts[15]=$aa

pause 1000

loop:
counter = counter + 1 : lcdout $fe , $c0 , "Waiting......" , DEC3 counter

waitfor55:
serin portb.2 , t2400 , temp : if temp <> $55 then goto waitfor55

waitforaa:
serin portb.2 , t2400 , temp : if temp <> $aa then goto waitforaa

serin portb.2 , t2400 , templo : serin portb.2 , t2400 , temphi

for convtemp = 0 to 15
if templo = converts[temp] then temp1 = convtemp
if temphi = converts[temp] then temp2 = convtemp
next convtemp

temp = ( temp2 * 16 ) + temp1
tempf = temp * 9 : tempf = tempf / 5 : tempf = tempf + 32
lcdout $fe , $80 , "Tc=" , DEC3 temp , "C,Tf=" , DEC3 tempf , "F."
lcdout $fe , $c0 , "Received....." , DEC3 count
goto loop


'TRANSMIT PIC

'same includes and defines as the other versions
'can probably reduce the char_pacing value quite a bit now that it's working

counter var byte : temp var word : output portb.2 : high portb.2
input portb.3 : dq var portb.4 : templo var byte : temphi var byte
converts var byte[15] : convtemp var byte
converts[0]=$55 : converts[1]=$56 : converts[2]=$59 : converts[3]=$5a
converts[4]=$65 : converts[5]=$66 : converts[6]=$69 : converts[7]=$6a
converts[8]=$95 : converts[9]=$96 : converts[10]=$99 : converts[11]=$9a
converts[12]=$a5 : converts[13]=$a6 : converts[14]=$a9 : converts[15]=$aa
pause 1000

loop:
lcdout $fe , $c0 , "Getting......" , DEC3 count
owout DQ , 1 , [ $cc ] : owout DQ , 0 , [ $44 ] : Pause 500
owout DQ , 1 , [ $cc ] : owout DQ , 0 , [ $be ]
owin DQ , 0 , [ temp.LOWBYTE , temp.HIGHBYTE , skip 6 ]
lcdout $fe , $80 , "Tc=" , DEC3 temp
lcdout $fe , $c0 , "Sending......" , DEC3 count

templo = temp.lowbyte & $f : temphi = temp.lowbyte >> 4
templo = converts[templo] : temphi = converts[temphi]

serout portb.2 , t2400 , [ $55 , $55 , $55 , $55 , $aa ]
serout portb.2 , t2400 , [ templo ] : serout portb.2 , t2400 , [ temphi ]

counter = counter + 1
goto loop

lerameur
- 27th December 2006, 15:43
what are temp1 and temp2 used for in the receiving code ?
because it is used at the end of the program , but the value is not initialized to anything, , no input,

skimask
- 27th December 2006, 16:01
what are temp1 and temp2 used for in the receiving code ?

Whoops....should be hi and lo instead of 1 and 2

temp = ( temphi * 16 ) + templo

lerameur
- 27th December 2006, 16:17
This is one way of encoding I have not seen before,
you did not like the loop I was doing in the first post ?
It displays 578C and 872F on the receiver side,
I will look at the decodin technique, because I do not know if it is encoding error or calculation error.

skimask
- 27th December 2006, 16:19
This is one way of encoding I have not seen before,
you did not like the loop I was doing in the first post ?
It displays 578C and 872F on the receiver side,
I will look at the decodin technique, because I do not know if it is encoding error or calculation error.

Is this with the wireless or with the wires like before? Could be either type of error.... I'll look at it a bit more....

lerameur
- 27th December 2006, 16:22
still using the wire.

WHY do you do this :

templo = temp.lowbyte & $f

skimask
- 27th December 2006, 16:37
still using the wire.

WHY do you do this :

templo = temp.lowbyte & $f

That masks off the upper 4 bits ( logical AND, temp.lowbyte AND %00001111 ) and use only the lower 4 bits to convert the nibble value to a byte-wide manchester encoded value....(and with the temphi variable, I shift the upper 4 into the lower 4 and do the same thing with it to get manchester encoded values)...
And do the same thing in reverse at the other end. Your method that you had when you started might work just fine.

skimask
- 27th December 2006, 16:40
Ya, I screwed it up again. This gets a bit difficult when you don't run the program immediately to see your errors (which is what you're doing at that end!).

Another version of the program coming in a couple of minutes (or less)...

skimask
- 27th December 2006, 16:56
'RECEIVE PIC

'same includes and defines as the other versions

temp var word : tempf var word : counter var byte : templo var byte : temphi var byte : input portb.2 : converts var byte[15]
convtemp var byte : converts[0] = $55 : converts[1] = $56 : converts[2] = $59 : converts[3] = $5a : converts[4] = $65
converts[5] = $66 : converts[6] = $69 : converts[7] = $6a : converts[8] = $95 : converts[9] = $96 : converts[10] = $99
converts[11] = $9a : converts[12] = $a5 : converts[13] = $a6 : converts[14] = $a9 : converts[15] = $aa
pause 1000

loop:
counter = counter + 1 : lcdout $fe , $c0 , "Waiting......" , DEC3 counter

waitfor55:
serin portb.2 , t2400 , temp : if temp <> $55 then goto waitfor55

waitforaa:
serin portb.2 , t2400 , temp : if temp <> $aa then goto waitforaa

serin portb.2 , t2400 , templo : serin portb.2 , t2400 , temphi

for convtemp = 0 to 15
if templo = converts[temp] then templo = convtemp
if temphi = converts[temp] then temphi = convtemp
next convtemp

temp = ( temphi << 4 ) + templo : tempf = temp * 9 : tempf = tempf / 5 : tempf = tempf + 32
lcdout $fe , $80 , "Tc=" , DEC3 temp , "C,Tf=" , DEC3 tempf , "F." : lcdout $fe , $c0 , "Received....." , DEC3 count
goto loop





'TRANSMIT PIC

'same includes and defines as the other versions, EXCEPT --------------
----------------------------------------------------------------------------------------
'change the char_pacing value to 500. If it's a large value (above 1000 or so), the receiver loses it's "training"
----------------------------------------------------------------------------------------

counter var byte : temp var word : output portb.2 : high portb.2 : input portb.3 : dq var portb.4 : templo var byte
temphi var byte :converts var byte[15] : converts[0]=$55 : converts[1]=$56 : converts[2]=$59 : converts[3]=$5a
converts[4]=$65 : converts[5]=$66 : converts[6]=$69 : converts[7]=$6a : converts[8]=$95 : converts[9]=$96 : converts[10]=$99
converts[11]=$9a : converts[12]=$a5 : converts[13]=$a6 : converts[14]=$a9 : converts[15]=$aa : pause 1000

loop:
lcdout $fe , $c0 , "Getting......" , DEC3 count : owout DQ , 1 , [ $cc ] : owout DQ , 0 , [ $44 ] : Pause 500
owout DQ , 1 , [ $cc ] : owout DQ , 0 , [ $be ] : owin DQ , 0 , [ temp.LOWBYTE , temp.HIGHBYTE , skip 6 ]
lcdout $fe , $80 , "Tc=" , DEC3 temp : lcdout $fe , $c0 , "Sending......" , DEC3 count
templo = temp.lowbyte & $f : temphi = temp.lowbyte >> 4 : templo = converts[templo] : temphi = converts[temphi]
serout portb.2 , t2400 , [ $55 , $55 , $55 , $55 , $aa , templo , temphi ]
counter = counter + 1
goto loop

lerameur
- 27th December 2006, 17:09
still getting extremely high values at the receiving end:
578C 872F

skimask
- 27th December 2006, 17:10
still getting extremely high values at the receiving end:
578C 872F

Good numbers at the transmitter side?

lerameur
- 27th December 2006, 17:22
yes , the transmitter is good :)

skimask
- 27th December 2006, 17:27
yes , the transmitter is good :)

Well, what are the numbers at the TX and RX side?

lerameur
- 27th December 2006, 17:31
transmitter:
043

receiver:
578 C 892 F

plus the counters

skimask
- 27th December 2006, 17:39
transmitter:
043

receiver:
578 C 892 F

plus the counters



Try n2400 instead of t2400.

skimask
- 27th December 2006, 17:44
Try n2400 instead of t2400.

Skip that...I forgot we're still on the wired, not the wireless modules. But, worth I try I suppose.

lerameur
- 27th December 2006, 17:44
no changes,

ok i will try the wireless

skimask
- 27th December 2006, 17:45
no changes,

ok i will try the wireless

I meant changing the t2400 to n2400, not switching over to wireless yet. Still have to get the comm's working without the wireless.

skimask
- 27th December 2006, 17:53
I meant changing the t2400 to n2400, not switching over to wireless yet. Still have to get the comm's working without the wireless.

How about this... (getting annoying isn't it? :) )
I commented out the encoding/decoding parts. Just sending a split up raw value now....see what happens...


'RECEIVE PIC

'same includes and defines as the other versions

temp var word : tempf var word : counter var byte : templo var byte
temphi var byte : input portb.2 : converts var byte[15] : convtemp var byte
converts[0] = $55 : converts[1] = $56 : converts[2] = $59
converts[3] = $5a : converts[4] = $65 : converts[5] = $66
converts[6] = $69 : converts[7] = $6a : converts[8] = $95
converts[9] = $96 : converts[10] = $99 : converts[11] = $9a
converts[12] = $a5 : converts[13] = $a6 : converts[14] = $a9
converts[15] = $aa : pause 1000

loop:
counter = counter + 1 : lcdout $fe , $c0 , "Waiting......" , DEC3 counter

waitfor55:
serin portb.2 , n2400 , temp : if temp <> $55 then goto waitfor55

waitforaa:
serin portb.2 , n2400 , temp : if temp <> $aa then goto waitforaa

serin portb.2 , n2400 , templo : serin portb.2 , n2400 , temphi

'for convtemp = 0 to 15
'if templo = converts[temp] then templo = convtemp
'if temphi = converts[temp] then temphi = convtemp
'next convtemp

temp = ( temphi << 4 ) + templo : tempf = temp * 9 : tempf = tempf / 5
tempf = tempf + 32
lcdout $fe , $80 , "Tc=" , DEC3 temp , "C,Tf=" , DEC3 tempf , "F."
lcdout $fe , $c0 , "Received....." , DEC3 count
goto loop


'TRANSMIT PIC

'same includes and defines as the other versions
'--------------------------------------------------------------------------
'remove the char_pacing value, with it in there, the RX will lose it's "training"
'-------------------------------------------------------------------------

counter var byte : temp var word : output portb.2 : high portb.2
input portb.3 : dq var portb.4 : templo var byte : temphi var byte
converts var byte[15] : converts[0] = $55 : converts[1] = $56
converts[2] = $59 : converts[3] = $5a : converts[4] = $65
converts[5] = $66 : converts[6] = $69 : converts[7] = $6a
converts[8] = $95 : converts[9] = $96 : converts[10] = $99
converts[11] = $9a : converts[12] = $a5 : converts[13] = $a6
converts[14] = $a9 : converts[15] = $aa : pause 1000

loop:
lcdout $fe , $c0 , "Getting......" , DEC3 count : owout DQ , 1 , [ $cc ]
owout DQ , 0 , [ $44 ] : Pause 500 : owout DQ , 1 , [ $cc ]
owout DQ , 0 , [ $be ]
owin DQ , 0 , [ temp.LOWBYTE , temp.HIGHBYTE , skip 6 ]
lcdout $fe , $80 , "Tc=" , DEC3 temp
lcdout $fe , $c0 , "Sending......" , DEC3 count
templo = temp.lowbyte & $f : temphi = temp.lowbyte >> 4
'templo = converts[templo] : temphi = converts[temphi]
serout portb.2 , n2400 , [ $55 , $55 , $55 , $55 , $aa ]
serout portb.2 , n2400 , [ templo , temphi ]
counter = counter + 1
goto loop

lerameur
- 27th December 2006, 18:01
well same results with n2400 and t2400

skimask
- 27th December 2006, 18:05
well same results with n2400 and t2400

And you're using the program as listed in post #118?

Probably going to end up backing up again, so we can move forward again!

lerameur
- 27th December 2006, 18:15
ok eee, seems to be working now, am I awake.... :)
thank you thank you
i will try the wireless

what is this line for (was for , or intended to)
'templo = converts[templo] : temphi = converts[temphi]

skimask
- 27th December 2006, 18:20
ok eee, seems to be working now, am I awake.... :)
thank you thank you
i will try the wireless

what is this line for (was for , or intended to)
'templo = converts[templo] : temphi = converts[temphi]

Well, what program are you running right now? I changed some stuff and was about to post it...but if you say it's working correctly at both ends, then I'll go with that.... So, repost the program you're running now (if it works), so I can remember what the line above did.

lerameur
- 27th December 2006, 18:25
using post 118

it works wireless,
does it have to do with the encoding technique ?
but most often its showing good temp.

lerameur
- 27th December 2006, 18:28
could I add a 10v voltage regulator for the RF transmitter to boost up the signal ? I am using the rentron 433mhz chips tws

skimask
- 27th December 2006, 18:33
using post 118

it works wireless, I get a lot glitches meaning temperature showing weird numbers like 930 , 445, etc.. it stays at those odd numbers for 3-5 seconds sometimes,
does it have to do with the encoding technique ?
but most often its showing good temp.

Glitches - Probably has to do with the encoding technique because the data isn't encoded (I commented that part out in post #118), but the 'training' bytes are encoded.

Maybe try to add a few more $55 to the serout line in the transmit section. And make sure the char_pacing isn't in the define sections anymore.

skimask
- 27th December 2006, 18:35
could I add a 10v voltage regulator for the RF transmitter to boost up the signal ? I am using the rentron 433mhz chips tws

If you're running the module at 5v now, you're good for about 500ft (that's what I've gotten at 9600 a few times, a few errors, but it still worked). and if you read the datasheet, you'll see that you have to run your data input line to the TX module at the same voltage range as your power input.

I've ran that TX module at 2.5v before and gotten 100ft without troubles.

lerameur
- 27th December 2006, 18:39
I di dwhat you told me removing the char_spac adding more $55, its worst now,
its constantly showing 360, 445, and sometime the temperature
more often 445

skimask
- 27th December 2006, 18:54
I di dwhat you told me removing the char_spac adding more $55, its worst now,
its constantly showing 360, 445, and sometime the temperature
more often 445

Well, I would think that taking out the char_pacing and adding $55 would help it, but apparently not since none of the data is being encoded, the receiver is picking the $55 up as actual data or something.
Try it the other way around, but do one thing at a time.
1) No char_pacing - a single $55, no $55 (which should not work!)
2) no char_pacing - two $55's
3) no char_pacing - 4 $55's
4) small char_pacing - single $55 (I would think that any char_pacing value above 4000 would mess things up bad enough not to work at all)
....
....
etc.
See which one works out the best...
OR....
you could add you manchester encoding routine back into the program (from way back when, ya know, page 1!!!) and see what happens.

lerameur
- 27th December 2006, 19:34
I added DEFINE CHAR_PACING 2000
also 1000 works good with four $55
But it seems to be long to change the temperature, sometime the receiver seems to hang there with its value.

lerameur
- 27th December 2006, 20:21
HI, ok
I learned a lot in these four pages of posts,
What i did now I took the original program and modified it (serin, definnes, $55 , $aa ...
it works great now
I got a couple of glitches when I took the reciever down in the basement ( one floor below in a zig zag)
if you would like to see the code i could post it,

skimask
- 27th December 2006, 22:54
HI, ok
I learned a lot in these four pages of posts,
What i did now I took the original program and modified it (serin, definnes, $55 , $aa ...
it works great now
I got a couple of glitches when I took the reciever down in the basement ( one floor below in a zig zag)
if you would like to see the code i could post it,

Sure, maybe I can streamline it a bit or something...who knows...

Then again...maybe I better not touch it! It works...leave it! :)
But seriously, I'll take a look...

skimask
- 27th December 2006, 22:57
I added DEFINE CHAR_PACING 2000
also 1000 works good with four $55
But it seems to be long to change the temperature, sometime the receiver seems to hang there with its value.

Those temp sensors aren't designed to respond to temp changes RIGHT NOW. If they did, they'd be all over the place. Remember, you have a certain amount of mass that you have to heat or cool and it takes X amount of time to do that, especially buried down in the middle of the blob of goo where the sensing element actually is. Fill a glass with ice cubes, fill the rest of the glass with water, let it sit for a bit, then dip the sensor in the water. It should read just a hair over, if not right on 0C/32F. You can add a bit of calibration by doing that. I don't think I'd try the boiling water for the other end though! :)

lerameur
- 27th December 2006, 23:09
well here goes,
I still need to do work, because I dont think it measures negatives temperature. Not sure yet how i am going to do it, but I will be

Transmitter:
'TRANSMIT PIC
INCLUDE "modedefs.bas"
DEFINE OSC 20 'use external 20mhz crystal
CMCON = 7 : ANSEL = 0 : ADCON1 = 7
DEFINE LCD_DREG PORTA ' Set LCD Data port
DEFINE LCD_DBIT 0 ' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
DEFINE LCD_EREG PORTB ' Set LCD Enable port
DEFINE LCD_EBIT 0 ' Set LCD Enable bit
DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
DEFINE LCD_LINES 2 ' Set number of lines on LCD
DEFINE LCD_COMMANDUS 2500
DEFINE LCD_DATAUS 250
DEFINE CHAR_PACING 2000

DQ var PortB.4
temp var word

temperature var word
count_remain var byte
count_per_c var byte
counter var byte
tempc var word
dataout var word
dataout2 var word
datain var word
array var word
encoded1 var word
encoded2 var word
encoded22 var word
encoded11 var word


loop:
owout DQ,1,[$cc]
owout DQ,0,[$44]
Pause 500
owout DQ,1,[$cc]
owout DQ,0,[$be]
owin DQ, 0, [temperature.LOwBYTE, temperature.Highbyte, Skip 4, count_remain, count_per_c]
'50
temperature = ((( temperature >> 1) *100)- 25) + (((count_per_c - count_remain) * 100) / count_per_c)
tempc = (((temperature *9) / 5)+3200)
dataout = temperature / 100
dataout2 = temperature

encoded1 =temperature.LowBYTE
encoded2 =temperature.HighBYTE

For counter=0 TO 7
IF encoded1.0[counter]=0 Then
encoded11.0[counter*2]=0
encoded11.0[counter*2+1]=1
Else
encoded11.0[counter*2]=1
encoded11.0[counter*2+1]=0
EndIF
Next counter

For counter=0 TO 7
IF encoded2.0[counter]=0 Then
encoded22.0[counter*2]=0
encoded22.0[counter*2+1]=1
Else
encoded22.0[counter*2]=1
encoded22.0[counter*2+1]=0
EndIF
Next counter
lcdout $FE,1
LCDOUT "TempC: ", dec (temperature / 100) , ".", dec2 temperature," ",$DF,"C"
lcdout $FE,$C0, bin encoded11.HighBYTE , ".", bin encoded2," ",$DF,"F"

serout portb.2, n2400, [$55, $55, $55, $55, $aa]
serout portb.2, n2400, [encoded22.HighBYTE, encoded22.LowBYTE, encoded11.HighBYTE, encoded11.LowBYTE ]
goto loop

End


Receiver:
'RECEIVE PIC
INCLUDE "modedefs.bas"
DEFINE OSC 20 'use external 20mhz crystal
CMCON = 7 : ANSEL = 0 : ADCON1 = 7
DEFINE LCD_DREG PORTA ' Set LCD Data port
DEFINE LCD_DBIT 0 ' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
DEFINE LCD_EREG PORTB ' Set LCD Enable port
DEFINE LCD_EBIT 0 ' Set LCD Enable bit
DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
DEFINE LCD_LINES 2 ' Set number of lines on LCD
DEFINE LCD_COMMANDUS 2500
DEFINE LCD_DATAUS 250

'16
datain2 var word :temp var word
datain var word
dataout var word
counter var byte
temperature var word
encoded1 var word
encoded2 var word
encoded11 var word
encoded22 var word

pause 2000
'28
loop:

waitfor55:
serin portb.2 , n2400 , temp : if temp <> $55 then goto waitfor55

waitforaa:
serin portb.2 , n2400 , temp : if temp <> $aa then goto waitforaa

'36
serin portb.2, n2400, encoded22.HighBYTE
serin portb.2, n2400, encoded22.LowBYTE
serin portb.2, n2400, encoded11.HighBYTE
serin portb.2, n2400, encoded11.LowBYTE

For counter=0 TO 7 'decoding
encoded1.0[counter]=encoded11.0[counter*2]
encoded2.0[counter]=encoded22.0[counter*2]
Next counter

temperature= encoded1 ' putting back together as the original temperature
For counter=0 TO 7
temperature.0[counter+8]=encoded2.0[counter+8]
Next counter

temperature.LowBYTE = encoded1
temperature.HighBYTE = encoded2

lcdout $FE,1
LCDOUT "TempC: ", dec (temperature / 100) , ".", dec2 temperature," ",$DF,"C"
lcdout $FE,$C0, bin encoded11.HighBYTE , ".", bin encoded2," ",$DF,"F"


goto loop
end

skimask
- 27th December 2006, 23:23
well here goes,
I still need to do work, because I dont think it measures negatives temperature. Not sure yet how i am going to do it, but I will be

Transmitter:
'TRANSMIT PIC
INCLUDE "modedefs.bas"
DEFINE OSC 20 'use external 20mhz crystal
CMCON = 7 : ANSEL = 0 : ADCON1 = 7
DEFINE LCD_DREG PORTA ' Set LCD Data port
DEFINE LCD_DBIT 0 ' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
DEFINE LCD_EREG PORTB ' Set LCD Enable port
DEFINE LCD_EBIT 0 ' Set LCD Enable bit
DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
DEFINE LCD_LINES 2 ' Set number of lines on LCD
DEFINE LCD_COMMANDUS 2500
DEFINE LCD_DATAUS 250
DEFINE CHAR_PACING 2000

DQ var PortB.4 : temp var word : temperature var word
count_remain var byte : count_per_c var byte : counter var byte
tempc var word : dataout var word : dataout2 var word : datain var word
array var word : encoded1 var word : encoded2 var word
encoded22 var word : encoded11 var word

loop:
owout DQ,1,[$cc] : owout DQ,0,[$44] : Pause 500 : owout DQ,1,[$cc]
owout DQ,0,[$be]
owin DQ, 0, [temperature.LOwBYTE, temperature.Highbyte, Skip 4, count_remain, count_per_c]
'50
temperature = ((( temperature >> 1) *100)- 25) + (((count_per_c - count_remain) * 100) / count_per_c)
tempc = (((temperature *9) / 5)+3200) : dataout = temperature / 100
dataout2 = temperature

encoded1 = temperature.LowBYTE : encoded2 =temperature.HighBYTE

For counter=0 TO 7
IF encoded1.0[counter]=0 Then
encoded11.0[counter*2]=0 : encoded11.0[counter*2+1]=1
Else
encoded11.0[counter*2]=1 : encoded11.0[counter*2+1]=0
EndIF
Next counter

For counter=0 TO 7
IF encoded2.0[counter]=0 Then
encoded22.0[counter*2]=0 : encoded22.0[counter*2+1]=1
Else
encoded22.0[counter*2]=1 : encoded22.0[counter*2+1]=0
EndIF
Next counter
lcdout $FE,1
LCDOUT "TempC: ", dec (temperature / 100) , ".", dec2 temperature," ",$DF,"C"
lcdout $FE,$C0, bin encoded11.HighBYTE , ".", bin encoded2," ",$DF,"F"

serout portb.2, n2400, [$55, $55, $55, $55, $aa]
serout portb.2, n2400, [encoded22.HighBYTE, encoded22.LowBYTE, encoded11.HighBYTE, encoded11.LowBYTE ]
goto loop

End


Receiver:
'RECEIVE PIC
INCLUDE "modedefs.bas"
DEFINE OSC 20 'use external 20mhz crystal
CMCON = 7 : ANSEL = 0 : ADCON1 = 7
DEFINE LCD_DREG PORTA ' Set LCD Data port
DEFINE LCD_DBIT 0 ' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
DEFINE LCD_EREG PORTB ' Set LCD Enable port
DEFINE LCD_EBIT 0 ' Set LCD Enable bit
DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
DEFINE LCD_LINES 2 ' Set number of lines on LCD
DEFINE LCD_COMMANDUS 2500
DEFINE LCD_DATAUS 250

'16
datain2 var word :temp var word : datain var word : dataout var word
counter var byte : temperature var word : encoded1 var word
encoded2 var word : encoded11 var word : encoded22 var word

pause 2000
'28
loop:

waitfor55:
serin portb.2 , n2400 , temp : if temp <> $55 then goto waitfor55

waitforaa:
serin portb.2 , n2400 , temp : if temp <> $aa then goto waitforaa

'36
serin portb.2, n2400, encoded22.HighBYTE
serin portb.2, n2400, encoded22.LowBYTE
serin portb.2, n2400, encoded11.HighBYTE
serin portb.2, n2400, encoded11.LowBYTE
'you can combine the serin's into one statement (now that we got the bracket thing straightened out!!!)

For counter=0 TO 7 'decoding
encoded1.0[counter]=encoded11.0[counter*2]
encoded2.0[counter]=encoded22.0[counter*2]
Next counter

temperature= encoded1 ' putting back together as the original temperature
For counter=0 TO 7
temperature.0[counter+8]=encoded2.0[counter+8]
Next counter

temperature.LowBYTE = encoded1 : temperature.HighBYTE = encoded2

lcdout $FE,1
LCDOUT "TempC: ", dec (temperature / 100) , ".", dec2 temperature," ",$DF,"C"
lcdout $FE,$C0, bin encoded11.HighBYTE , ".", bin encoded2," ",$DF,"F"

goto loop
end


Looks good enough. As far as handling the negative numbers, I'd do all the math at the receiving end, that way you can preserve the sign bit and work with it there rather than try to worry about how to transmit the sign bit along with the real temperature and screwing it up in the process.

The negative temperature is nothing more than using 2's complement math. Google it, re-read the -1820 datasheet. It's not that hard to handle those cases. It just takes a bit of creative math to work it out. And PBP can handle it if you work it right (hint: re-read the PBP manual, the SEROUT can handle 'signed' integers, make that work for you in the receiver code).

lerameur
- 28th December 2006, 14:46
hi, I have this simple if then statement, it givs me four mistakes.. It tells me I need and endif and also its abad expression , this is straight out of the pbp manual. what is wrong with it

IF temperature.bit11 = 1 Then zerotemp


zerotemp
program here

skimask
- 28th December 2006, 15:13
hi, I have this simple if then statement, it givs me four mistakes.. It tells me I need and endif and also its abad expression , this is straight out of the pbp manual. what is wrong with it

IF temperature.bit11 = 1 Then zerotemp


zerotemp
program here

If temperature.11 = 1 then goto zerotemp (don't need the goto but it always keeps me straight, and bit11 should work, but I just use 11 for no reason in particular)

zerotemp: (you didn't have a colon)
program here

lerameur
- 28th December 2006, 15:50
naa, i was initializing zerotemp dee.
I am going to put the calculation on the receiver side only, this is getting real confusing.
The reason i did not want to do that is I am sending 4 byte of coded information. I want to have a high accuracy, so i would like to send the count_per_c and count_remain and in the data sheet. that will add more bytes, If I take the raw information and send it, it will be 4 bytes or 8 encoded byte to send. Is this do able ?
I mean is it too much to send wireles ?
k

lerameur
- 28th December 2006, 16:02
anywau here si the code fo the sending part:
i am just worried about the two serout line, should I put it into one line, or is it just the same like this,

I am leaving now, coming back ina few hours


'TRANSMIT PIC
INCLUDE "modedefs.bas"
DEFINE OSC 20 'use external 20mhz crystal
CMCON = 7 : ANSEL = 0 : ADCON1 = 7
DEFINE LCD_DREG PORTA ' Set LCD Data port
DEFINE LCD_DBIT 0 ' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
DEFINE LCD_EREG PORTB ' Set LCD Enable port
DEFINE LCD_EBIT 0 ' Set LCD Enable bit
DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
DEFINE LCD_LINES 2 ' Set number of lines on LCD
DEFINE LCD_COMMANDUS 2500
DEFINE LCD_DATAUS 250
DEFINE CHAR_PACING 2000

DQ var PortB.5
temp var word

temperature var word
count_remain var byte
count_per_c var byte
counter var byte

encoded1 var word
encoded2 var word
encoded22 var word
encoded11 var word
encoded33 var word
encoded44 var word

loop:
owout DQ,1,[$cc]
owout DQ,0,[$44]
Pause 500
owout DQ,1,[$cc]
owout DQ,0,[$be]
owin DQ, 0, [temperature.LOwBYTE, temperature.Highbyte, Skip 4, count_remain, count_per_c]
'50

encoded1 =temperature.LowBYTE
encoded2 =temperature.HighBYTE

For counter=0 TO 7
IF encoded1.0[counter]=0 Then
encoded11.0[counter*2]=0
encoded11.0[counter*2+1]=1
Else
encoded11.0[counter*2]=1
encoded11.0[counter*2+1]=0
EndIF
Next counter

For counter=0 TO 7
IF encoded2.0[counter]=0 Then
encoded22.0[counter*2]=0
encoded22.0[counter*2+1]=1
Else
encoded22.0[counter*2]=1
encoded22.0[counter*2+1]=0
EndIF
Next counter

For counter=0 TO 7
IF count_remain.0[counter]=0 Then
encoded33.0[counter*2]=0
encoded33.0[counter*2+1]=1
Else
encoded33.0[counter*2]=1
encoded33.0[counter*2+1]=0
EndIF
Next counter

For counter=0 TO 7
IF count_per_c.0[counter]=0 Then
encoded44.0[counter*2]=0
encoded44.0[counter*2+1]=1
Else
encoded44.0[counter*2]=1
encoded44.0[counter*2+1]=0
EndIF
Next counter


lcdout $FE,1
LCDOUT "TempC: ", dec (temperature / 100) , ".", dec2 temperature," ",$DF,"C"
lcdout $FE,$C0, bin count_remain , ".", bin count_per_c," ",$DF,"F"

serout portb.2, n2400, [$55, $55, $55, $55, $aa]
serout portb.2, n2400, [encoded11.HighBYTE, encoded11.LowBYTE, encoded22.HighBYTE, encoded22.LowBYTE ]
serout portb.2, n2400, [encoded33.HighBYTE, encoded33.LowBYTE, encoded44.HighBYTE, encoded44.LowBYTE ]
goto loop

End

skimask
- 28th December 2006, 16:11
naa, i was initializing zerotemp dee.
I am going to put the calculation on the receiver side only, this is getting real confusing.
The reason i did not want to do that is I am sending 4 byte of coded information. I want to have a high accuracy, so i would like to send the count_per_c and count_remain and in the data sheet. that will add more bytes, If I take the raw information and send it, it will be 4 bytes or 8 encoded byte to send. Is this do able ?
I mean is it too much to send wireles ?
k

I send strings and strings of data using the TWS/RWS modules without much problem at all. Of course I get messed up data once in awhile, that's what error detection is for (checksums, etc.). 4/8 bytes is fine...1000 bytes is fine. It's all in how you want to send it, break it down, detect errors, etc. Just create and use LEDAWDTP (lerameur's error detection and wireless data transfer protocol).

I agree...send only the raw information, then do the math at the receiver end, again, with some error correction. For instance, you get one reading, save it placeA and display it...you get the next reading, save it in placeB. If the placeB reading is higher than placeA, then increment placeA by one, same thing is it's lower, decrement it by one. That way, a one-time reading that's 'out in the weeds' because of bad data won't neccessarily show up on the output as a fluctuating result.

skimask
- 28th December 2006, 16:13
Now that the whole thing is working, you can probably condense those serout lines down into one line...try it and find out...
That and it makes the program shorter on the screen so you don't have to scroll thru so much stuff...

'TRANSMIT PIC
INCLUDE "modedefs.bas"
DEFINE OSC 20 'use external 20mhz crystal
CMCON = 7 : ANSEL = 0 : ADCON1 = 7
DEFINE LCD_DREG PORTA ' Set LCD Data port
DEFINE LCD_DBIT 0 ' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
DEFINE LCD_EREG PORTB ' Set LCD Enable port
DEFINE LCD_EBIT 0 ' Set LCD Enable bit
DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
DEFINE LCD_LINES 2 ' Set number of lines on LCD
DEFINE LCD_COMMANDUS 2500
DEFINE LCD_DATAUS 250
DEFINE CHAR_PACING 2000

DQ var PortB.5 : temp var word : temperature var word : count_remain var byte : count_per_c var byte : counter var byte
encoded1 var word:encoded2 var word:encoded22 var word:encoded11 var word:encoded33 var word:encoded44 var word

loop:
owout DQ,1,[$cc] : owout DQ,0,[$44] : Pause 500 : owout DQ,1,[$cc] : owout DQ,0,[$be]
owin DQ, 0, [temperature.LOwBYTE, temperature.Highbyte, Skip 4, count_remain, count_per_c]
'50

encoded1 =temperature.LowBYTE : encoded2 =temperature.HighBYTE

'I'd put these encoding/decoding sections into their own subroutine to GOSUB to...
For counter=0 TO 7
IF encoded1.0[counter]=0 Then
encoded11.0[counter*2]=0 : encoded11.0[counter*2+1]=1
Else
encoded11.0[counter*2]=1 : encoded11.0[counter*2+1]=0
EndIF
Next counter

For counter=0 TO 7
IF encoded2.0[counter]=0 Then
encoded22.0[counter*2]=0 : encoded22.0[counter*2+1]=1
Else
encoded22.0[counter*2]=1 : encoded22.0[counter*2+1]=0
EndIF
Next counter

For counter=0 TO 7
IF count_remain.0[counter]=0 Then
encoded33.0[counter*2]=0 : encoded33.0[counter*2+1]=1
Else
encoded33.0[counter*2]=1 : encoded33.0[counter*2+1]=0
EndIF
Next counter

For counter=0 TO 7
IF count_per_c.0[counter]=0 Then
encoded44.0[counter*2]=0 : encoded44.0[counter*2+1]=1
Else
encoded44.0[counter*2]=1 : encoded44.0[counter*2+1]=0
EndIF
Next counter


lcdout $FE,1 : LCDOUT "TempC: ", dec (temperature / 100) , ".", dec2 temperature," ",$DF,"C"
lcdout $FE,$C0, bin count_remain , ".", bin count_per_c," ",$DF,"F"

serout portb.2, n2400,[$55,$55,$55,$55,$aa,encoded11.HighBYTE,encoded11.L owBYTE,encoded22.HighBYTE]
serout portb.2, n2400,[encoded22.LowBYTE,encoded33.HighBYTE,encoded33.Low BYTE,encoded44.HighBYTE]
serout portb.2, n2400,[encoded44.LowBYTE]
goto loop

lerameur
- 28th December 2006, 20:29
OK, I must be getting lucky, I'm not getting many mistakes as before. The system works now, the sending code is good. The receiving is good for positive celcius, For some undetermined reason it is not giving the right Ferenheit degrees, and I am using the same math equation as before to translate from C to F.
I am now working on the negative celcius and also in that scenatio there is two cases, positive and negative F ...
I will the subroutine for later, I never touched it before so I will do it at the end once everything is working

'RECEIVE PIC
INCLUDE "modedefs.bas"
DEFINE OSC 20 'use external 20mhz crystal
CMCON = 7 : ANSEL = 0 : ADCON1 = 7
DEFINE LCD_DREG PORTA ' Set LCD Data port
DEFINE LCD_DBIT 0 ' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
DEFINE LCD_EREG PORTB ' Set LCD Enable port
DEFINE LCD_EBIT 0 ' Set LCD Enable bit
DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
DEFINE LCD_LINES 2 ' Set number of lines on LCD
DEFINE LCD_COMMANDUS 2500
DEFINE LCD_DATAUS 250
DEFINE CHAR_PACING 2000

counter var byte : temperature var word : encoded1 var word : encoded2 var word : encoded3 var byte
encoded11 var word : encoded22 var word : encoded33 var word : encoded44 var word : encoded4 var byte
count_remain var byte : count_per_c var byte : temp var byte : tempc var byte
pause 2000

loop:
'23
waitfor55:
serin portb.2 , n2400 , temp : if temp <> $55 then goto waitfor55

waitforaa:
serin portb.2 , n2400 , temp : if temp <> $aa then goto waitforaa

serin portb.2, n2400, encoded11.HighBYTE : serin portb.2, n2400, encoded11.LowBYTE
serin portb.2, n2400, encoded22.HighBYTE : serin portb.2, n2400, encoded22.LowBYTE
serin portb.2, n2400, encoded33.HighBYTE : serin portb.2, n2400, encoded33.LowBYTE
serin portb.2, n2400, encoded44.HighBYTE : serin portb.2, n2400, encoded44.LowBYTE

For counter=0 TO 7 'decoding
encoded1.0[counter]=encoded11.0[counter*2] : encoded2.0[counter]=encoded22.0[counter*2]
encoded3.0[counter]=encoded33.0[counter*2] : encoded4.0[counter]=encoded44.0[counter*2]
Next counter
'41
temperature= encoded1 ' putting back together as the original temperature
For counter=0 TO 7
temperature.0[counter+8]=encoded2.0[counter+8]
Next counter

temperature.LowBYTE = encoded1
temperature.HighBYTE = encoded2
count_remain = encoded3
count_per_c = encoded4

IF temperature.11 = 1 Then goto Zerotemp
temperature = ((( temperature >> 1) *100)- 25) + (((count_per_c - count_remain) * 100) / count_per_c)
tempc = (((temperature *9) / 5)+3200)

lcdout $FE,1, "TempC: ", "+", dec (temperature / 100) , ".", dec2 temperature," ",$DF,"C"
lcdout $FE,$C0, "TempF: ", dec (tempc / 100) , ".", dec2 tempc >> 1," ",$DF,"F"
goto loop

Zerotemp:
temperature = temperature >> 1 'removing lowest bit
for counter=0 to 14 ' 2's compliment, starting to invert all the digits
if temperature.0[counter] = 1 then temperature.0[counter] =1
if temperature.0[counter] = 0 then temperature.0[counter] =0
next counter
temperature = temperature + 1 ' 2,s compliment ends by adding a one

temperature = ((( temperature >> 1) *100)- 25) + (((count_per_c - count_remain) * 100) / count_per_c)
tempc = (((temperature *9) / 5)+3200)

lcdout $FE,1, "TempC: ", "-", dec (temperature / 100) , ".", dec2 temperature," ",$DF,"C"
lcdout $FE,$C0, "TempF: ", dec (tempc / 100) , ".", dec2 tempc >> 1," ",$DF,"F"
goto loop


end

skimask
- 28th December 2006, 20:43
for one thing, tempc should be tempf shouldn't it?
Another thing, if your temp value (which I assume is multiplied by 100 by that conversion/correction thing you've got going on) is above 7281, you'll overflow your 16 bit tempc value (65536 / 9 = 7281.xxx). So try dividing by 5 first, then multiply by 9.

tempc = ( ( ( temperature / 5 ) * 9 ) + 3200 )

another thing...what are you trying to do with the lcdout line?
lcdout $FE,$C0,"TempF:",dec (tempc/100),".",dec2 tempc >>1," ",$DF,"F"

I think what you really mean is:
lcdout $fe,$c0,"TempF:",DEC3 (tempc/100),".",DEC2 (tempc//100)," ",$DF,"F"

use the remainder (modulus) ( // ) function, not the shift ( >> ) function.

lerameur
- 28th December 2006, 20:54
its working good, now, I think I have a problem with the 2,s compliment, working on it
I am just doing 2,s compliment, I get all 1,s at the output


Zerotemp:
temperature = temperature >> 1 'removing lowest bit
temperature1 = temperature
for counter=0 to 6 ' 2's compliment, starting to invert all the digits
if temperature.0[counter] = 1 then temperature.0[counter] =0
if temperature.0[counter] = 0 then temperature.0[counter] =1
next counter
'temperature = temperature + 1 ' 2,s compliment ends by adding a one

'temperature = ((( temperature >> 1) *100)- 25) + (((count_per_c - count_remain) * 100) / count_per_c)
'tempc = (((temperature *9) / 5) + 3200)

lcdout $FE,1, "TempC: ", bin temperature1, ".", dec2 temperature," ",$DF,"C"
lcdout $FE,$C0, "TempF: ", bin temperature , ".", dec2 (tempF // 100)," ",$DF,"F"
goto loop

lerameur
- 28th December 2006, 22:45
I just flip these around and it works

if temperature.0[counter] = 0 then temperature.0[counter] =1
if temperature.0[counter] = 1 then temperature.0[counter] =0

skimask
- 28th December 2006, 23:25
Zerotemp:
temperature = temperature >> 1 'removing lowest bit
temperature1 = temperature
------------------------------------------why are you removing the lowest bit?

for counter=0 to 6 ' 2's compliment, starting to invert all the digits
if temperature.0[counter] = 1 then temperature.0[counter] =0
if temperature.0[counter] = 0 then temperature.0[counter] =1
next counter
------------------------------------this will never work....follow it thru
1. if temp.counter = 1 then set it to 0
2. if it's zero set it to 1.....it just got set to zero by the above line!!!!!
what you want is:

for counter = 0 to 6
if temperature.0[counter] = 1 then
temperature.0[counter] = 0
else
temperature.0[counter] = 1
endif

or just use this:
temperature = ~ temperature (bitwise inversion)



'temperature = temperature + 1 ' 2,s compliment ends by adding a one

'temperature = ((( temperature >> 1) *100)- 25) + (((count_per_c - count_remain) * 100) / count_per_c)
'tempc = (((temperature *9) / 5) + 3200)

lcdout $FE,1, "TempC: ", bin temperature1, ".", dec2 temperature," ",$DF,"C"
lcdout $FE,$C0, "TempF: ", bin temperature , ".", dec2 (tempF // 100)," ",$DF,"F"
goto loop

And you didn't change the temperature to doing the /5 first, and then the *9. If you leave it the way you've got it, you'll get an overflow when it gets really warm outside!

lerameur
- 28th December 2006, 23:26
when it get to ZERO, it shows 655,
then when it reach about -3 then it shows the right temp, weird..
any idea?

skimask
- 28th December 2006, 23:27
I just flip these around and it works

if temperature.0[counter] = 0 then temperature.0[counter] =1
if temperature.0[counter] = 1 then temperature.0[counter] =0

See my post above referring to your post #114...your logic above is flawed also

(temperature.0[counter] - just call it temp for right now)
if temp is zero, set it to one. then go to the next line down
if temp is one, set it to zero. again, it just got set to 1 on the line above!

skimask
- 28th December 2006, 23:28
when it get to ZERO, it shows 655,
then when it reach about -3 then it shows the right temp, weird..
any idea?

Not wierd, you just have to fix a bunch of stuff....!

lerameur
- 29th December 2006, 00:19
its all good now, exept foe that part between 0 to -5 degrees celcius,
There is no grey area, if the bit 11 os 1, then goto zerotemp, the math is the same for -1 C or -10C....

'RECEIVE PIC
INCLUDE "modedefs.bas"
DEFINE OSC 20 'use external 20mhz crystal
CMCON = 7 : ANSEL = 0 : ADCON1 = 7
DEFINE LCD_DREG PORTA ' Set LCD Data port
DEFINE LCD_DBIT 0 ' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
DEFINE LCD_EREG PORTB ' Set LCD Enable port
DEFINE LCD_EBIT 0 ' Set LCD Enable bit
DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
DEFINE LCD_LINES 2 ' Set number of lines on LCD
DEFINE LCD_COMMANDUS 2500
DEFINE LCD_DATAUS 250
DEFINE CHAR_PACING 2000

counter var byte : temperature var word : encoded1 var word : encoded2 var word : encoded3 var byte
encoded11 var word : encoded22 var word : encoded33 var word : encoded44 var word : encoded4 var byte
count_remain var byte : count_per_c var byte : temp var word : tempc var byte : tempF var word
temperature1 var word
pause 2000

loop:
'23
waitfor55:
serin portb.2 , n2400 , temp : if temp <> $55 then goto waitfor55

waitforaa:
serin portb.2 , n2400 , temp : if temp <> $aa then goto waitforaa

serin portb.2, n2400, encoded11.HighBYTE : serin portb.2, n2400, encoded11.LowBYTE
serin portb.2, n2400, encoded22.HighBYTE : serin portb.2, n2400, encoded22.LowBYTE
serin portb.2, n2400, encoded33.HighBYTE : serin portb.2, n2400, encoded33.LowBYTE
serin portb.2, n2400, encoded44.HighBYTE : serin portb.2, n2400, encoded44.LowBYTE

For counter=0 TO 7 'decoding
encoded1.0[counter]=encoded11.0[counter*2] : encoded2.0[counter]=encoded22.0[counter*2]
encoded3.0[counter]=encoded33.0[counter*2] : encoded4.0[counter]=encoded44.0[counter*2]
Next counter
'41
temperature= encoded1 ' putting back together as the original temperature
For counter=0 TO 7
temperature.0[counter+8]=encoded2.0[counter+8]
Next counter

temperature.LowBYTE = encoded1
temperature.HighBYTE = encoded2
count_remain = encoded3
count_per_c = encoded4

IF temperature.11 = 1 Then goto Zerotemp
temperature = ((( temperature >> 1) *100)- 25) + (((count_per_c - count_remain) * 100) / count_per_c)
tempF = (((temperature /5) *9 ) + 3200)

lcdout $FE,1, "TempC: ", "+", dec (temperature / 100) , ".", dec2 temperature," ",$DF,"C"
lcdout $FE,$C0, "TempF: ", "+", dec2 (tempF / 100) , ".", dec2 (tempF // 100)," ",$DF,"F"
goto loop

Zerotemp: ' cases when zero celcius and positive Fahrenheit
temperature = temperature >> 1 'removing lowest bit
temperature1 = temperature
for counter = 0 to 6
if temperature.0[counter] = 1 then
temperature.0[counter] = 0
else
temperature.0[counter] = 1
endif
next counter

temp = temp + 1 ' 2,s compliment ends by adding a one
temp = temp >> 5

temperature = ((( temp ) *100)- 25) + (((count_per_c - count_remain) * 100) / count_per_c)
tempF = 3200 -((temperature /5) * 9)
if tempF = 0 then goto ZeroF

lcdout $FE,1, "TempC: ", "-", dec (temperature / 100) , ".", dec2 temperature," ",$DF,"C"
lcdout $FE,$C0, "TempF: ", dec (tempF / 100) , ".", dec2 tempF ," ",$DF,"F"
goto loop

ZeroF: ' cases when zero celcius and 0 Fahrenheit
temperature = ((( temp ) *100)- 25) + (((count_per_c - count_remain) * 100) / count_per_c)
tempF = 3200 -((temperature /5) * 9)

lcdout $FE,1, "TempC: ", "-", dec (temperature / 100) , ".", dec2 temperature," ",$DF,"C"
lcdout $FE,$C0, "TempF: ", "-", dec (tempF / 100) , ".", dec2 tempF ," ",$DF,"F"

goto loop

end

skimask
- 29th December 2006, 01:26
ZeroF: ' cases when zero celcius and 0 Fahrenheit

end

You do realize that 0C is not 0F right?
0C = 32F
0F = -17.78C

Maybe it would be easier (if you really need to display both C and F) if you'd convert your initial celsius reading from the serin statements over to the Kelvin scale (0C = 273K, 0K = -273C), add in the correction factors, and then convert them back, taking into account the + and - as needed right before displaying the final numbers

lerameur
- 29th December 2006, 01:40
You do realize that 0C is not 0F right?
0C = 32F
0F = -17.78C
------------ at 0F the program jumps to ZeroF taking into account that now both C anf F are negative


Maybe it would be easier (if you really need to display both C and F) if you'd convert your initial celsius reading from the serin statements over to the Kelvin scale (0C = 273K, 0K = -273C), add in the correction factors, and then convert them back, taking into account the + and - as needed right before displaying the final numbers

----------- If I do that I will still have three posibilities with the same conversion won't I?
I mean
1) +C and +F
2) -C and +F
3) -C and -F

skimask
- 29th December 2006, 01:47
----------- If I do that I will still have three posibilities with the same conversion won't I?
I mean
1) +C and +F
2) -C and +F
3) -C and -F

And all based from the celsius value....
1) if tempC > 0 then both C and F are positive
2) if tempC => -17 and tempC <=0 then C is negative, F is positive
3) if tempC < -17 then both C and F are negative

or in Kelvin terms...
1) if tempK > 273 then C/F +
2) if tempK => 256 and tempK <=273 then C- and F+
3) if tempK < 256 then C/F -

lerameur
- 29th December 2006, 01:55
yes exactly, that,s what i meant, I omitted the numerical degrees.
I believe this is what I have in my program.
One glitch is that when is hits ZERO, it immediatly shows -5C, the conversion from C to F is good (making conversion from -5 to 23F) BUt it is not getting the right values between 0 to -5 C

skimask
- 29th December 2006, 02:03
Well, this might be a bug...or not...the tempC to tempF conversion is done differently in the 2 spots...and so are the lines above that...2 different methods... Shouldn't everything be the same except for the display?



IF temperature.11 = 1 Then goto Zerotemp
temperature = ((( temperature >> 1) *100)- 25) + (((count_per_c - count_remain) * 100) / count_per_c)
tempF = (((temperature /5) *9 ) + 3200)
..................................................

Zerotemp: ' cases when zero celcius and positive Fahrenheit
...............
temperature = ((( temp ) *100)- 25) + (((count_per_c - count_remain) * 100) / count_per_c)
tempF = 3200 -((temperature /5) * 9)

'maybe should be tempf = (((temperature /5) *9 ) + 3200) like it was above?

if tempF = 0 then goto ZeroF

end



I'm not sure, you're doing it a bit different than I would do it... maybe it's one of those 'features' like Windows always has in it that Microsoft fixes every Tuesday :)

lerameur
- 29th December 2006, 02:18
I made these formulas and tested them on a calculator. it works. I dont know hy it do not work on the pogram I wrote.
So
ZeroF: ' cases when zero celcius and 0 Fahrenheit
temperature = ((( temp ) *100)- 25) + (((count_per_c - count_remain) * 100) / count_per_c)
tempF = 3200 -((temperature /5) * 9)

--- SO if I need to do the conversion : -17C to 1.4F
so I take 1700 (17 *100) put it in the formula (temperature) I get 140, just divide by 100 to get the answer..

k

skimask
- 29th December 2006, 04:54
I made these formulas and tested them on a calculator. it works. I dont know hy it do not work on the pogram I wrote.
So
ZeroF: ' cases when zero celcius and 0 Fahrenheit
temperature = ((( temp ) *100)- 25) + (((count_per_c - count_remain) * 100) / count_per_c)
tempF = 3200 -((temperature /5) * 9)

--- SO if I need to do the conversion : -17C to 1.4F
so I take 1700 (17 *100) put it in the formula (temperature) I get 140, just divide by 100 to get the answer..

k


Zerotemp: ' cases when zero celcius and positive Fahrenheit
temperature = temperature >> 1 'removing lowest bit
temperature1 = temperature
for counter = 0 to 6
if temperature.0[counter] = 1 then
temperature.0[counter] = 0
else
temperature.0[counter] = 1
endif
next counter



------------------------------------temp value right here not set up
temp = temp + 1 ' 2,s compliment ends by adding a one
temp = temp >> 5

temperature = ((( temp ) *100)- 25) + (((count_per_c - count_remain) * 100) / count_per_c)
tempF = 3200 -((temperature /5) * 9)
if tempF = 0 then goto ZeroF

lcdout $FE,1, "TempC: ", "-", dec (temperature / 100) , ".", dec2 temperature," ",$DF,"C"
lcdout $FE,$C0, "TempF: ", dec (tempF / 100) , ".", dec2 tempF ," ",$DF,"F"
goto loop

ZeroF: ' cases when zero celcius and 0 Fahrenheit
temperature = ((( temp ) *100)- 25) + (((count_per_c - count_remain) * 100) / count_per_c)
tempF = 3200 -((temperature /5) * 9)

lcdout $FE,1, "TempC: ", "-", dec (temperature / 100) , ".", dec2 temperature," ",$DF,"C"
lcdout $FE,$C0, "TempF: ", "-", dec (tempF / 100) , ".", dec2 tempF ," ",$DF,"F"

goto loop

Where is the first temp getting set at? I don't think it is. I think it's always $ab (left over $aa from the serin with 1 added).

lerameur
- 29th December 2006, 13:25
I just got up, looked at the program , wow , a mess I did yesterday....
I have to go be back working on it this afternoon.

lerameur
- 29th December 2006, 21:00
ok I changed it a bit, but it is still getting confused about the zero mark.
stll showing +655.XX celcius
another thing, the decimal values are going the opposite way in the negative ,
meaning, -1.96 to -1.90 instead of -1.90 to -1.96
I have dec2 temperature for the decimal I tried
1- dec2 temperature but it do not work ...

loop:
'23
waitfor55:
serin portb.2 , n2400 , temp : if temp <> $55 then goto waitfor55

waitforaa:
serin portb.2 , n2400 , temp : if temp <> $aa then goto waitforaa

serin portb.2, n2400, encoded11.HighBYTE : serin portb.2, n2400, encoded11.LowBYTE
serin portb.2, n2400, encoded22.HighBYTE : serin portb.2, n2400, encoded22.LowBYTE
serin portb.2, n2400, encoded33.HighBYTE : serin portb.2, n2400, encoded33.LowBYTE
serin portb.2, n2400, encoded44.HighBYTE : serin portb.2, n2400, encoded44.LowBYTE

For counter=0 TO 7 'decoding
encoded1.0[counter]=encoded11.0[counter*2] : encoded2.0[counter]=encoded22.0[counter*2]
encoded3.0[counter]=encoded33.0[counter*2] : encoded4.0[counter]=encoded44.0[counter*2]
Next counter
'41
temperature= encoded1 ' putting back together as the original temperature
For counter=0 TO 7
temperature.0[counter+8]=encoded2.0[counter+8]
Next counter

temperature.LowBYTE = encoded1
temperature.HighBYTE = encoded2
count_remain = encoded3
count_per_c = encoded4

IF temperature.11 = 1 Then goto Zerotemp
temperature = ((( temperature >> 1) *100)- 25) + (((count_per_c - count_remain) * 100) / count_per_c)
tempF = (((temperature /5) *9 ) + 3200)

lcdout $FE,1, "TempC: ", "+", dec (temperature / 100) , ".", dec2 temperature," ",$DF,"C"
lcdout $FE,$C0, "TempF: ", "+", dec2 (tempF / 100) , ".", dec2 (tempF // 100)," ",$DF,"F"
goto loop

Zerotemp: '------------- cases when zero celcius and positive Fahrenheit
temperature = ~temperature +1
'63
temperature = ((( temperature >>1 ) *100)- 25) + (((count_per_c - count_remain) * 100) / count_per_c)
tempF = 3200 -((temperature /5) * 9)
if tempF <= 0 then goto ZeroF

lcdout $FE,1, "TempC: ", "-", dec (temperature / 100) , ".", dec2 temperature," ",$DF,"C"
lcdout $FE,$C0, "TempF: ", dec (tempF / 100) , ".", dec2 tempF ," ",$DF,"F"
goto loop

ZeroF: '---------------- cases when zero celcius and 0 Fahrenheit
tempF = 3200 -((temperature /5) * 9)

lcdout $FE,1, "TempC: ", "-", dec (temperature / 100) , ".", dec2 temperature," ",$DF,"C"
lcdout $FE,$C0, "TempF: ", "-", dec (tempF / 100) , ".", dec2 tempF ," ",$DF,"F"

goto loop

end

skimask
- 29th December 2006, 21:45
ok I changed it a bit, but it is still getting confused about the zero mark.
stll showing +655.XX celcius
another thing, the decimal values are going the opposite way in the negative ,
meaning, -1.96 to -1.90 instead of -1.90 to -1.96
I have dec2 temperature for the decimal I tried
1- dec2 temperature but it do not work ...
end


So, I can assume that the positive temperature readings are all correct?

Why are the 2nd and 3rd temp conversion formula's different from the 1st?
t = 3200 - *5 / 9 instead of t = T*5/9 + 3200 (shortened, you know what they are)

temperature = ( ~temperature ) + 1 try that also





loop:
'23
waitfor55:
serin portb.2 , n2400 , temp : if temp <> $55 then goto waitfor55

waitforaa:
serin portb.2 , n2400 , temp : if temp <> $aa then goto waitforaa

serin portb.2, n2400, encoded11.HighBYTE : serin portb.2, n2400, encoded11.LowBYTE
serin portb.2, n2400, encoded22.HighBYTE : serin portb.2, n2400, encoded22.LowBYTE
serin portb.2, n2400, encoded33.HighBYTE : serin portb.2, n2400, encoded33.LowBYTE
serin portb.2, n2400, encoded44.HighBYTE : serin portb.2, n2400, encoded44.LowBYTE

For counter=0 TO 7 'decoding
encoded1.0[counter]=encoded11.0[counter*2] : encoded2.0[counter]=encoded22.0[counter*2]
encoded3.0[counter]=encoded33.0[counter*2] : encoded4.0[counter]=encoded44.0[counter*2]
Next counter
'41
temperature= encoded1 ' putting back together as the original temperature
For counter=0 TO 7
temperature.0[counter+8]=encoded2.0[counter+8]
Next counter

temperature.LowBYTE = encoded1
temperature.HighBYTE = encoded2
count_remain = encoded3
count_per_c = encoded4

IF temperature.11 = 1 Then goto Zerotemp
temperature = ((( temperature >> 1) *100)- 25) + (((count_per_c - count_remain) * 100) / count_per_c)
tempF = (((temperature /5) *9 ) + 3200)

lcdout $FE,1, "TempC: ", "+", dec (temperature / 100) , ".", dec2 temperature," ",$DF,"C"
lcdout $FE,$C0, "TempF: ", "+", dec2 (tempF / 100) , ".", dec2 (tempF // 100)," ",$DF,"F"
goto loop

Zerotemp: '------------- cases when zero celcius and positive Fahrenheit
'temperature = ( ~ temperature ) + 1 ----- do this later, right before displaying it
'63
temperature = ((( temperature >>1 ) *100)- 25) + (((count_per_c - count_remain) * 100) / count_per_c)
tempF = ((temperature /5) * 9) + 3200

if tempF <= 0 then goto ZeroF

temperature = ( ~ temperature ) + 1 : tempf = ( ~ tempF ) + 1 ' added this
lcdout $FE,1, "TempC: ", "-", dec (temperature / 100) , ".", dec2 temperature," ",$DF,"C"
lcdout $FE,$C0, "TempF: ", dec (tempF / 100) , ".", dec2 tempF ," ",$DF,"F"
goto loop

ZeroF: '---------------- cases when zero celcius and 0 Fahrenheit
tempF = ((temperature /5) * 9) + 3200

temperature = ( ~ temperature ) + 1 : tempf = ( ~ tempF ) + 1 ' added this
lcdout $FE,1, "TempC: ", "-", dec (temperature / 100) , ".", dec2 temperature," ",$DF,"C"
lcdout $FE,$C0, "TempF: ", "-", dec (tempF / 100) , ".", dec2 tempF ," ",$DF,"F"

goto loop

end



Try that....

I just did an edit... You might have to do the correction/conversion/calculation before you do the 2's complement conversion. I've modified the program for that.

skimask
- 29th December 2006, 22:00
Found this at Rentron's site:

'************************************************* *******
'* Name : Temp.BAS *
'* Author : Bruce Reynolds *
'* Notice : Copyright (c) 2003 Reynolds Electronics *
'* : All Rights Reserved *
'* Date : 7/28/2003 *
'* Version : 1.0 *
'* Notes : *
'* : *
'************************************************* *******
DEFINE osc 20 ' We're using a 20MHz oscillator
Comm_Pin VAR PortC.0 ' One-wire Data-Pin "DQ" on PortC.0
Busy VAR BIT ' Busy Status-Bit
R_Temp VAR WORD ' RAW Temperature readings
TempC VAR WORD ' Temp in deg C
TempF VAR WORD ' Temp in deg F
Float VAR WORD ' Holds remainder for + temp C display
Cold_Bit VAR R_Temp.Bit11' Sign-Bit for +/- Temp. 1 = Below 0 deg C
Real_Cold CON 1 ' Define Real_Cold = 1
BAUD CON 16468 ' N9600 for serial LCD
DISP VAR PortB.0 ' Pin to drive serial LCD
Deg CON 223 ' Data to display Deg ° symbol
CLR CON 1 ' CLR LCD command
LINE1 CON 128 ' LCD line #1
LINE2 CON 192 ' LCD line #2
LINE3 CON 148 ' LCD line #3
LINE4 CON 212 ' LCD line #4
INS CON 254 ' LCD command mode parameter
Sign VAR BYTE ' +/- sign for temp display
Dummy VAR BYTE ' Dummy for Div32

SEROUT2 DISP,BAUD, [INS,CLR]
Start_Convert:
OWOUT Comm_Pin, 1, [$CC, $44]' Skip ROM search & do temp conversion

Wait_Up:
OWIN Comm_Pin, 4, [Busy] ' Read busy-bit
IF Busy = 0 THEN Wait_Up ' Still busy..?, Wait_Up..!
OWOUT Comm_Pin, 1, [$CC, $BE]' Skip ROM search & read scratchpad memory
OWIN Comm_Pin, 2, [R_Temp.Lowbyte, R_Temp.Highbyte]' Read two bytes / end comms
GOSUB Convert_Temp
GOTO Start_Convert

Convert_Temp: ' +32.0 to +257 F
IF Cold_Bit = Real_Cold THEN Yikes ' If Cold_Bit = 1, it's below "0" deg C
Sign = "+"
Dummy = 625 * R_Temp ' Multiply to load internal registers with 32-bit value
TempC = DIV32 10 ' Use Div32 value to calculate precise deg C
Dummy = 1125 * R_Temp
TempF = DIV32 100
IF TempF >6795 THEN ' Over 99.5 deg F..?
TempF = TempF + 3200
SEROUT2 DISP,BAUD, [INS,LINE1, " TempF = ",Sign,DEC TempF DIG 4,_
DEC TempF DIG 3,DEC TempF DIG 2,".",DEC2 TempF,Deg,"F "]
ELSE
TempF = TempF + 3200
SEROUT2 DISP,BAUD, [INS,LINE1, " TempF = ",Sign,DEC TempF DIG 3,_
DEC TempF DIG 2,".",DEC2 TempF,Deg,"F "]
ENDIF
TempC = (R_Temp & $0FF0) >> 4 ' Mask middle 8-bits, shift into lower byte
Float = ((R_Temp.Lowbyte & $0F) * 625) ' Lower 4-bits of result * 625
SEROUT2 DISP,BAUD, [INS,LINE2, " TempC = ",Sign,DEC TempC,".",DEC Float,Deg,"C "]
SEROUT2 DISP,BAUD, [INS,LINE4, "Raw", IBIN16 R_Temp]
RETURN

Yikes: ' Display full range -C to -F conversion
Sign = "-" ' Display - symbol for negative temp
Dummy = 625 * ~R_Temp+1' Multiply to load internal registers with 32-bit value
TempC = DIV32 10 ' Use Div32 value to calculate precise deg C
TempF = ~R_Temp / 16 ' Begin conversion from -C to deg +/-F
IF TempF >=18 THEN ' Check for -degrees F "-18 C = -0.4 F"
TempF = ((((TempF + 50) * 9) /5) -122) ' -C to -F below -17 deg C
SEROUT2 DISP,BAUD, [INS,LINE1, " TempF = ",Sign, DEC TempF,Deg,"F "]
SEROUT2 DISP,BAUD, [INS,LINE2, " TempC = ",Sign,DEC TempC DIG 4,_
DEC TempC DIG 3,".",DEC3 TempC,Deg,"C "]
SEROUT2 DISP,BAUD, [INS,LINE4, "Raw", IBIN16 R_Temp]
ELSE ' Else result = +deg F
TempF = ((((-TempF + 50) * 9) /5) -58)' -C to +F below 32.0 deg F to -17 deg C
SEROUT2 DISP,BAUD, [INS,LINE1, " TempF = ","+",DEC TempF,Deg,"F "]
SEROUT2 DISP,BAUD, [INS,LINE2, " TempC = ",Sign,DEC TempC DIG 4,_
DEC TempC DIG 3,".",DEC3 TempC,Deg,"C "]
SEROUT2 DISP,BAUD, [INS,LINE4, "Raw", IBIN16 R_Temp]
ENDIF
RETURN

END



Might get some good ideas from here on how to do the job efficiently.

lerameur
- 29th December 2006, 22:27
yes the positive values works just fine,
I dont why you are doing 2,s compliment twice in the zerotemp.
I saw that program , but there was too many things I did not understand, like this line:
Dummy = 625 * R_Temp ' Multiply to load internal registers with 32-bit value

Why multiply by 625..


I also tryed it as is: ( it get stuck at 0.00 C and stays there)

loop:
'24
waitfor55:
serin portb.2 , n2400 , temp : if temp <> $55 then goto waitfor55

waitforaa:
serin portb.2 , n2400 , temp : if temp <> $aa then goto waitforaa

serin portb.2, n2400, encoded11.HighBYTE : serin portb.2, n2400, encoded11.LowBYTE
serin portb.2, n2400, encoded22.HighBYTE : serin portb.2, n2400, encoded22.LowBYTE
serin portb.2, n2400, encoded33.HighBYTE : serin portb.2, n2400, encoded33.LowBYTE
serin portb.2, n2400, encoded44.HighBYTE : serin portb.2, n2400, encoded44.LowBYTE

For counter=0 TO 7 'decoding
encoded1.0[counter]=encoded11.0[counter*2] : encoded2.0[counter]=encoded22.0[counter*2]
encoded3.0[counter]=encoded33.0[counter*2] : encoded4.0[counter]=encoded44.0[counter*2]
Next counter
'40
temperature= encoded1 ' putting back together as the original temperature
For counter=0 TO 7
temperature.0[counter+8]=encoded2.0[counter+8]
Next counter

temperature.LowBYTE = encoded1
temperature.HighBYTE = encoded2
count_remain = encoded3
count_per_c = encoded4

IF temperature.11 = 1 Then goto Zerotemp
temperature = ((( temperature >> 1) *100)- 25) + (((count_per_c - count_remain) * 100) / count_per_c)
tempF = (((temperature /5) *9 ) + 3200)

lcdout $FE,1, "TempC: ", "+", dec (temperature / 100) , ".", dec2 temperature," ",$DF,"C"
lcdout $FE,$C0, "TempF: ", "+", dec2 (tempF / 100) , ".", dec2 (tempF // 100)," ",$DF,"F"
goto loop
'58
Zerotemp: ' cases when zero celcius and positive Fahrenheit

Dummy = 625 * ~temperature+1' Multiply to load internal registers with 32-bit value
TempC = DIV32 10 ' Use Div32 value to calculate precise deg C
TempF = ~temperature / 16 ' Begin conversion from -C to deg +/-F
IF TempF >=18 THEN ' Check for -degrees F "-18 C = -0.4 F"
TempF = ((((TempF + 50) * 9) /5) -122) ' -C to -F below -17 deg C
lcdout $FE,1, "TempF: " ,"-" , DEC TempF,$DF,"F "
lcdout $FE,$C0, "TempC: ", "-",DEC TempC DIG 4, DEC TempC DIG 3,".",DEC3 TempC, $DF,"C "

ELSE ' Else result = +deg F
TempF = ((((-TempF + 50) * 9) /5) -58)' -C to +F below 32.0 deg F to -17 deg C
lcdout $FE,1, " TempF: " , "+", DEC TempF, $DF,"F "
lcdout $FE,$C0, " TempC: ","-" ,DEC TempC DIG 4,DEC TempC DIG 3,".",DEC3 TempC,$DF,"C "

ENDIF
goto loop

end

skimask
- 29th December 2006, 23:14
yes the positive values works just fine,
I dont why you are doing 2,s compliment twice in the zerotemp.
I saw that program , but there was too many things I did not understand, like this line:
Dummy = 625 * R_Temp ' Multiply to load internal registers with 32-bit value

Why multiply by 625..

end

I'm not doing the 2's compliment twice, the first one is commented out, the 2nd is for the + case, the 3rd is for the - case. It won't get done more than once.

Do you have your PBP manual handy by chance?
I'm still looking at the rest of your code in your last post, I wanna show you some stuff about 32 bit math in the PBP manual that might help.

lerameur
- 29th December 2006, 23:30
ya the manual is right here:

I get this code , still not working , but better:

loop:
'23
waitfor55:
serin portb.2 , n2400 , temp : if temp <> $55 then goto waitfor55

waitforaa:
serin portb.2 , n2400 , temp : if temp <> $aa then goto waitforaa

serin portb.2, n2400, encoded11.HighBYTE : serin portb.2, n2400, encoded11.LowBYTE
serin portb.2, n2400, encoded22.HighBYTE : serin portb.2, n2400, encoded22.LowBYTE
serin portb.2, n2400, encoded33.HighBYTE : serin portb.2, n2400, encoded33.LowBYTE
serin portb.2, n2400, encoded44.HighBYTE : serin portb.2, n2400, encoded44.LowBYTE

For counter=0 TO 7 'decoding
encoded1.0[counter]=encoded11.0[counter*2] : encoded2.0[counter]=encoded22.0[counter*2]
encoded3.0[counter]=encoded33.0[counter*2] : encoded4.0[counter]=encoded44.0[counter*2]
Next counter
'41
temperature= encoded1 ' putting back together as the original temperature
For counter=0 TO 7
temperature.0[counter+8]=encoded2.0[counter+8]
Next counter

temperature.LowBYTE = encoded1
temperature.HighBYTE = encoded2
count_remain = encoded3
count_per_c = encoded4

IF temperature.11 = 1 Then goto Zerotemp
temperature = ((( temperature >> 1) *100)- 25) + (((count_per_c - count_remain) * 100) / count_per_c)
tempF = (((temperature /5) *9 ) + 3200)

lcdout $FE,1, "TempC: ", "+", dec (temperature / 100) , ".", dec2 temperature," ",$DF,"C"
lcdout $FE,$C0, "TempF: ", "+", dec2 (tempF / 100) , ".", dec2 (tempF // 100)," ",$DF,"F"
goto loop

Zerotemp: '------------- cases when zero celcius and positive Fahrenheit
temp1 = temperature
temperature = ( ~ temperature ) + 1 '----- do this later, right before displaying it
'63
tempc =temperature
temperature = ((( temperature ) *100)- 25) + (((count_per_c - count_remain) * 100) / count_per_c)
tempF = ((temperature /5) * 9) + 3200

if tempF <= 0 then goto ZeroF

'lcdout $FE,1, bin temp1 , ".", bin temperature ," ",$DF,"C"
'lcdout $FE,$C0, bin tempc , ".", dec tempc/2 ," ",$DF,"F"

'temperature = ( ~ temperature ) + 1 : tempf = ( ~ tempF ) + 1 ' added this
lcdout $FE,1, "TempC: ", "-", dec (temperature / 100) , ".", dec2 temperature," ",$DF,"C"
lcdout $FE,$C0, "TempF: ", dec (tempF / 100) , ".", dec2 tempF ," ",$DF,"F"
goto loop

ZeroF: '---------------- cases when zero celcius and 0 Fahrenheit
tempF = ((temperature /5) * 9) + 3200

temperature = ( ~ temperature ) + 1 : tempf = ( ~ tempF ) + 1 ' added this
lcdout $FE,1, "TempC: ", "-", dec (temperature / 100) , ".", dec2 temperature," ",$DF,"C"
lcdout $FE,$C0, "TempF: ", "-", dec (tempF / 100) , ".", dec2 tempF ," ",$DF,"F"

goto loop

end

skimask
- 29th December 2006, 23:33
[QUOTE=lerameur;30245]ya the manual is right here:

Page 33-35, 32 bit math, that will explain the code from Rentron.

skimask
- 29th December 2006, 23:36
temperature = ( ~ temperature ) + 1 : tempf = ( ~ tempF ) + 1 ' added this
lcdout $FE,1, "TempC: ", "-", dec (temperature / 100) , ".", dec2 temperature," ",$DF,"C"
lcdout $FE,$C0, "TempF: ", "-", dec (tempF / 100) , ".", dec2 tempF ," ",$DF,"F"

goto loop

end

That 2nd conversion is done twice... once after Zerotemp & once after ZeroF.

lerameur
- 29th December 2006, 23:56
That 2nd conversion is done twice... once after Zerotemp & once after ZeroF.
O yes, I removed it, anyway I cant test that cold yet

skimask
- 30th December 2006, 00:17
O yes, I removed it, anyway I cant test that cold yet

No, but you can simulate it at the transmitter end with a loop instead of reading the temp sensor....duh!!! :)

Just set up the transmitter to send out a slowly changing temperature that goes up the scale, resets to the low end, climbs back up again, whatever works for you.
Or do it at the receiver end, put a couple of buttons in there, one button-temp goes up, another button-temp goes down.

lerameur
- 30th December 2006, 00:40
ok , I get that now,
I want to concentrate on the cold but not that cold part for now.. the sensor is sticking outsid now, its about -11C
I wanted to see what was behing calculated..
The 2's compliment, the binary value gives me a good degree (tempc)
when I put it in the equation it then screws up, I think the 2 byte count_per_c AND count_remain and different since it is in negative mode... hummm
Nothing is siad about this in the specsheet either, and the program on Rentron does not use that part.

here is the code:

Zerotemp: '------------- cases when zero celcius and positive Fahrenheit
temp1 = temperature
temperature = ( ~ temperature ) + 1 '----- do this later, right before displaying it
tempc =temperature
temperature = ((( temperature ) *100)- 25) + (((count_per_c - count_remain) * 100) / count_per_c)
tempF = ((temperature /5) * 9) + 3200
if tempF <= 0 then goto ZeroF
lcdout $FE,1, dec temp1 , ".", dec temperature ," ",$DF,"C"
lcdout $FE,$C0, dec temperature, dec tempc , ".", dec tempc/2 ," ",$DF,"F"
temperature," ",$DF,"C"

goto loop

lerameur
- 30th December 2006, 01:48
putting the 2,s compliment just befire works best:
but the temperature seems to cut in half,, showing -5C when it is -10C

Just getting +655 when I get to zero degrees.


loop:
'23
waitfor55:
serin portb.2 , n2400 , temp : if temp <> $55 then goto waitfor55

waitforaa:
serin portb.2 , n2400 , temp : if temp <> $aa then goto waitforaa

serin portb.2, n2400, encoded11.HighBYTE : serin portb.2, n2400, encoded11.LowBYTE
serin portb.2, n2400, encoded22.HighBYTE : serin portb.2, n2400, encoded22.LowBYTE
serin portb.2, n2400, encoded33.HighBYTE : serin portb.2, n2400, encoded33.LowBYTE
serin portb.2, n2400, encoded44.HighBYTE : serin portb.2, n2400, encoded44.LowBYTE

For counter=0 TO 7 'decoding
encoded1.0[counter]=encoded11.0[counter*2] : encoded2.0[counter]=encoded22.0[counter*2]
encoded3.0[counter]=encoded33.0[counter*2] : encoded4.0[counter]=encoded44.0[counter*2]
Next counter
'41
temperature= encoded1 ' putting back together as the original temperature
For counter=0 TO 7
temperature.0[counter+8]=encoded2.0[counter+8]
Next counter

temperature.LowBYTE = encoded1
temperature.HighBYTE = encoded2
count_remain = encoded3
count_per_c = encoded4

IF temperature.11 = 1 Then goto Zerotemp
temperature = ((( temperature >> 1) *100)- 25) + (((count_per_c - count_remain) * 100) / count_per_c)
tempF = (((temperature /5) *9 ) + 3200)

lcdout $FE,1, "TempC: ", "+", dec (temperature / 100) , ".", dec2 temperature," ",$DF,"C"
lcdout $FE,$C0, "TempF: ", "+", dec2 (tempF / 100) , ".", dec2 (tempF // 100)," ",$DF,"F"
goto loop

Zerotemp: '------------- cases when zero celcius and positive Fahrenheit
temp1 = temperature

temperature = ((( temperature >>1 ) *100)- 25) + (((count_per_c - count_remain) * 100) / count_per_c)


if tempF <= 0 then goto ZeroF

temperature = ( ~ temperature ) + 1 ': tempf = ( ~ tempF ) + 1 ' added this
tempF = 3200 - ((temperature /5) * 9)
lcdout $FE,1, "TempC: ", "-", dec (temperature / 100) , ".", dec2 temperature," ",$DF,"C"
lcdout $FE,$C0, "TempF: ", dec (tempF / 100) , ".", dec2 tempF ," ",$DF,"F"
goto loop

ZeroF: '---------------- cases when zero celcius and 0 Fahrenheit
tempF = 3200 - ((temperature /5) * 9)

lcdout $FE,1, "TempC: ", "-", dec (temperature / 100) , ".", dec2 temperature," ",$DF,"C"
lcdout $FE,$C0, "TempF: ", "-", dec (tempF / 100) , ".", dec2 tempF ," ",$DF,"F"

goto loop

end

skimask
- 30th December 2006, 02:59
putting the 2,s compliment just befire works best:
but the temperature seems to cut in half,, showing -5C when it is -10C

Just getting +655 when I get to zero degrees.

Zerotemp: '------------- cases when zero celcius and positive Fahrenheit
temp1 = temperature
temperature = ((( temperature >>1 ) *100)- 25) + (((count_per_c - count_remain) * 100) / count_per_c)

if tempF <= 0 then goto ZeroF

temperature = ( ~ temperature ) + 1 ': tempf = ( ~ tempF ) + 1 ' added this
tempF = 3200 - ((temperature /5) * 9)

ZeroF: '---------------- cases when zero celcius and 0 Fahrenheit
tempF = 3200 - ((temperature /5) * 9)

goto loop

end

Why are you using:tempF = 3200 - ((temperature /5) * 9)
instead of tempF = ( ( ( temperature / 5 ) * 9 ) + 3200 ) ?

The positive case (the only one that's working) uses the +3200, the negative cases are using the 3200-.....

What's the deal there?

lerameur
- 30th December 2006, 18:03
simple I need to take the difference. I believe pic basic pro can only handle unsigned numbers. So but keeking the original forula we get negative number for zero temperature. So by putting the 3200 in front , we get a positive number and add a minus sign.

for -15 degrees celcius
we have 15*100 =1500 in the euqation
=3200 - (1500/5*9) = 500
= 500/100 ------divide by hundred caus ewe multiplied by a 100 initially
=5
= -5 ----- here we just add the minus

but anyway , remember when i said my decimal values was going reverse. I was thinking and that is similar from doing 2,s compliment . so i decided to do 2,s compliment on everything..

Zerotemp: '------------- cases when zero celcius and positive Fahrenheit
temperature = ( ~ temperature ) + 1
count_per_c = ( ~ count_per_c) + 1
count_remain= ( ~count_remain) + 1
temp1 = temperature

temperature = ((( temperature >>1 ) *100)- 25) + (((count_per_c - count_remain) * 100) / count_per_c)
if tempF <= 0 then goto ZeroF

': tempf = ( ~ tempF ) + 1 ' added this
tempF = (((temperature /5) *9 ) + 3200)
lcdout $FE,1, "TempC: ", "-", dec (temperature / 100) , ".", dec2 temperature," ",$DF,"C"
lcdout $FE,$C0, "TempF: ", dec (tempF / 100) , ".", dec2 tempF ," ",$DF,"F"
goto loop

ZeroF: '---------------- cases when zero celcius and 0 Fahrenheit
tempF = 3200 - ((temperature /5) * 9)

lcdout $FE,1, "TempC: ", "-", dec (temperature / 100) , ".", dec2 temperature," ",$DF,"C"
lcdout $FE,$C0, "TempF: ", "-", dec (tempF / 100) , ".", dec2 tempF ," ",$DF,"F"

goto loop

end

lerameur
- 30th December 2006, 19:14
I thought that would work, but nope

look at his thread, last couple of posts,
seems like I am not the only one having his problem .

skimask
- 30th December 2006, 22:37
simple I need to take the difference. I believe pic basic pro can only handle unsigned numbers. So but keeking the original forula we get negative number for zero temperature. So by putting the 3200 in front , we get a positive number and add a minus sign.

for -15 degrees celcius
we have 15*100 =1500 in the euqation
=3200 - (1500/5*9) = 500
= 500/100 ------divide by hundred caus ewe multiplied by a 100 initially
=5
= -5 ----- here we just add the minus

but anyway , remember when i said my decimal values was going reverse. I was thinking and that is similar from doing 2,s compliment . so i decided to do 2,s compliment on everything..

Zerotemp: '------------- cases when zero celcius and positive Fahrenheit
temperature = ( ~ temperature ) + 1
count_per_c = ( ~ count_per_c) + 1
count_remain= ( ~count_remain) + 1
temp1 = temperature

temperature = ((( temperature >>1 ) *100)- 25) + (((count_per_c - count_remain) * 100) / count_per_c)
if tempF <= 0 then goto ZeroF

': tempf = ( ~ tempF ) + 1 ' added this
tempF = (((temperature /5) *9 ) + 3200)
lcdout $FE,1, "TempC: ", "-", dec (temperature / 100) , ".", dec2 temperature," ",$DF,"C"
lcdout $FE,$C0, "TempF: ", dec (tempF / 100) , ".", dec2 tempF ," ",$DF,"F"
goto loop

ZeroF: '---------------- cases when zero celcius and 0 Fahrenheit
tempF = 3200 - ((temperature /5) * 9)

lcdout $FE,1, "TempC: ", "-", dec (temperature / 100) , ".", dec2 temperature," ",$DF,"C"
lcdout $FE,$C0, "TempF: ", "-", dec (tempF / 100) , ".", dec2 tempF ," ",$DF,"F"

goto loop

end

I'm thinking that the easiest way to solve this whole mess is to add an offset to the original C value.
The 1820 will only handle temps up to +85C and has an operating range of -55 -> +125C. So, that's a total range of 180C. So, add, say 200 to the original Celsius input. You still have 3 cases to deal with (+C/F , -C/+F and -C/-F), but it might be easier to deal with this way... (and it will still work in the confines of a word value, 200 + 125 = 325 , 20000 + 12500 = 32500).

At the receiving end,
If C temp is => 200 (20000) , then subtract 200 (20000) and handle it like normal, which already works fine. +C and +F

If the C temp is => 182.22 (18222) AND < 20000....handle it for -C and +F

If the C temp is < 182.22 (18222).....handle it for -C and -F.

In the last 2 cases when you have a negative temp, I think setting a display flag and converting the temp's to a positive range, then displaying them is the way to go (flip them back over the zero, i.e. -10 = 10 with a display flag), but you're already doing that (even though it isn't working at the moment).

lerameur
- 30th December 2006, 23:31
thanks , I decided to take a short cut, I just realize that the equation they gave in the spec sheet is only good for positive Celsius degrees. I lokked how count_per_C and Count_Remain worked . I will try and come up with a formula for negative values with thse featuer, I will need to invert the Count remain, and flip the last two . .

anyway here is the program that works, but with only 0.5 Degrees off in the negative region.
BUT frpm 0 to -0.5 I stil get +655 C....



loop:
'23
waitfor55:
serin portb.2 , n2400 , temp : if temp <> $55 then goto waitfor55

waitforaa:
serin portb.2 , n2400 , temp : if temp <> $aa then goto waitforaa

serin portb.2, n2400, encoded11.HighBYTE : serin portb.2, n2400, encoded11.LowBYTE
serin portb.2, n2400, encoded22.HighBYTE : serin portb.2, n2400, encoded22.LowBYTE
serin portb.2, n2400, encoded33.HighBYTE : serin portb.2, n2400, encoded33.LowBYTE
serin portb.2, n2400, encoded44.HighBYTE : serin portb.2, n2400, encoded44.LowBYTE

For counter=0 TO 7 'decoding
encoded1.0[counter]=encoded11.0[counter*2] : encoded2.0[counter]=encoded22.0[counter*2]
encoded3.0[counter]=encoded33.0[counter*2] : encoded4.0[counter]=encoded44.0[counter*2]
Next counter
'41
temperature= encoded1 ' putting back together as the original temperature
For counter=0 TO 7
temperature.0[counter+8]=encoded2.0[counter+8]
Next counter

temperature.LowBYTE = encoded1
temperature.HighBYTE = encoded2
count_remain = encoded3
count_per_c = encoded4

IF temperature.11 = 1 Then goto Zerotemp
temperature = ((( temperature >> 1) *100)- 25) + (((count_per_c - count_remain) * 100) / count_per_c)
tempF = (((temperature /5) *9 ) +3200)

lcdout $FE,1, "TempC: ", "+", dec (temperature / 100) , ".", dec2 temperature," ",$DF,"C"
lcdout $FE,$C0, "TempF: ", "+", dec2 (tempF / 100) , ".", dec2 (tempF // 100)," ",$DF,"F"
goto loop

Zerotemp: '------------- cases when zero celcius and positive Fahrenheit

temperature = ( ~ temperature ) + 1

if temperature.0 =0 then
tempbit = 0
else
tempbit = 5 : tempf0 = ((temperature>>1) *10 )+5
endif

tempF = (3200 - (((tempf0*10) /5) *9 ) )
if temperature => 18 then goto ZeroF

lcdout $FE,1, "TempC: ", "-", dec (temperature >>1) , ".", dec tempbit," ",$DF,"C"
lcdout $FE,$C0, "TempF: ", "+", dec2 (tempF / 100) , ".", dec2 (tempF // 100)," ",$DF,"F"
'lcdout $FE,$C0, "T: ", dec tempf0 , ".", dec tempF ," ",$DF,"F"
goto loop

ZeroF: '---------------- cases when zero celcius and 0 Fahrenheit

tempF = ((((tempf0*10) /5) *9 ) -3200 )
lcdout $FE,1, "TempC: ", "-", dec (temperature >>1) , ".", dec tempbit," ",$DF,"C"
lcdout $FE,$C0, "TempF: ", "-", dec2 (tempF / 100) , ".", dec2 (tempF // 100)," ",$DF,"F"
goto loop

end

lerameur
- 30th December 2006, 23:46
ahhhhhhh, look on page 3 of the ds18s20 spec sheet.
0 celcius = 0000 0000 0000 0000
-0.5 celcius = 1111 1111 1111 1111
see, there is no formula for temperature in between these two, the calculation is done only ( by default with COUNT PER COUNT and COUNT REMAIN. which is obviously not good, not sure yet how I am going to fix that, working on it...

skimask
- 31st December 2006, 00:03
ahhhhhhh, look on page 3 of the ds18s20 spec sheet.
0 celcius = 0000 0000 0000 0000
-0.5 celcius = 1111 1111 1111 1111
see, there is no formula for temperature in between these two, the calculation is done only ( by default with COUNT PER COUNT and COUNT REMAIN. which is obviously not good, not sure yet how I am going to fix that, working on it...

Sounds like it's time for one of those cases where you just ignore it!
After all, how much information do you really need between 0 and -.5 C ?

lerameur
- 31st December 2006, 00:09
y amaybe , but the +655 is annoying, I'm almost there,
OK it stick the whole unit outside, Its giving a steady -7 C

Got rid of the +655:
added this:

IF temperature.11 = 1 Then goto Zerotemp
if temperature = 0 then goto Special
.
.
.
Special:
lcdout $FE,1, "TempC: ", dec 0 , ".", dec 0," ",$DF,"C"
lcdout $FE,$C0, "TempF: ", dec 32 , ".", dec 0," ",$DF,"F"
goto loop

lerameur
- 31st December 2006, 01:38
and lastly,

i want to use a 9v battery to power the system. I want to add a led to signal when the battery need to be changed. would you know at what voltage this would be ?

mister_e
- 31st December 2006, 01:43
It will depend wich regulator you use and wich voltage your PIC run.

For battery operated device i will suggest a LDO regulator instead of those grandpa 7805.

Archangel
- 31st December 2006, 01:49
and lastly,

i want to use a 9v battery to power the system. I want to add a led to signal when the battery need to be changed. would you know at what voltage this would be ?
Watch those sales you can get a solar yard light for < $8.00 US complete with rechargeable batteries you would have solar panel, batteries, housing and an LED to flash!, you would have to settle for 3 volts though.

skimask
- 31st December 2006, 01:58
and lastly,

i want to use a 9v battery to power the system. I want to add a led to signal when the battery need to be changed. would you know at what voltage this would be ?

For one thing, I don't know what your system is made of (I know bits and pieces, that's it, not the whole thing). And another thing, a 9v battery would be dead in a short matter of days running this system, especially if you're using a linear regulator (7805 type), even if you set it up to spend most of it's time sleeping and only waking up like once a minute or so.

Better idea would be to go with a 4 cell (AAA or AA, doesn't matter) NiMH pack and skip the regulators altogether, then charge it up for about 12 hours using a 9v wall wart and an inline 200-ish ohm series resistor (less resistor = quicker charge at the expense of battery life). 4 2000mAh NiMH batteries would last a LOT longer than a 9v battery.

But if you insist on a 9v battery, I'd hook it up to an unused A/D input thru a voltage divider consisting of 2 equal resistors. Get the A/D input working and displaying correctly, then turn on the 'change battery' light at about 6.5v. Anything below that and the regulator won't regulate (if you're using a 7805 type).

lerameur
- 31st December 2006, 02:27
ok so i guess I will chucking those LM7805 out of th house...
I have four 2300 nimh AA for my digital camera, guess I could use those for now, not need for voltage regulator right, just want to double check .
but with this setup , how would I have a regulated voltage to compare the batteries voltage, , How would I implement my blinking led for low voltage ?

skimask
- 31st December 2006, 03:14
ok so i guess I will chucking those LM7805 out of th house...
I have four 2300 nimh AA for my digital camera, guess I could use those for now, not need for voltage regulator right, just want to double check .
but with this setup , how would I have a regulated voltage to compare the batteries voltage, , How would I implement my blinking led for low voltage ?

What are the implications is the unit's power runs out? (might help to figure that bit out if I knew how badly the unit had to stay powered up).


How about this? Use a 2.5v reference chip from Microchip, MCP1525. Use that as Vref+ for an A/D input on the PIC. Take your battery pack, put a v-divider on it, say 2:1 ratio, 10K & 10K, or whatever, pluck the signal off the middle of that, read that to an A/D channel, and presto...instant voltage reading...with some math of course.

Ground on Vref-, 2.5v (from MCP1525) on Vref+.
Batt+ to one side of 40K resistor, Batt- to one side of 10K resistor. Other 2 ends of resistor connected together and fed to A/D input (say AN0 for example).
Do a read on AN0 A/D input. I forget what PIC you're using, but say it has a 10 bit A/D converter. That means that your 10 bit A/D converter would have a resolution (based on the 2.5v Vref+) of 2.44xxx mV. Since the voltage going into the converter is divided by 2, the real resolution of the total voltage across the battery is 4.8828125mV.
If you're project doesn't drain much current, you could probably run it down to about 3.6v (.9v/cell). So, while reading the A/D, your reading is going down. When it hits 737 (737 x .0048828125 = 3.598v), turn on the low battery light. Actually, you'll probably want the light on sooner to give yourself some time to get them charged up. And the MCP1525 comes in TO-92 & SOT-23 packages. Easy to use.

lerameur
- 31st December 2006, 03:21
my father cuts meat and has a cold room in the garage, This unit is wireless receiver that will give him the temperature. It is not crucial if there is a downtime to charge the battery, (or a downtime of a few hours if the compressot breaks down) but at least a warning that they are running low.

skimask
- 31st December 2006, 03:28
my father cuts meat and has a cold room in the garage, This unit is wireless receiver that will give him the temperature. It is not crucial if there is a downtime to charge the battery, (or a downtime of a few hours if the compressot breaks down) but at least a warning that they are running low.

The transmitter is in the room and it's wireless/battery powered? And the receiver is elsewhere, plugged into the wall or something?

Ya know for that matter, you could (and probably are but I'm not sure), transmit the transmitter's battery voltage along with temperature data to the receiver.

lerameur
- 31st December 2006, 03:32
nope, the transmitter is in the garage, pluged into the wall, there is a 40 feet line runnin gfrom the sending module to the sensor, becasue the sensor is inside the fridge. This part is done, I installed the module up high inthe garage with the antenna sticking out, it is a straight line to the house. The receiving module is wireless, so he cantake it in his room or the kitchen etc..

skimask
- 31st December 2006, 03:36
nope, the transmitter is in the garage, pluged into the wall, there is a 40 feet line runnin gfrom the sending module to the sensor, becasue the sensor is inside the fridge. This part is done, I installed the module up high inthe garage with the antenna sticking out, it is a straight line to the house. The receiving module is wireless, so he cantake it in his room or the kitchen etc..



Ok, TX, powered, garage....

RX - portable, battery powered. Couple of notes I thought of. If the receiver doesn't get a good update for a minute or something, a light/alarm or something goes off as an indication to check on the transmitter (power went off or the transmitter got kicked over by the cat or something out there).

Have you already tried the TX module with this 40ft of wire? Does it work?

lerameur
- 31st December 2006, 03:39
yes the TX module is fully completed , I was doing my earlier test with it.
well also, i wanted to add a led for the battery alarm. A led for when the temperature goes over 50 F, and a piezo buzzer that gos off for 10 sec if the temperature goes over 50 F.

skimask
- 31st December 2006, 08:32
yes the TX module is fully completed , I was doing my earlier test with it.
well also, i wanted to add a led for the battery alarm. A led for when the temperature goes over 50 F, and a piezo buzzer that gos off for 10 sec if the temperature goes over 50 F.

So what's the next step?

lerameur
- 31st December 2006, 13:07
I am using a pic16F88 and I amnot sure whcih pins to use. Right now I am using pins 1, 2, 17, 18 for my lcd out and also pin 6,7 for control. Pin 5 and 14 for powering. Pin 8 for input.
If I use the Vref, then i need to move my lcd out pins to pin 10 through 13 ( I wanted to us these for led out, piezo and other outputs i needed. I never had luck outputting on port A. Shouln't be hard to get it going.
Also I dont have any MCP1525, I only have 7805 chips maybe use this chip for now and replace it when I get another ?...
and use a voltage divider on the 7805 to obtain 2.5 v ?
I assume the MCP1525 is an LDO chip ??

also instead of using 40k and 10 K resistors, can I use 400k and 100K ? would that take up even less power ?

lerameur
- 31st December 2006, 20:27
hi , maybe i woul dneed expert advise here on wiring and soldering. I think I did an ok job, but when i move my wires a few times after soldering, they break, I use the same wire that i use on the breadboard (picture you seen )
k

skimask
- 1st January 2007, 09:23
I am using a pic16F88 and I amnot sure whcih pins to use. Right now I am using pins 1, 2, 17, 18 for my lcd out and also pin 6,7 for control. Pin 5 and 14 for powering. Pin 8 for input.
If I use the Vref, then i need to move my lcd out pins to pin 10 through 13 ( I wanted to us these for led out, piezo and other outputs i needed. I never had luck outputting on port A. Shouln't be hard to get it going.
Also I dont have any MCP1525, I only have 7805 chips maybe use this chip for now and replace it when I get another ?...
and use a voltage divider on the 7805 to obtain 2.5 v ?
I assume the MCP1525 is an LDO chip ??

also instead of using 40k and 10 K resistors, can I use 400k and 100K ? would that take up even less power ?

Well, if you can't change the Vref pins around, then maybe use 2 A/D converters and compare your fixed reference against the total applied? In other words, if you're battery ever got down to 2.5v, then the A/D input would be at maximum. Just takes a bit of math I supose...

And since you don't have any MCP1525 or anything like it, I know one thing you do have that does have a fixed reference...

Or do you? :)
I'll give you a little bit to think about it, then I'll give you the answer.

And also since you don't have a fixed voltage (or do you? :) )...you won't need to worry about the resistors for now.

lerameur
- 1st January 2007, 15:39
the only fix voltage I have now is my Lm7805 at 5v.

and also, what is the lowest voltage for 4 Nmhi batteries, (when needed to be changed)

well I removed the Lm7805, , i dont have any fox voltage reference. also, leaving the LM7805 there, i could not get enough voltage for the unit to operate

skimask
- 1st January 2007, 21:58
the only fix voltage I have now is my Lm7805 at 5v.

and also, what is the lowest voltage for 4 Nmhi batteries, (when needed to be changed)

well I removed the Lm7805, , i dont have any fox voltage reference. also, leaving the LM7805 there, i could not get enough voltage for the unit to operate

Read the datasheets for the 7805 and you'll find out why you can't get enough voltage from them, they need a couple of volts of overhead to operate correctly.

Lowest volts for NiMH batts - really depends on the current draw, the higher the draw, the higher the end voltage. I suspect for your application, you might want to charge them up when they hit 1v/cell (4v total). That will give you some time to get to it. I wouldn't let them get much below .8v/cell, but then they're on their way out anyways. As far as charging, take them up to about 1.4v/cell depending on the charge rate, faster charge, higher voltage (up to a point of course), slower charge, lower voltage. Overall, 1.4v is a good round number.

More on the easy voltage reference later. Here's a bit of a teaser for you: take a diode, any old diode, a resistor and a 9v battery. Hook it up as follows, +9v to resistor, resistor to one side of diode, other side (banded side) of diode to -9v. Read the voltage across the diode, just the diode and only the diode. Now change the value of the resistor, read the voltage across the diode again, change the resistor again, read the diode again, swap the 9v battery for the 4cell NiMH pack, read the diode again. Let me know your results.

lerameur
- 1st January 2007, 22:19
yes actually, i went and read that , its like a diode, loosing 0.7 volt, so you need a bit more to compensate..
i have been working on the a/d conversion, again this is my first time, I am reading section 12 of he pic16f88 datasheet.

i wrote this program , bit it do not display the right inotmation:


'RECEIVE PIC
INCLUDE "modedefs.bas"
DEFINE OSC 20 'use external 20mhz crystal
CMCON = 7
ANSEL = %00001100 'Put port 2 and 3 analog and otehr digital
ADCON1 = %11000001 ' Set PORTA analog and RIGHT justify result
ADCON0 = %00010001 ' Configure and turn on A/D Module

DEFINE LCD_DREG PORTB ' Set LCD Data port
DEFINE LCD_DBIT 4 ' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
DEFINE LCD_EREG PORTB ' Set LCD Enable port
DEFINE LCD_EBIT 0 ' Set LCD Enable bit
DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
DEFINE LCD_LINES 2 ' Set number of lines on LCD
DEFINE LCD_COMMANDUS 2500
DEFINE LCD_DATAUS 250
DEFINE CHAR_PACING 2000
pause 1000

' Define ADCIN parameters
Define ADC_BITS 10 ' Set number of bits in result
Define ADC_CLOCK 3 ' Set clock source (3=rc)
Define ADC_SAMPLEUS 50 ' Set sampling time in uS

input1 var word : input2 var word

TRISA = %11111111 ' Set PORTA to all input

Pause 500

loop: ADCIN portA.2, input1
ADCIN portA.3, input2

Lcdout $fe, 1 ' Clear LCD
Lcdout "Value1: ", DEC input1 ' Display the decimal value
lcdout $FE,$C0, "Value2: ", dec input2
Pause 200

Goto loop
End

lerameur
- 1st January 2007, 22:23
More on the easy voltage reference later. Here's a bit of a teaser for you: take a diode, any old diode, a resistor and a 9v battery. Hook it up as follows, +9v to resistor, resistor to one side of diode, other side (banded side) of diode to -9v. Read the voltage across the diode, just the diode and only the diode. Now change the value of the resistor, read the voltage across the diode again, change the resistor again, read the diode again, swap the 9v battery for the 4cell NiMH pack, read the diode again. Let me know your results.[/QUOTE]

I will do this test a little bit later, i will give you the results.

skimask
- 1st January 2007, 22:53
yes actually, i went and read that , its like a diode, loosing 0.7 volt, so you need a bit more to compensate..
i have been working on the a/d conversion, again this is my first time, I am reading section 12 of he pic16f88 datasheet.

i wrote this program , bit it do not display the right inotmation:


'RECEIVE PIC
INCLUDE "modedefs.bas"
DEFINE OSC 20 'use external 20mhz crystal
CMCON = 7
ANSEL = %00001100 'Put port 2 and 3 analog and otehr digital
ADCON1 = %11000001 ' Set PORTA analog and RIGHT justify result
ADCON0 = %00010001 ' Configure and turn on A/D Module

DEFINE LCD_DREG PORTB ' Set LCD Data port
DEFINE LCD_DBIT 4 ' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
DEFINE LCD_EREG PORTB ' Set LCD Enable port
DEFINE LCD_EBIT 0 ' Set LCD Enable bit
DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
DEFINE LCD_LINES 2 ' Set number of lines on LCD
DEFINE LCD_COMMANDUS 2500
DEFINE LCD_DATAUS 250
DEFINE CHAR_PACING 2000
pause 1000

' Define ADCIN parameters
Define ADC_BITS 10 ' Set number of bits in result
Define ADC_CLOCK 3 ' Set clock source (3=rc)
Define ADC_SAMPLEUS 50 ' Set sampling time in uS

input1 var word : input2 var word

TRISA = %11111111 ' Set PORTA to all input

Pause 500

loop: ADCIN portA.2, input1
ADCIN portA.3, input2

Lcdout $fe, 1 ' Clear LCD
Lcdout "Value1: ", DEC input1 ' Display the decimal value
lcdout $FE,$C0, "Value2: ", dec input2
Pause 200

Goto loop
End

What did it display? How are you hooked up?

The thing I had in mind is keeping Vref+ and Vref- on Vdd and Vss (battery power). One A/D input is connected to the diode, .7v, which should always stay the same (give or take a bit depending on temperature). The output number from the A/D will be a ratio of that diode (.7v) to the battery voltage., the lower the number, the higher the battery voltage.

For example, if the battery voltage was actually .7v (just for arguments sake, I know it would never be that low), and the diode voltage was .7v, the A/D output would be 1023.
If the battery voltage was 4.8v and the diode was .7, .7 divided by 4.8 multiplied by 1024 (full scale A/D reading) would be 149 (149.3). So, 149 would be full charge.
Taking that same train of thought, if the battery voltage was 3.6v (.9v/cell, battery dead), .7 divided by 3.6 multplied 1024 would be 199 (199.1) which would mean dead battery.

Are ya following me here?

skimask
- 1st January 2007, 22:54
More on the easy voltage reference later. Here's a bit of a teaser for you: take a diode, any old diode, a resistor and a 9v battery. Hook it up as follows, +9v to resistor, resistor to one side of diode, other side (banded side) of diode to -9v. Read the voltage across the diode, just the diode and only the diode. Now change the value of the resistor, read the voltage across the diode again, change the resistor again, read the diode again, swap the 9v battery for the 4cell NiMH pack, read the diode again. Let me know your results.

I will do this test a little bit later, i will give you the results.[/QUOTE]



Ok, it looks like you're ahead of me a bit :)

lerameur
- 2nd January 2007, 02:15
well the program i wrote was initially suppose to be a simple a/d program. I never did A/D, so i wanted to write a program with just that in it, I want to read a sensor (light to voltage ) then output the value to the lcd screen, Then I will integrate this concept into my project. I am using the pic16F88,with analog input on portA.2 and A.3.
My lcd shows about 100 at start up and goes up gradually to 980 in about a minute. obviously something is wrong
I want to understand the A/D by that knowing how to program , before going further.
k

lerameur
- 2nd January 2007, 03:01
another thing, I get (sometimes) wired values on the receiver. I read the temperature good, but once in a whjile, I get 2 temperature reading on one line, other ime i get +200, etc...
does this have to do with the system being wireless, or the fact that my encoding technique is weak and prone to mistakes??

lerameur
- 2nd January 2007, 20:14
HI I did the test , as I suspected, I get 0.7v all the time. So I caould put a few in a row to get a higher voltage difference and use that as a reference voltage.

skimask
- 2nd January 2007, 20:52
HI I did the test , as I suspected, I get 0.7v all the time. So I caould put a few in a row to get a higher voltage difference and use that as a reference voltage.

You could, but those diodes will vary in voltage with time, temperature, current flow, moon phases, etc, not by much, but they will change over time and temperature at least, and in series, they'd do nothing but get worse. Therefore, you're battery voltage reading will change accordingly, and probably screw you up in the long run. And you have to have X amount of current to even get the diodes to conduct. You might end up using more power than you would really want to just to get a reading.

Have you been able to get the A/D working yet?
Like I said, spare pin to a resistor (probably 1K or so), other side of resistor to non-banded side of diode, banded side of diode to ground. Tap the non-banded side to your A/D port and take some readings with the battery hooked up as normal and A/D converter set up with Vref+ at Vdd and Vref- at Vss. If you're using the 10bit A/D, you should get a reading arorund 150-ish. Then as the battery wears down, the reading will go up. A reading of roughly 200 will mean a dead battery.

And, you can save the power to read the battery by change that 'spare pin' mentioned above to an input and shutting off the A/D module.

lerameur
- 2nd January 2007, 21:43
ok , I have a problem now:

i wrote this program below, I configured so it read porta.0, but I get 0 output when I ground it and oscillation between 890 and to 900 when i put it to Vdd.
if I leave the program as is, and just put the input wire to portA.1 theni get 0 output when i groud the wire, and 1023 when I put it to Vdd.
Why am I getting a better result to a non configured port 6, at least i am ot calling this pin ??
my ADCON0 = %10000001 i believe this is for An0 to input
I am also trying to get two input for A/d , is that possible ?

'RECEIVE PIC
INCLUDE "modedefs.bas"


DEFINE OSC 20 'use external 20mhz crystal
DEFINE LCD_DREG PORTB ' Set LCD Data port
DEFINE LCD_DBIT 4 ' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
DEFINE LCD_EREG PORTB ' Set LCD Enable port
DEFINE LCD_EBIT 0 ' Set LCD Enable bit
DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
DEFINE LCD_LINES 2 ' Set number of lines on LCD
DEFINE LCD_COMMANDUS 2500
'DEFINE LCD_DATAUS 250
'DEFINE CHAR_PACING 2000
pause 1000

' Define ADCIN parameters
Define ADC_BITS 10 ' Set number of bits in result
Define ADC_CLOCK 3 ' Set clock source (3=rc)
Define ADC_SAMPLEUS 50 ' Set sampling time in uS

input1 var word : input2 var word

TRISA = %11111111 ' Set PORTA to all input
CMCON = 7
ANSEL = %00001100
ADCON1 = %10000010
ADCON0 = %10000001

Pause 500

loop: ADCIN porta.0, input1

Lcdout $fe, 1 ' Clear LCD
Lcdout "Value1: ", DEC input1 ' Display the decimal value
lcdout $FE,$C0, "Value2: ", dec input2
Pause 200

Goto loop
End


Also, what do you mean by : Spare pin to resistor ?

lerameur
- 3rd January 2007, 13:27
trying to get multiple input,but getting wrong values


loop:
ADCON0 = %10000001 ' Configure and turn on A/D Module
ADCIN porta.0, input1
pause 50

ADCON0 = %10001001 ' Configure and turn on A/D Module
ADCIN porta.1, input2
pause 50

Lcdout $fe, 1 ' Clear LCD
Lcdout "Value1: ", DEC input1 ' Display the decimal value
lcdout $FE,$C0, "Value2: ", dec input2
Pause 400

Goto loop

skimask
- 3rd January 2007, 17:00
ok , I have a problem now:

i wrote this program below, I configured so it read porta.0, but I get 0 output when I ground it and oscillation between 890 and to 900 when i put it to Vdd.
if I leave the program as is, and just put the input wire to portA.1 theni get 0 output when i groud the wire, and 1023 when I put it to Vdd.
Why am I getting a better result to a non configured port 6, at least i am ot calling this pin ??
my ADCON0 = %10000001 i believe this is for An0 to input
I am also trying to get two input for A/d , is that possible ?

'RECEIVE PIC
INCLUDE "modedefs.bas"


DEFINE OSC 20 'use external 20mhz crystal
DEFINE LCD_DREG PORTB ' Set LCD Data port
DEFINE LCD_DBIT 4 ' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
DEFINE LCD_EREG PORTB ' Set LCD Enable port
DEFINE LCD_EBIT 0 ' Set LCD Enable bit
DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
DEFINE LCD_LINES 2 ' Set number of lines on LCD
DEFINE LCD_COMMANDUS 2500
'DEFINE LCD_DATAUS 250
'DEFINE CHAR_PACING 2000
pause 1000

' Define ADCIN parameters
Define ADC_BITS 10 ' Set number of bits in result
Define ADC_CLOCK 3 ' Set clock source (3=rc)
Define ADC_SAMPLEUS 50 ' Set sampling time in uS

input1 var word : input2 var word

TRISA = %11111111 ' Set PORTA to all input
CMCON = 7
ANSEL = %00001100
ADCON1 = %10000010
ADCON0 = %10000001

Pause 500

loop: ADCIN porta.0, input1

Lcdout $fe, 1 ' Clear LCD
Lcdout "Value1: ", DEC input1 ' Display the decimal value
lcdout $FE,$C0, "Value2: ", dec input2
Pause 200

Goto loop
End


Also, what do you mean by : Spare pin to resistor ?



Oscillation - I get that too on most everything I do on the A/D inputs (I don't know if it's a function of crappy circuit boards or bad design, doesn't matter to me anyways). You're probably going to want to do some sort of software averaging and/or put a capacitor across the input line to smooth it out a bit.

Spare pin on resistor - instead of putting the diode direct to battery power, thru a resistor to ground, you can intermittently power that diode thru a spare PIC output pin and save that power. Every little bit helps ya know.

lerameur
- 3rd January 2007, 19:04
ok, but what about this loop here, can i do that, having multiple a/d conversion on one chip ?

loop:
ADCON0 = %10000001 ' Configure and turn on A/D Module
ADCIN porta.0, input1
pause 50

ADCON0 = %10001001 ' Configure and turn on A/D Module
ADCIN porta.1, input2
pause 50

From the definition of ADCON0, I can only choose one pin for A/D conversion. Maybe thats why it get mixed up .

skimask
- 3rd January 2007, 21:36
ok, but what about this loop here, can i do that, having multiple a/d conversion on one chip ?

loop:
ADCON0 = %10000001 ' Configure and turn on A/D Module
ADCIN porta.0, input1
pause 50

ADCON0 = %10001001 ' Configure and turn on A/D Module
ADCIN porta.1, input2
pause 50

From the definition of ADCON0, I can only choose one pin for A/D conversion. Maybe thats why it get mixed up .

You can do A/D on more than one pin, just not at the same time. I'm not sure why it didn't work for you in the one post. Maybe not waiting long enough between conversions and/or long enough between switching A/D channel assignment. I think you have to wait awhile, not only after the last conversion, but after you switch the channel, which ADCIN does for you. So, again, not sure. I'll think on it. Until then, double check your configuration, TRIS assignments, ADCON setup, etc.etc.
And you shouldn't have to use more than one channel for your project, unless I missed something there too...

lerameur
- 4th January 2007, 01:39
HI,
I dont have to use more then one for this project, But I had this problem before and did not persue into it, so I asked the question just on the way. I read on a site, just like you said, adding a capacitor to the output of the sensor or battery will help. The thing I dont know why it works, I tried these two program they both works, just dont know why the program with just one ADCON0 works

Two Adcon
ADCON0 = %10000001 ' Configure and turn on A/D Module
ADCIN porta.0, input1
pause 50

ADCON0 = %10001001 ' Configure and turn on A/D Module
ADCIN porta.1, input2
pause 50


One ADCON0
ADCON0 = %10000001 ' Configure and turn on A/D Module
ADCIN porta.0, input1
ADCIN porta.1, input2
pause 50

See they both work, but I did not configure port A.1.. why ?

skimask
- 4th January 2007, 02:16
HI,
I dont have to use more then one for this project, But I had this problem before and did not persue into it, so I asked the question just on the way. I read on a site, just like you said, adding a capacitor to the output of the sensor or battery will help. The thing I dont know why it works, I tried these two program they both works, just dont know why the program with just one ADCON0 works

Two Adcon
ADCON0 = %10000001 ' Configure and turn on A/D Module
ADCIN porta.0, input1
pause 50

ADCON0 = %10001001 ' Configure and turn on A/D Module
ADCIN porta.1, input2
pause 50


One ADCON0
ADCON0 = %10000001 ' Configure and turn on A/D Module
ADCIN porta.0, input1
ADCIN porta.1, input2
pause 50

See they both work, but I did not configure port A.1.. why ?

You're using the ADCIN command. Ya think maybe PBP sets it up for ya?
I know the PBP manual doesn't explicitly say it that it sets it up for you, but it does say that ADCIN reads the 'channel' and also says all you have to do is set the required pins to inputs, it doesn't really say to select the channel you want to sample... I suppose the manual could be a little more informative in this respect.
I just looked at the ADC section of the 'F88. It's a bit different than some of the other PICs. Not only do you have to TRIS the pins you want to inputs, but you also have to enable the A/D in the ANSEL register. I don't know if PBP does this for you or not.
You can easily check for that in your .lst file after compiling the program. Just put a comment around the line you're wanting to check and search for that comment in the .lst file. Should make it a bit easier for ya...

lerameur
- 4th January 2007, 17:18
hi,

Ok I got the A/D working now.

I bought another RF module kit from this web site:
http://www.robotshop.ca/home/products/robot-parts/communication-control/rc-communications/on-shine-high-sensitivity-tx-rx.html
( actuallyI just had to drive there).
I use the exact program and configuraiton and I am getting contact output on the lcd :
TempC : 0
TempF: 32

here is what I see on the scope:
http://www3.sympatico.ca/lerameur/

skimask
- 4th January 2007, 17:26
hi,

Ok I got the A/D working now.

I bought another RF module kit from this web site:
http://www.robotshop.ca/home/products/robot-parts/communication-control/rc-communications/on-shine-high-sensitivity-tx-rx.html
( actuallyI just had to drive there).
I use the exact program and configuraiton and I am getting no ouput
here is what I see on the scope:
http://www3.sympatico.ca/lerameur/

A/D is working as expected? Values are what you need and all that?

RF Modules - sounds like you should take them back and get another pair of the same thing you've already got.

lerameur
- 4th January 2007, 17:40
I bought three pair of them , They all act the same...
it looks ok from the scope doesn't it ??

A/D is working as expected? Values are what you need and all that?
Yes :)

skimask
- 4th January 2007, 17:49
I bought three pair of them , They all act the same...
it looks ok from the scope doesn't it ??

A/D is working as expected? Values are what you need and all that?
Yes :)

Put the old ones back in and snap a pic of those, put the 2 pic's up side by side. Maybe one is inverted from the other or something.

lerameur
- 4th January 2007, 17:51
I did that they are almost the same on the scope.

skimask
- 4th January 2007, 17:57
I did that they are almost the same on the scope.

Almost apparently isn't close enough.
Fatten up the traces a bit if you can and repost the pics including the original RF module sets.
Also, you might want to try speeding up the TX rate, maybe a couple more sync bytes ($55), maybe less, who knows.
That's the problem with getting something to work with one thing, and then using another, you gotta redo practically everything.

lerameur
- 4th January 2007, 17:59
Ok I posted a picture of the working module, I bit different.
same link

skimask
- 4th January 2007, 18:05
Ok I posted a picture of the working module, I bit different.
same link

2nd picture, bottom trace is old 'working' receiver output?

If so, do you see that big gap after every transmission? That's the data slicer slowly losing it's mind. After a couple of ms, it starts going nuts, which is why you have to train the rx.

If I had to guess, I would say try using n2400 (or t2400, I don't remember which) instead of what you're using now, on both TX and RX. Then try t2400 on the TX and n2400 on the RX. It (the new TX/RX pair) looks like it's inverted or something.
And again, try bumping up the speed. On the new RX 'scope picture, see how that gap isn't there? That thing loses it's mind fast.

lerameur
- 4th January 2007, 18:43
Ok i tried faster speed, and same thing, I changed to t2400 here si the result, it looks good, but the output gives me
tempc: -6396C
tempf: -60 F

3rd pic:
http://www3.sympatico.ca/lerameur/

It also take like 15 seconds before anything appears on the lcd.
whereas before a few seconds

Then try t2400 on the TX and n2400 on the RX.
output is now:
tempc: +148C
tempf: +99.75 F
and it does not seem to be moving from that

i did all the test with all three set of TX and RX modules, same results with each

these modules has to be working, the only difference is the white space is a bit smaller.. unless it means the chip is useless. Should i order other fron Rentron ?

skimask
- 4th January 2007, 20:06
Ok i tried faster speed, and same thing, I changed to t2400 here si the result, it looks good, but the output gives me
tempc: -6396C
tempf: -60 F

3rd pic:
http://www3.sympatico.ca/lerameur/

It also take like 15 seconds before anything appears on the lcd.
whereas before a few seconds

Then try t2400 on the TX and n2400 on the RX.
output is now:
tempc: +148C
tempf: +99.75 F
and it does not seem to be moving from that

i did all the test with all three set of TX and RX modules, same results with each

these modules has to be working, the only difference is the white space is a bit smaller.. unless it means the chip is useless. Should i order other fron Rentron ?


How about n2400 on TX and t2400 on RX?
Try 1200 or 300 yet?

Order from Rentron - I would stick with what works, or at least what has worked in the past rather than trying something new.

lerameur
- 4th January 2007, 20:47
SLAP me with a dead fish in the face....
I have crystals in drawers, Ithoight they where 20Mhz, they where 2.0 Mhz...
it works now...

skimask
- 4th January 2007, 20:55
SLAP me with a dead fish in the face....
I have crystals in drawers, Ithoight they where 20Mhz, they where 2.0 Mhz...
it works now...

Go figure :) And that would explain why the traces were so different in width at the same time scale on the 'scope.

lerameur
- 4th January 2007, 21:59
I am attempting to use the encoder I received a while ago to compare with my software encoding technique. see new thread

k

lerameur
- 5th January 2007, 01:49
I am going to start my other project which needs two HPWM port, so I choose the pic16F876 for now, I cannot make it oscillate, you have idea, is there a software (programming thing ) that is needed ? I read the spec sheet i didnot see anything about it

skimask
- 5th January 2007, 05:13
I am going to start my other project which needs two HPWM port, so I choose the pic16F876 for now, I cannot make it oscillate, you have idea, is there a software (programming thing ) that is needed ? I read the spec sheet i didnot see anything about it

Have you got PGM (RB4? RB5?) pulled up or down, whichever it is?
The '876 is practically the same as the '877, I don't remember any tricks for it, just make sure you xtal config bits are set right (should be HS I would think).

skimask
- 5th January 2007, 05:15
I am attempting to use the encoder I received a while ago to compare with my software encoding technique. see new thread

k

I saw that. Some (most?) of them won't do data. They'll do a single switch position on the TX end, to a single relay/light/whatever on the RX end.

That's why I pushed the manchester encoding so hard a couple of weeks ago. You know what you're doing now (I think anyways, you got the temperature to transmit without it didn't you?) and don't need those encoders.

skimask
- 5th January 2007, 05:16
SLAP me with a dead fish in the face....
I have crystals in drawers, Ithoight they where 20Mhz, they where 2.0 Mhz...
it works now...

Speaking of slapping yourself in the dead face with a fish :)
Just now I couldn't get my PIC to run...I had the oscillator in there backwards...3 hours down the tubes...datasheets show it upside-down :)

lerameur
- 5th January 2007, 18:15
hehehe, yes well that 2.0 Mhz crystals cost some hours too Grrrrr

Manchester encoding is working good. I also saw on previous post that other where trying to remove errors in the transmition so the wireless could be almost full proof. I saw the shiftin function was used in one case.

When I ordered these encoders, , I did not know there was different types of encoding (serial , parallel). Maybe one day I will find use for them.
k

lerameur
- 5th January 2007, 18:46
xtal config bits ?

isn't it this line I had in my code:
DEFINE OSC 20 'use external 20mhz crystal

Do I need to add this line too ?
@ DEVICE PIC16F877,HS_OSC ' Use PIC16F877 and HS Oscilator

Why didn,t i need to add this when using the pic16F88??

skimask
- 5th January 2007, 18:54
xtal config bits ?

isn't it this line I had in my code:
DEFINE OSC 20 'use external 20mhz crystal

Nope, that DEFINE just tells PBP what sort of timing to use when it compiles. For example, if you defined 4mhz, a pause 1000 would have x number of delay statements (or loops or whatever). If you define 20mhz, PBP will automatically change that X number to 5 times the number of delay statements (or loops or whatever). The real explanation is towards the end of the PBP manual.

For checking your xtal config bits, you'll either want to check you programmer's config bit settings (which you'd probably do right before you hit the program button), or start adding config lines in your code.
For example, here's a bit (ok, actually it's all of them plus explanations below it of what each register does and how to use it) of config's for one of my projects using a PIC18F4620:

@ __CONFIG _CONFIG1H, _OSC_HSPLL_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
@ __CONFIG _CONFIG2L, _BOREN_OFF_2L & _PWRT_ON_2L
@ __CONFIG _CONFIG2H, _WDT_OFF_2H & _WDTPS_32768_2H
@ __CONFIG _CONFIG3H, _LPT1OSC_OFF_3H & _MCLRE_ON_3H & _PBADEN_OFF_3H & _CCP2MX_PORTC_3H
@ __CONFIG _CONFIG4L, _XINST_OFF_4L & _STVREN_OFF_4L & _LVP_OFF_4L & _DEBUG_OFF_4L

@ __CONFIG _CONFIG5L, _CP0_OFF_5L & _CP1_OFF_5L & _CP2_OFF_5L & _CP3_OFF_5L
@ __CONFIG _CONFIG5H, _CPB_OFF_5H & _CPD_OFF_5H
@ __CONFIG _CONFIG6L, _WRT0_OFF_6L & _WRT1_OFF_6L & _WRT2_OFF_6L & _WRT3_OFF_6L
@ __CONFIG _CONFIG6H, _WRTC_OFF_6H & _WRTB_OFF_6H & _WRTD_OFF_6H
@ __CONFIG _CONFIG7L, _EBTR0_OFF_7L & _EBTR1_OFF_7L & _EBTR2_OFF_7L & _EBTR3_OFF_7L
@ __CONFIG _CONFIG7H, _EBTRB_OFF_7H

;----- CONFIG1H Options --------------------------------------------------
;_OSC_LP_1H,_OSC_XT_1H,_OSC_HS_1H,_OSC_RC_1H,_OSC_ EC_1H,_OSC_ECIO6_1H,_OSC_HSPLL_1H,_OSC_RCIO6_1H,_O SC_INTIO67_1H,_OSC_INTIO7_1H,_FCMEN_OFF_1H,_FCMEN_ ON_1H,_IESO_OFF_1H,_IESO_ON_1H

;----- CONFIG2L Options --------------------------------------------------
;_PWRT_ON_2L, _PWRT_OFF_2L, _BOREN_OFF_2L, _BOREN_ON_2L, _BOREN_NOSLP_2L, _BOREN_SBORDIS_2L, _BORV_0_2L, _BORV_1_2L, _BORV_2_2L, _BORV_3_2L

;----- CONFIG2H Options --------------------------------------------------
;_WDT_OFF_2H, _WDT_ON_2H, _WDTPS_ 1 / 2 / 4 / 8 / 16 / 32 / 64 / 128 / 256 / 512 / 1024 / 2048 / 4096 / 8192 / 16384 / 32768 _2H

;----- CONFIG3H Options --------------------------------------------------
;_MCLRE_OFF_3H, _MCLRE_ON_3H, _LPT1OSC_OFF_3H, _LPT1OSC_ON_3H, _PBADEN_OFF_3H, _PBADEN_ON_3H, _CCP2MX_PORTBE_3H, _CCP2MX_PORTC_3H

;----- CONFIG4L Options --------------------------------------------------
;_STVREN_OFF_4L, _STVREN_ON_4L, _LVP_OFF_4L, _LVP_ON_4L, _XINST_OFF_4L, _XINST_ON_4L, _DEBUG_ON_4L, _DEBUG_OFF_4L

;------CONFIG5/6/7 Options not used for code/eeprom protection

lerameur
- 5th January 2007, 19:12
where can I get a tutorial on this,
I checked PBP manual the datasheet of my PIC and I have not seen that. I just want to be able to read what you posted,
1H, 2L 2H etc.. no idea, (and the rest too)
hennnn I feel pretty stupid now

I saw that this is in the file included in the PBP compiler, like INCLUDE "P16F877A.INC"

SteveB
- 5th January 2007, 19:23
where can I get a tutorial on this...

Here is a good starting place: Presetting Configuration Fuses (PIC Defines) into your Program (http://www.picbasic.co.uk/forum/showthread.php?t=543)

skimask
- 5th January 2007, 19:33
where can I get a tutorial on this,
I checked PBP manual the datasheet of my PIC and I have not seen that. I just want to be able to read what you posted,
1H, 2L 2H etc.. no idea, (and the rest too)
hennnn I feel pretty stupid now

I saw that this is in the file included in the PBP compiler, like INCLUDE "P16F877A.INC"

Check 'Special Features' section of the datasheet, and 'Presetting Config fuses' link above. That should hook you up with all the info you need. It got me straightened out in a hurry.

lerameur
- 5th January 2007, 19:35
Ok thanks for the link

to go back to the A/D conversion.
I read another way to use analog to digital with direct ADC control, and not with adcin , What does that mean ?

skimask
- 5th January 2007, 19:41
Ok thanks for the link

to go back to the A/D conversion.
I read another way to use analog to digital with direct ADC control, and not with adcin , What does that mean ?

Accessing the registers directly, select channel, set pin assignments, set acquisition time, set sampling time, turn module on, start a/d conversion, wait for completion and read the registers.
Again, if ADCIN is working, stay with it. You won't do a lot better with direct access.

mister_e
- 5th January 2007, 21:09
Yup it's just another way to do the same thing... it's just a little less code hungry

lerameur
- 7th January 2007, 01:00
Ok still working on the same pic.

I finally got the oscillation going.
I wrote this program: (I have two questions)
1) why does the DEFINE OSC 20 not work in this case
2) In the program i wrote, NOTHING appears on the LCD
Can I put all the ldout pin on the B port ?
Pin 11 LCD on to PIN 25
Pin 12 --> Pin 26
Pin 13 --> Pin 27
Pin 14 --> Pin 28

anything software for the lcd that i dont have to do with the Pic 16f88 ?

@ DEVICE PIC16F876A , HS_OSC , WDT_OFF , PWRT_ON , BOD_ON , LVP_OFF , PROTECT_OFF
'HS 20mhz, watchdog off, powerup timer on, mclr external, brown out detect on, low volt program off , code protect off

DEFINE LCD_DREG PORTB ' Set LCD Data port
DEFINE LCD_DBIT 4 ' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
DEFINE LCD_EREG PORTB ' Set LCD Enable port
DEFINE LCD_EBIT 0 ' Set LCD Enable bit
DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
DEFINE LCD_LINES 2 ' Set number of lines on LCD
DEFINE LCD_COMMANDUS 2500
DEFINE LCD_DATAUS 250
DEFINE CHAR_PACING 2000

Pause 1000 ' Wait 1 second

loop:

lcdout $FE,1, "Number: ", dec 55
pause 100
goto loop
end

Have you got PGM (RB4? RB5?) pulled up or down, whichever it is?
I use them for my LCDout....

skimask
- 7th January 2007, 01:16
Ok still working on the same pic.

1) why does the DEFINE OSC 20 not work in this case
2) In the program i wrote, NOTHING appears on the LCD
Can I put all the ldout pin on the B port ?

anything software for the lcd that i dont have to do with the Pic 16f88 ?

end

1) What do you mean by OSC 20 doesn't work? Compile error? Timing wrong?

2) yes, you can put the LCD data lines anywhere you CAN define them.
Did you try an led blink yet?

PIC16F876A and 16F88 should operate the same as far as PBP is concerned.
Why not use port D like usual?

lerameur
- 7th January 2007, 01:32
What do you mean by OSC 20 doesn't work? Compile error? Timing wrong?
No oscillation on the scope... thast why

2) yes, you can put the LCD data lines anywhere you CAN define them.
Did you try an led blink yet?
I will try it

PIC16F876A and 16F88 should operate the same as far as PBP is concerned.
Why not use port D like usual?
NO port D on that chip, I tried portC 4 to 7 , no difference

skimask
- 7th January 2007, 01:45
What do you mean by OSC 20 doesn't work? Compile error? Timing wrong?
No oscillation on the scope... thast why

2) yes, you can put the LCD data lines anywhere you CAN define them.
Did you try an led blink yet?
I will try it

PIC16F876A and 16F88 should operate the same as far as PBP is concerned.
Why not use port D like usual?
NO por D onthat chip, I tried portC 4 to & , no differnce

You said in post 236 you got the oscillation going.

Port D - DOH!!!! I knew that...I was just checking you...yeah that's it, just checking... :)

lerameur
- 7th January 2007, 01:47
yes it does oscillate
when I put thisline:

@ DEVICE PIC16F876A , HS_OSC , WDT_OFF , PWRT_ON , BOD_ON , LVP_OFF , PROTECT_OFF

and not:
DEFINE OSC 20

lerameur
- 7th January 2007, 01:53
led on RC3,.. do not work :(

@ DEVICE PIC16F876A , HS_OSC , WDT_OFF , PWRT_ON , BOD_ON , LVP_OFF , PROTECT_OFF
'HS 20mhz, watchdog off, powerup timer on, mclr external, brown out detect on, low volt program off , code protect off

INCLUDE "modedefs.bas"

DEFINE LCD_DREG PORTC ' Set LCD Data port
DEFINE LCD_DBIT 4 ' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
DEFINE LCD_EREG PORTB ' Set LCD Enable port
DEFINE LCD_EBIT 0 ' Set LCD Enable bit
DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
DEFINE LCD_LINES 2 ' Set number of lines on LCD
DEFINE LCD_COMMANDUS 2500
DEFINE LCD_DATAUS 250
DEFINE CHAR_PACING 2000

TRISC =0

Pause 1000 ' Wait 1 second

loop:

lcdout $FE,1, "Number: ", dec 55
pause 100

portc.3=0
portc.3=1
pause 300
portc.3=0

goto loop

end

lerameur
- 7th January 2007, 02:18
even this do not work...
compiles and everything, but no action

@ DEVICE PIC16F876A , HS_OSC , WDT_OFF , PWRT_ON , BOD_ON , LVP_OFF , PROTECT_OFF
'HS 20mhz, watchdog off, powerup timer on, mclr external, brown out detect on, low volt program off , code protect off
DEFINE OSC 20
INCLUDE "modedefs.bas"
TRISC =0
loop:

portc.3=1 'Blink led
pause 300
portC.3=0
pause 300

goto loop

end

skimask
- 7th January 2007, 03:29
yes it does oscillate
when I put thisline:

@ DEVICE PIC16F876A , HS_OSC , WDT_OFF , PWRT_ON , BOD_ON , LVP_OFF , PROTECT_OFF

and not:
DEFINE OSC 20

DEFINE OSC 20 is for PBP and it's internal compiler and setting up various timing loops; it doesn't set any config bits anywhere in the PIC.

Leave both in there.

lerameur
- 7th January 2007, 03:32
then why doesn't the program in post 242 work ??

skimask
- 7th January 2007, 03:36
then why doesn't the program in post 242 work ??

osc running at ~20mhz?
are you using a crystal or one of those can oscillators?
all other things being equal, it's probably the programmer's fault (not you, I mean the actual hardware)

lerameur
- 7th January 2007, 03:47
i am using a crystal 20.0Mhz
programmer ? I have another one ...

lerameur
- 7th January 2007, 04:25
ok TRied the easy Prog Programmer,
http://www.embedinc.com/easyprog/index.htm
does not work more, same thing, I meam .. nothing is happening...

skimask
- 7th January 2007, 06:11
ok TRied the easy Prog Programmer,
http://www.embedinc.com/easyprog/index.htm
does not work more, same thing, I meam .. nothing is happening...

Just curious, is the chip a 16F876 or a 16F876A.... there's a difference as far as programming method goes...

lerameur
- 7th January 2007, 11:58
it is the 876A and 877A BOTH

lerameur
- 7th January 2007, 12:26
I also have te Pic18F4685, PBP do not have a file to compile this...
How do I go about making an Hex file out of it ??