Jump to content
Sign in to follow this  
Matthias

delay routine

Recommended Posts

I tried some routines for reading a temperature-sensor DS1820 on the compiler today, and found the following

problem. I use a 16F871 at 20 MHz

 

the routines worked properly when all the routines

where in the main.c file. I tried to seperate them

in an extra c-file. from now on they didn't work any more.

I didn't alter the routines themself.

 

I watched the output on the pin and found that the times

are not correct.

 

I compared the two codes and found one significant

difference: the routines for delay_us are not the same.

 

code when the routines in the main.c, this seems to be ok.

 

_delay_usend

 

code when routines in the extra-c file, :

 

_delay_usend

 

I copied the first code over the second and altered the labels:

 

 

_delay_usend

 

after a reassemble, the code worked fine.

is this a bug? why are the routines different?

 

Thanks

Matthias

Share this post


Link to post
Share on other sites
Guest Matthias

the code got lost somehow :)  here it is again:

 

working code:

_delay_usend

 

not working code:

_delay_usend

 

replaced working code:

_delay_usend

Share this post


Link to post
Share on other sites
Guest Dave

Mathias,

 

Looks like the code you are trying to post contains something that is confusing Ikonboard (the forum software).  :)

 

Please check there no funny character sequences, or control characters in the post ???

 

Check the post using the "Preview Post" button before "Add Reply" button is pressed.

 

Regards

Dave

Share this post


Link to post
Share on other sites
Guest Matthias

Yes it seems so, don't know why. Next try....  ???

 

working code:

_delay_us
       movlw D'2'
       subwf param00_delay_us, F
label_0010
       nop
       nop
       decfsz param00_delay_us, F
       goto label_0010
       nop
       return

 

not working:

_delay_us
       bcf STATUS, RP0
       bcf STATUS, RP1
       rrf param00_delay_us, F
       rrf param00_delay_us, F
       movlw D'63'
       andwf param00_delay_us, F
       movlw D'3'
       subwf param00_delay_us, F
label_0015
       nop
       decfsz param00_delay_us, F
       goto label_0015
       nop
       return

 

replacement code:

_delay_us
       movlw D'2'
       subwf param00_delay_us, F
label_0015
       nop
       nop
       decfsz param00_delay_us, F
       goto label_0015
       nop
       return

Share this post


Link to post
Share on other sites
Guest Pavel

Different code in delay routines may be generated if the #pragma CLOCK_FREQ value in the source files is different. For example #pragma CLOCK_FREQ is used in the main file but this file is not the first one in compilation sequence. Than the files that are compiled before the main one may use different CLOCK_FREQ values.

Try to add the #pragma CLOCK_FREQ directive (using the same value) into the beginning of every source file in a project.

 

Regards,

Pavel

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...