CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

One wire stops working when clock increased

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
smanzer



Joined: 14 Sep 2009
Posts: 24
Location: Ontario, Canada

View user's profile Send private message Visit poster's website

One wire stops working when clock increased
PostPosted: Thu Sep 23, 2010 6:56 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Sep 23, 2010 6:59 pm     Reply with quote

Post a link to the 1-wire driver that you're using.
Douglas Kennedy



Joined: 07 Sep 2003
Posts: 755
Location: Florida

View user's profile Send private message AIM Address

PostPosted: Fri Sep 24, 2010 11:32 am     Reply with quote

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

View user's profile Send private message Visit poster's website

Found the solution
PostPosted: Sun Sep 26, 2010 4:49 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu May 17, 2012 8:01 am     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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