|
|
View previous topic :: View next topic |
Author |
Message |
RobS
Joined: 29 Jan 2005 Posts: 10
|
DS18B20 1-wire time critical application issue - need input |
Posted: Sun Apr 17, 2005 7:42 am |
|
|
Hi,
I'm using a PIC 18LF8720 with a PCWH ver 3.206 compiler to operate a Dallas DS18B20 1-wire digital thermometer.
I have a program where one of its functions is to measure and return temperature from this device. Out of 60 sensors measured two did not function, that is the temperature returned was 4095 deg C. The correct value was 22 deg C. I then decided to test the two devices using a test program that was generated during development of the main program. The two devices work with the test program.
In accordance with the data sheet the read function, which obtains temperature from the device, sets an output low, delays 2 microseconds, releases the output by reading the output, delays 10 microseconds and then reads the input to determine if the device is sending a 1 or a 0.
By using an additional output as a trigger I examined the bit stream on a scope during a read time slot and found the timing was slightly different with the two programs. The time when the PIC was reading the device to determine if a 0 or 1 bit was sent was several microseconds later on the program that did not function Vs. the program that did function. It appears these two devices are at the far end of their tolerance.
After examining the .lst file for both programs it turns out the read_byte function whose C code is exactly the same in both programs has slightly different assembly language versions, that is there are extra lines which would account for the extra time. Both programs were compiled with the same version compiler.
I’m concerned that the code turned out to be slightly different for the two programs and am thinking I should use assembly language for time critical applications like communicating with a DS18B20.
I would like some feed back on this and some recommendation on incorporating assembly language into a C program.
Thanks |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Sun Apr 17, 2005 8:53 am |
|
|
What frequency is your processor running at? Just a few extra instructions shouldn't give you a difference of several microseconds unless you are running at a lower frequency.
Quote: | the read_byte function whose C code is exactly the same in both programs has slightly different assembly language versions, that is there are extra lines which would account for the extra time. Both programs were compiled with the same version compiler. | Same compiler version and same code but different code generated? This is strange. Very likely both programs are not the same. Do you have fast_io enabled in one program and not in the other? For time critical applications activate the fast_io compiler directive, this will save you setting the tris-bits with every I/O operation.
Quote: | It appears these two devices are at the far end of their tolerance. | Which devices do you mean here? The PICs or the thermometers? |
|
|
jds-pic
Joined: 17 Sep 2003 Posts: 205
|
Re: DS18B20 1-wire time critical application issue - need in |
Posted: Sun Apr 17, 2005 8:39 pm |
|
|
RobS wrote: | I have a program where one of its functions is to measure and return temperature from this device. Out of 60 sensors measured two did not function, that is the temperature returned was 4095 deg C. |
why don't you range check the result and repeat the read operation if it is beyond the range of the sensor? in no case should your software report such an anomolous reading to the user or another applications. see
http://cuhwww.upr.clu.edu/~pnm/presentations/ariane.htm
RobS wrote: | The correct value was 22 deg C. I then decided to test the two devices using a test program that was generated during development of the main program. The two devices work with the test program. |
always integrate your test code with your application. do it as best to can to preserve the main functions of your applications. careful application of includes and proper top-down programming structure will make it possible.
RobS wrote: | I’m concerned that the code turned out to be slightly different for the two programs and am thinking I should use assembly language for time critical applications like communicating with a DS18B20. |
i use a lot of onewire devices in production -- and have not seen this problem. more than likely, your code is not quite consistent with the onewire spec. it works most of the time, but not all of the time.
RobS wrote: | I would like some feed back on this and some recommendation on incorporating assembly language into a C program.
|
you have not figured out what the problem is. don't apply a "solution" yet.
before delving into assembly, i would:
revisit your code against the onewire spec.
consult a known-good library, e.g. http://www.ccsinfo.com/forum/viewtopic.php?t=19520
figure out what interrrupts are enabled during time-critical onewire reads
jds-pic |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|