PDA

View Full Version : Setting 8Mhz clock speed on PIC16F684



LEDave
- 12th May 2020, 22:44
Can someone kindly help me please?

I am trying to make a PIC16F684 run at 8Mhz instead of the default 4Mhz.

Problem is, test led's just keeping flashing at 10 secs...

I have MPASM ticked as the Compiler/Assembler and using PBP 2.60

Simple code below:

@ __config _INTOSCIO & _WDT_OFF

DEFINE OSC 8

OSCCON = %01110000 ' Internal 8MHz osc
'OSCTUNE = %00000000 ' not in use
ANSEL = %00000000 'Disable analog select so ports work as digital i/o.
CMCON0 = %00000111 'Disable analog comparators.
TRISA = %00000000 'Set PORTA as OUTPUT.
PORTA = %00000000 'Set PORTA pins all low.


Start

main:

HIGH PORTA.2
PAUSE 10000
LOW PORTA.2
PAUSE 2000
HIGH PORTA.2
PAUSE 10000
LOW PORTA.2
PAUSE 2000

goto main

richard
- 12th May 2020, 23:38
Problem is, test led's just keeping flashing at 10 secs...

PAUSE 10000 is 10 seconds

if the osc is 8 mhz and you tell the compiler the osc is 8 mhz with DEFINE OSC 8
then the pause is 10 seconds as requested

what do you expect the result to be ?

LEDave
- 13th May 2020, 00:17
Hi Richard, thanks for the reply.

"what do you expect the result to be ?"

I thought (and was hoping) that double the OSC speed from 4 to 8Mhz would drive the led's twice as fast, 10secs would become five at 8Mhz if you see what I mean.

Dave

LEDave
- 13th May 2020, 01:00
Just to add, I based my last post on this article: http:// melabs.com/resources/pbpmanual/7_0.htm

But I may have misinterpreted it, in that I thought PAUSE 1000 with DEFINE OSC 4 internal OSC would give one second delay and pause 1000 with DEFINE OSC 8 internal OSC would give 0.5 second delay.....

So are we saying that the above PAUSE 1000 would both cause a one second delay?

Is it only external Xtals/resonators that throw the internal timing off?

Dave

richard
- 13th May 2020, 02:29
Is it only external Xtals/resonators that throw the internal timing off?

no not at all.

the only time it fails is when DEFINE OSC does not match the real osc frequency.

LEDave
- 13th May 2020, 10:30
Thanks again Richard.

So as long as I use DEFINE OSC X, PB knows and compensates for the change still giving the correct timings PAUSE etc?

David

Dave
- 13th May 2020, 15:03
Yes, That is correct. The PAUSE command is based on the OSC frequency. If you had an 4 Mhz. crystal connected and told PBP that the OSC was 8Mhz. the PAUSE command would give you 2 times the value entered into the PAUSE command.

LEDave
- 14th May 2020, 00:08
Dave & Richard, thank you both for taking the time to reply, much appreciated.

Dave