Page 1 of 1

Timing Issue?

Posted: Mon Jun 22, 2015 10:30 pm
by JDR04
Hi folks, I have attached the flowchart I have done for a darkness detector.

Everything seems to be working fine except for when I want the LED (connectd to GP5)to come on for 1 second. For som reason it it comes on for about half a second which is too quick. I've set the internal clock to 8Mhz and 4Mhz for the delays and have checked my chip configurations. For the life of me I just cannot figure out where I have gone wrong so would appreciate somebody pointing it out.

Thanks for your time.............JDR04

Re: Timing Issue?

Posted: Tue Jun 23, 2015 10:57 am
by medelec35
Hi John,
The only thing I can spot is osccon value not matching clock frequency.
osccon=0x60; = 4MHz (since this is the default value on switch on then osccon is not required).
osccon=0x70; = 8MHz

Martin

Re: Timing Issue?

Posted: Thu Jun 25, 2015 10:15 pm
by JDR04
Hi Martin, thanks for your time. Could I clear one thing up as I think I may misunderstand it.

I've got osccon=70 so I can run the chip at 8Mhz. The 4 Mhz I set was for the delay periods? Am I confusing something here????

Thanks a lot.....John

Re: Timing Issue?

Posted: Thu Jun 25, 2015 10:22 pm
by medelec35
Hi John,
JDR04 wrote:'ve got osccon=70 so I can run the chip at 8Mhz. The 4 Mhz I set was for the delay periods? Am I confusing something here????
Yes, I'm afraid you are.
The Clock speed must be set to match the actual osc speed.
All the dalays are automatically calculated.

So if osccon = 0x70; sets osc to 8MHz then you must also set clock speed to 8MHz.
Same if you have a 20MHz crystal then you must also set clock speed to 20MHz.
Etc..

Martin

Re: Timing Issue?

Posted: Sat Jun 27, 2015 6:54 pm
by JDR04
OK, finally get it.

Thanks for your patience.............Take care,John

Re: Timing Issue?

Posted: Sun Jun 28, 2015 1:40 am
by medelec35
No problem at all John.
Glad you have got it now.

Martin