View previous topic :: View next topic |
Author |
Message |
smanzer
Joined: 14 Sep 2009 Posts: 24 Location: Ontario, Canada
|
One wire stops working when clock increased |
Posted: Thu Sep 23, 2010 6:56 pm |
|
|
Good evening everyone, I have a problem that perhaps someone has seen before and can help.
I am using the one wire library found in this forum and it works great. I am using a PIC18F8722 at 10MHz. If I use the fuse H4 to give it 40MHz the one wire routines fail.
Anyone had this happen before?
Thanks in advance,
Steven _________________ "I am always doing that which I can not do, in order that I may learn how to do it."
- Pablo Picasso |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Sep 23, 2010 6:59 pm |
|
|
Post a link to the 1-wire driver that you're using. |
|
|
Douglas Kennedy
Joined: 07 Sep 2003 Posts: 755 Location: Florida
|
|
Posted: Fri Sep 24, 2010 11:32 am |
|
|
One wire has very specific timing too fast or too slow and there will be issues. Most of this is often resolved by the use of CCS delay statements that are automatically adjusted for a change in the oscillator frequency. Now changing to H4 is not enough. The frequency in the #use delay must also be set to 40mhz. The delay is based on #use delay and not on the FUSE settings. |
|
|
smanzer
Joined: 14 Sep 2009 Posts: 24 Location: Ontario, Canada
|
Found the solution |
Posted: Sun Sep 26, 2010 4:49 am |
|
|
Thank you for the replies everyone. I tinkered with the #delay and found no change - it works with 10MHz and fails at 40MHz.
I put some debug code in and found the problem was the ow_read_bit() function. Turns out the timing in this function would not work at the higher clock rate.
I searched this forum and found that user Swys had different timing than the original code I used. I modified to match Swys and bing it works!
Here is the corrected function:
Code: |
int8 OW_read_bit(void)
{
int8 value;
// Originally this function failed with H4 fuse
// Modifications from CCS user Swys allowed it to work.
OW_disable_interrupts(TRUE);
output_low(ONE_WIRE_PIN);
delay_us(6); // CCS user Swys changed from 1 to 6
output_float(ONE_WIRE_PIN);
delay_us(9); // Read within 15uS from start of time slot
OW_disable_interrupts(FALSE);
value = input(ONE_WIRE_PIN);
delay_us(55); // CCS user Swys has this added
return(value);
} |
Hope this helps someone else.
Regards,
Steven _________________ "I am always doing that which I can not do, in order that I may learn how to do it."
- Pablo Picasso |
|
|
dynamitron
Joined: 18 Mar 2009 Posts: 38
|
|
Posted: Thu May 17, 2012 8:01 am |
|
|
A few days ago I had this problem and did not find a solution.
At the end I stayed frustrated at 10 MHz.
Now I will try your modified code. |
|
|
|