PDA

View Full Version : Pic16f18857 clock setup



microcnc05
- 22nd September 2017, 13:23
I'm hitting my head against the wall now. I can't seem to figure out this new chip. I just want to get it up and running with the internal oscillator at 32Mhz. When I blink an led with a 1 sec interval it's way to fast. If anyone can give me a walk through that would be great.

Charlie
- 22nd September 2017, 14:20
If it is blinking too fast, that would point to your clock speed being too high which is extremely unlikely. Are you absolutely sure your code is correct? Perhaps you should post your blink code.

HenrikOlsson
- 22nd September 2017, 17:51
Yes, it's not very likely that the PIC is running faster than 32MHz.
There's two parts to it. Get the PIC to actually run at the desired frequency and inform the compiler what that speed is so it can get its timing calculations correct. If you don't tell the compiler that you're running the PIC at 32MHz it defaults to 4MHz and your PAUSE 1000 will in effect become a PAUSE 125.

/Henrik.

microcnc05
- 22nd September 2017, 21:19
I was following the data sheet and it must be set for 32Mhz because when I used a pause of 1000 and hooked up the oscilloscope to it I was getting 125ms. I used the define 32 in PBP but it doesn't seem to work. I've never used a chip like this, the oscon register is different. I'll try again tomorrow.

HenrikOlsson
- 22nd September 2017, 21:52
define OSC 32
OSC is case sensitive, the rest is not.

/Henrik.

microcnc05
- 23rd September 2017, 14:05
I've tried so many thing now with no luck. Here is the config setup in 16f18857.inc file. A pause 1000 led on & off program is giving me 125ms on the scope.
#CONFIG
__config _CONFIG1, _FEXTOSC_HS & _RSTOSC_HFINT32 & _CLKOUTEN_OFF & _CSWEN_ON & _FCMEN_ON
__config _CONFIG2, _MCLRE_ON & _PWRTE_OFF & _LPBOREN_OFF & _BOREN_ON & _BORV_LO & _ZCD_OFF & _PPS1WAY_OFF & _STVREN_ON & _DEBUG_OFF
__config _CONFIG3, _WDTCPS_WDTCPS_11 & _WDTE_ON & _WDTCWS_WDTCWS_7 & _WDTCCS_LFINTOSC
__config _CONFIG4, _WRT_OFF & _SCANE_available & _LVP_OFF
__config _CONFIG5, _CP_OFF & _CPD_OFF

#ENDCONFIG

It's my understanding that on reset the internal clock will be running at 32Mhz with these fuses set. I've tried simply setting Define OSC 32, and adding OSCFRQ = %00000110.
There are three OSCCON registers and OSCEN register. I'm off in the weeds and don't know which way to go at this point.

I did notice that when I program the chip with meProg that the configuration HFINTOSC WITH 2X PLL was set instead of HFINTOSC like the fuse is set for. I changed that and my blink program goes from 125ms to 2sec. For what it's worth. Any help would be appreciated thanks.

HenrikOlsson
- 23rd September 2017, 14:29
Why is it so hard to post the code - as in everything? Not just the code, not just the config, not bits, pieces and snippets for us to piece together and extract information from. You think it's hard at your end, how do you think it is for us?


A pause 1000 led on & off program is giving me 125ms on the scope.
That tells me that the PIC is actually running 8 times faster than the compiler thinks it is. You tell it to pause for 1000ms but in reallity it only pauses for 125ms, 1000/125=8. As have been said before it's not very likely that the PIC is running faster than 32MHz (or in this case 8 times faster = 256MHz) it's much more likely that it IS actually running at 32MHz but you haven't properly told the compiler that so it thinks it's running at 4MHz (32 / 4 = 8).

I don't have that chip here but if you post the code, within code tags, which is giving you the 125ms pause when it should be 1000ms I'll see if I can spot the problem.

/Henrik.

microcnc05
- 23rd September 2017, 15:06
Sorry HenrikOlsson for the frustration. I figured it out just now, it wasn't the code. It was my anti-virus software, I had ransom ware protection on. This somehow allowed some of the pic to be programmed but would act screwy. I checked off ransom ware protection and reprogrammed the chip same code, everything works as it should now. Thank you for your help.

HenrikOlsson
- 23rd September 2017, 15:16
Wow, that's the first time I've heard of anything like that. An antivirus program on a PC messing up code on a PIC.
I'm glad you figured that out because I certainly would not have done it from where I'm sitting :-)

/Henrik.

microcnc05
- 23rd September 2017, 15:41
I don't know if I would have figured it out without your last post wanting all my code. I just updated to PBP 3.1, on my system I have to disable ransom ware protection to install programs. I started my program file in PBP when it was still off, then I turned it back on.

To post code for you I started a new file with just the clock info TRIS registers and simple led loop. This time though it would compile but not bring up the programmer. I tried opening the hex manually but the programmer said it couldn't find the file. Hmmmm If it couldn't find the new file something is blocking it was my thinking, that's when I remembered the antivirus software. It lets somethings pass and others not.

So we'll just call this a collaborative effort :)