Jump to content
Sign in to follow this  
azoto

Weird Delay

Recommended Posts

Hi All,

 

I'm doing a very simple project using Boostc and a PIC16F877.

All of a sudden (after reopening BoostC and my programmer) the delay functions seem not to work anymore, or better if I put for example

 

set_bit(portb,0);

delay_ms(7);

clear_bit(portb,0);

 

then the LED connected to portb.0 is switched off, but if I try

 

set_bit(portb,0);

delay_ms(8);

clear_bit(portb,0);

 

Then it's steady on.

 

I wasn't using delay_ms, of course, but delay_s that is not working at all anymore.

delay_us is working fine (well, I didn't check the real timing...)

 

Can u please help? I've got no idea of what it could be.

 

Thanks

Share this post


Link to post
Share on other sites

azoto,

 

Sounds like maybe the watchdog timer is constantly reseting the CPU before some of the code gets reached when the longer delay is used.

 

Make sure watchdog is disabled, or set to a longer time.

 

Regards

Dave

Share this post


Link to post
Share on other sites

Hi Dave,

thanks for the reply.

 

In theory the WDT should be disabled since my fuses are:

#pragma DATA _CONFIG, _PWRTE_OFF & _BODEN_OFF & _WDT_OFF & _LVP_ON & _CPD_OFF & _DEBUG_OFF & _HS_OSC & _CP_OFF

 

But I tried this code anyway, to be test the WDT:

set_bit(portb,0);

clear_wdt();

delay_ms(3);

clear_wdt();

delay_ms(3);

clear_wdt();

clear_wdt();

delay_ms(3);

clear_wdt();

delay_ms(3);

clear_wdt();

clear_bit(portb,0);

 

But it doesn't work. I gues if it was the WDT it should, since this code's working:

set_bit(portb,0);

delay_ms(7);

clear_bit(portb,0);

 

Any other idea?

I even tried to change the PIC and to switch to another crystal, but nothing.

 

I can't really understand what's going on, since the code was working on the same hardware just few hours before.

 

Thanks for any help

Share this post


Link to post
Share on other sites

I just tryed the simplified example I wrote here on a blank project and it worked. Sorry for wasting your time: I guess I simplified too much my code.

 

If you're interested in the weird code that doesn't make delay functions work, I can either put it here or send it to you. All the functions are from the internet, since it's been only a week I'm doing this.

 

I'll rewrite everything, so I don't expect an answer on that, but it would be great to know what's wrong with that code, cause I'm trying to learn the art of PIC programming (and electronics in general as well).

 

Thanks

 

 

EDIT: I've found it! RB6 & RB7 were set as inputs... I'm programming my PIC via LVP, may it be related?

Edited by azoto

Share this post


Link to post
Share on other sites

azoto,

 

I would be interested in seeing that project that appears to give strange delays, just in case we have a problem with them.

 

Please send the project to support@picant.com.

 

Regards

Dave

Share this post


Link to post
Share on other sites

Hi Dave, I'm an ass... RB3 and RB6,7 were floating, so it gave really strange behaviours. I guess I should read some good books before trying everything from scratch...

 

Thanks

 

azoto,

 

I would be interested in seeing that project that appears to give strange delays, just in case we have a problem with them.

 

Please send the project to support@picant.com.

 

Regards

Dave

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...