PDA

View Full Version : Internal oscillator please help



timbash
- 25th February 2009, 19:35
I've been trying for a day and a half now to get my PIC to do something I finally have it running but it is running slow. If I put pause 1000 in the code it basically stops. When I do pause 1 it runs at about 4Hz but speeds up if I put my finger near the pic. Whatever changes I make to Internal oscillator speeds it stays at the same speed. It even runs if I set it for external oscillator. I don't understand. Here's the code I have.


@ Device PWRT_OFF
@ Device MCLR_OFF
@ Device INTRC_OSC
@ Device BOR = 0
@ Device Debug_Off

OSCCON = %01110000
OPTION_REG = %11111111
TRISB = %00101010



Any help would be appreciated.

Thanks,

Acetronics2
- 25th February 2009, 19:38
Which Pic, please ...

Alain

SOMRU
- 25th February 2009, 19:46
RTDS is the answer...

Refer To Data Sheets

timbash
- 25th February 2009, 20:21
Sorry, 16F819

I've been over the datasheets time and time again and cannot figure this out.

Thanks

Bruce
- 25th February 2009, 21:18
It even runs if I set it for external oscillator
That's a big red flag there. Are you 100% sure you're even programming it?

If you set config options for an external crystal or resonator, program the part,
and it's still running, you really do have a problem.

Post all your code & let us know which programmer you're using. That would really
help.

timbash
- 25th February 2009, 21:27
This is all I have, at this point I was just trying to get the thing to do something in this case the leds on the different ports do switch on and off.

@ Device PWRT_OFF
@ Device MCLR_OFF
@ Device INTRC_OSC
@ Device BOR = 0
@ Device Debug_Off

OSCCON = %01110000
OPTION_REG = %11111111
TRISB = %00101010


loop:

TRISB = %00101010
Pause 1
PortB = 1
TRISB = %11010101
Pause 1
PortB = 1
TRISB = %00101010
Pause 1
goto loop

End

mister_e
- 25th February 2009, 21:33
Indeed there's a problem, the above don't set the proper config fuses.

Try

@ device pic16f819, INTRC_OSC_NOCLKOUT
@ device pic16f819, WDT_OFF
@ device pic16f819, PWRT_ON
@ device pic16f819, MCLR_OFF
@ device pic16f819, BOD_ON
@ device pic16f819, LVP_OFF
@ device pic16f819, DEBUG_OFF

That line you had

@ Device BOR = 0
screw everything up ;)

Bruce
- 25th February 2009, 21:57
You might want DEFINE OSC 8 in there too if you're running at 8MHz VS the default 4MHz.

timbash
- 25th February 2009, 22:12
Well Steve, that seems to have done it Thank You!!! I'm not sure I quite understand it all but I can work it out I'm sure.

Thanks again.

peterdeco1
- 26th February 2009, 14:11
Hi Tim. Maybe this will help you. I believe the following also applys to the 16F88.

'INTERNAL OSCILLATOR VALUES for 16f818/819:
'OSCCON = $00 'for 31.25 khz
'OSCCON = $10 '125khz
'OSCCON = $20 '250khz
'OSCCON = $30 '500khz
'OSCCON = $40 '1mhz
'OSCCON = $50 '2mhz
'OSCCON = $60 '4mhz
'OSCCON = $70 '8mhz
adcon1 = 7 ' set inputs to digital. Using the adcin command will automatically convert the ADC port to 'analog
'OPTION_REG.7=0 ' Switch-ON weak pull-up's on portb
'@ DEVICE MCLR_ON, INTRC_OSC, WDT_ON, LVP_OFF, BOD_OFF, PWRT_ON, PROTECT_ON
'CCPMX_ON THE @ DEVICE LINE ABOVE SETS HPWM OUTPUT TO RB3, CCPMX_OFF (DEFAULT IF NOT 'SPECIFIED) = RB2