View previous topic :: View next topic |
Author |
Message |
mle
Joined: 12 Sep 2003 Posts: 10
|
pbp to ccs |
Posted: Wed Sep 17, 2003 8:53 am |
|
|
Hello,
I have a function written in both pbp and in ccs, and I am getting different results. The function reads 2 bytes from a ds1820 temperature sensor. I am trying to read the temperature value from the scratchpad and the pbp version gives me $0030, whereas the ccs version gives $0036. I know that the pbp version is correct. The ccs version doesn't seem to respond to different temperatures correctly and I always get $0036 for the temperature value, whereas the pbp version ranges from $0030 to $0037 as I add or remove heat.
Here is the pbp version
' Read temperature from the DS1820
read1820:
For i = 1 TO 16 ' 16 bits to a word
temp = temp >> 1 ' Shift down bits
temp.15 = 1 ' Preset read bit to 1
Low DQin ' Start the time slot
TrisB.1 = 0 ' set DQin to an output
@nop ' Delay 1us at 4MHz
TrisB.1 = 1 ' set DQin back to an input
@ nop
@ nop
@ nop
@ nop
@ nop
@ nop
@ nop
@ nop
@ nop
@ nop
IF DQIn = 0 Then
temp.15 = 0 ' Set bit to 0
EndIF
PauseUs 60 ' Wait out rest of time slot
Next i
Return
End
------------------------------------------------------------------------
And this is the ccs version
long read1wire(){
int i; //counter
int result;
long temperature; //the temperature value read in from the sensor
For (i=1; i<=16; i++){
#asm
bcf PortB,1 //pull line low to start time slot
bcf TrisB,1 //set dqin to an output
nop
bsf TrisB,1 //set dqin to an input
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
#endasm
shift_right(&temperature,2,input(DQIN));
delay_us(60);
}
return temperature;
}
Can anyone suggest why the ccs one doen't work?
Thank you,
mle |
|
|
Guest
|
|
Posted: Wed Sep 17, 2003 9:07 am |
|
|
Actually it does work! I'm just doing something wrong with the temperature pointer |
|
|
jds-pic
Joined: 17 Sep 2003 Posts: 205
|
onewire library ( dallas 1wire devices / 1820 / 1822 ) |
Posted: Wed Sep 17, 2003 12:38 pm |
|
|
hi,
can i make a few suggestions when dealing with these onewire devices?
--make a library that you can use over and over again.
--make a library that you can optimize over time, but starts off with a lot of good debugging info including intermediate output.
--make a library that can easily be debugged.
--make a library that has no dependence on the PIC clock speed used.
--make a library that has no dependence on the PIC pin used.
--make a library that does not mix ASM and C as it violates all of the above.
in summary, make (or borrow) a library.
let me help you get you started:
http://losdos.dyndns.org:8080/public/onewire/lib-onewire.html
or
http://losdos.dyndns.org:8080/public/onewire/lib-onewire.h
regards. |
|
|
Guest
|
Re: onewire library ( dallas 1wire devices / 1820 / 1822 ) |
Posted: Fri Dec 09, 2005 10:28 am |
|
|
jds-pic wrote: | hi,
can i make a few suggestions when dealing with these onewire devices?
--make a library that you can use over and over again.
--make a library that you can optimize over time, but starts off with a lot of good debugging info including intermediate output.
--make a library that can easily be debugged.
--make a library that has no dependence on the PIC clock speed used.
--make a library that has no dependence on the PIC pin used.
--make a library that does not mix ASM and C as it violates all of the above.
in summary, make (or borrow) a library.
let me help you get you started:
http://losdos.dyndns.org:8080/public/onewire/lib-onewire.html
or
http://losdos.dyndns.org:8080/public/onewire/lib-onewire.h
regards. |
|
|
|
DragonPIC
Joined: 11 Nov 2003 Posts: 118
|
|
Posted: Fri Dec 09, 2005 12:24 pm |
|
|
bcf PortB,1 //pull line low to start time slot
bcf TrisB,1 //set dqin to an output
These registers are located in different banks. Remember, you are working with inline asm where you must do this manually. Also, you must make sure the bank is in back in the state you changed it from since the compiler does not know. I might be wrong with this, I never used inline asm with the pic before. Look at your list file.
another way to do this is:
Code: | #byte port_b = 0x06
#byte TrisB = 0x86
#bit dqin_tris = TrisB.1
#bit DQIN= port_b.1
For (i=1; i<=16; i++){
DQIN = 0; //pull line low to start time slot
dqin_tris = 0; //set dqin to an output
delay_cycles(1);
dqin_tris = 1; //set dqin to an input
delay_cycles(10);
shift_right(&temperature,2,input(DQIN));
delay_us(60);
} |
The compiler will know what to do then. See if this help. _________________ -Matt |
|
|
DragonPIC
Joined: 11 Nov 2003 Posts: 118
|
|
Posted: Fri Dec 09, 2005 12:42 pm |
|
|
Look in the list file and make sure you will be reading each bit within the 15us slot. Also, make sure you are waiting 46us more after the 15us. Some C code can be compiled into longer or shorter asm than you think. _________________ -Matt |
|
|
jds-pic
Joined: 17 Sep 2003 Posts: 205
|
|
Posted: Fri Dec 09, 2005 1:06 pm |
|
|
when are we members going to stand up and put a stop to "guest" posting? this thread is over 2 years old but gets resurrected by a "guest", wasting a lot of folks time replying to a dead topic.
jds-pic |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Dec 09, 2005 1:09 pm |
|
|
To DragonPic:
You're responding to the notorious "guest", who every day dredges up
some old thread and then quotes part of it, without adding anything of
value.
To jds:
Someone will have to ask Darren to handle it. |
|
|
DragonPIC
Joined: 11 Nov 2003 Posts: 118
|
|
Posted: Fri Dec 09, 2005 1:40 pm |
|
|
lol..... What a jerk. At least I learn more than something. _________________ -Matt |
|
|
DragonPIC
Joined: 11 Nov 2003 Posts: 118
|
|
Posted: Fri Dec 09, 2005 1:43 pm |
|
|
I only replied to it because I though it had to do with the "
Read temperature maximum minimum ds1624" post. _________________ -Matt |
|
|
Darren Rook
Joined: 06 Sep 2003 Posts: 287 Location: Milwaukee, WI
|
|
Posted: Fri Dec 09, 2005 5:21 pm |
|
|
PCM programmer wrote: | To DragonPic:
You're responding to the notorious "guest", who every day dredges up
some old thread and then quotes part of it, without adding anything of
value.
To jds:
Someone will have to ask Darren to handle it. |
Interesting, I never noticed this before.
I think forcing people to register or locking threads after a long period of time would be more annoying then whatever this person's intentions are. What do you guys think? Also, what do you think this guys intentions are, I can't figure it out. |
|
|
mkent
Joined: 09 Sep 2003 Posts: 37 Location: TN, USA
|
|
Posted: Fri Dec 09, 2005 6:31 pm |
|
|
I would be in favor of letting people read all, but have to be registered and signed on in order to post. |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
|
Posted: Fri Dec 09, 2005 8:15 pm |
|
|
I very definitely agree.
Many of the forums allow reading for all but require registration to post. That might help things in this forum.
I am very much in favor of eliminating/blocking "guest" posting entirely. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
Ttelmah Guest
|
|
Posted: Sat Dec 10, 2005 4:34 pm |
|
|
The text input 'confirmation code' system, should prevent any 'bot' from doing this. I'm afraid this is either a glitch, or a real person.
Best Wishes |
|
|
|