oscillator frequency 16F628
- rene
- Posts: 56
- Joined: Sun Sep 13, 2009 11:27 am
- Location: Dordrecht - Nederland
- Has thanked: 5 times
- Been thanked: 2 times
oscillator frequency 16F628
Hello,
I have a little problem with a 16F628.
The PIC has an internal clock of 4 MHz or 37kHz ....
But all my programs designed with flowcode4 and tested on the EB006 will run the chip at 37khz.
How do I get this chip running on 4MHz ?
According microchip registry PCON
bit 3 OSCF: INTRC / ER oscillator frequency
1 = 4 MHz typical
0 = 37 kHz typical
The *.asm file of the program shows: gbl_pcon equ 0x000008E
If correct you would say bit 3 = 1.
I do not know how and where this can be changed in flowcode4.
Is the problem the EB006, the PIC, or some parameters settings in flowcode4..?
Who do knows how to use this dynamic clockspeed with flowcode4 ....
Thanks
Rene
I have a little problem with a 16F628.
The PIC has an internal clock of 4 MHz or 37kHz ....
But all my programs designed with flowcode4 and tested on the EB006 will run the chip at 37khz.
How do I get this chip running on 4MHz ?
According microchip registry PCON
bit 3 OSCF: INTRC / ER oscillator frequency
1 = 4 MHz typical
0 = 37 kHz typical
The *.asm file of the program shows: gbl_pcon equ 0x000008E
If correct you would say bit 3 = 1.
I do not know how and where this can be changed in flowcode4.
Is the problem the EB006, the PIC, or some parameters settings in flowcode4..?
Who do knows how to use this dynamic clockspeed with flowcode4 ....
Thanks
Rene
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: oscillator frequency 16F628
Hello Rene,
Set the Flowcode project options clock speed to 4MHz to allow delays etc to be correct.
The set the config to use the internal oscillator.
Finally add a C code block to the start of your program containing the following code.
set_bit (pcon, 3);
The datasheet says this bit is set by default so I wonder why it is defaulting to 37khz setting.
Set the Flowcode project options clock speed to 4MHz to allow delays etc to be correct.
The set the config to use the internal oscillator.
Finally add a C code block to the start of your program containing the following code.
set_bit (pcon, 3);
The datasheet says this bit is set by default so I wonder why it is defaulting to 37khz setting.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
- rene
- Posts: 56
- Joined: Sun Sep 13, 2009 11:27 am
- Location: Dordrecht - Nederland
- Has thanked: 5 times
- Been thanked: 2 times
Re: oscillator frequency 16F628
Thanks Benj...
I try to set and reset the pcon bit as you described , the clock speed of the pic increased and decreased with changing bit status...
Now i know how to set some bit in C-code (I like to know more about C with Flowcode4. what will you recommend me)
I'll try to bitbang a PWM fore some RGB leds... but the speed of the internal clock seems to be not fast enough. (4 Mhz and prescale 1/4 ???)
I thought it would be fast enough for some PWM's
With the xtal osc. of the EB006 and the OSC set to HS it works fine.
I'll choose for the 16F628 because of his internal OSC, less parts needed to my pcb..
Could the pic be broken or what ?
Rene
I try to set and reset the pcon bit as you described , the clock speed of the pic increased and decreased with changing bit status...

Now i know how to set some bit in C-code (I like to know more about C with Flowcode4. what will you recommend me)
I'll try to bitbang a PWM fore some RGB leds... but the speed of the internal clock seems to be not fast enough. (4 Mhz and prescale 1/4 ???)
I thought it would be fast enough for some PWM's
With the xtal osc. of the EB006 and the OSC set to HS it works fine.
I'll choose for the 16F628 because of his internal OSC, less parts needed to my pcb..
Could the pic be broken or what ?
Rene
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: oscillator frequency 16F628
Hello Rene,
Have you seen this article on bit banging PWM. Hopefully it should allow you to use your chip running at 4MHz.
http://www.matrixmultimedia.com/article.php?a=52
Have you seen this article on bit banging PWM. Hopefully it should allow you to use your chip running at 4MHz.
http://www.matrixmultimedia.com/article.php?a=52
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Re: oscillator frequency 16F877A
Hi guys,
How can I make my PWM to have a frequency of 100kHz. using Flowcode 5, the chip is currently showing 19.2kHz and not giving me the option of changing my switching frequency. Am building a boost converter and needs 100KHz freq. Using pic 16f877A. Thanks

How can I make my PWM to have a frequency of 100kHz. using Flowcode 5, the chip is currently showing 19.2kHz and not giving me the option of changing my switching frequency. Am building a boost converter and needs 100KHz freq. Using pic 16f877A. Thanks

-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: oscillator frequency 16F628
Hi daniel212,
Adjusting period register (and Prescaler divide) will alter PWM frequency: But the lower the period register, then resolution of PWM duty will be lower.
So with 8 bit PWM if period register = 48 then there are only 48 steps from 0 to 100%.
For the higher frequencies, if 10bit resolution is not good enough then I would recommend using a microcontroller with a PLL function.
This will allow higher clock frequencies (Xtal or internal osc is usually multiplied by 4)
So you you have a 10MHz xtal, then PLL will run the chip at 40MHz.
Then you will have a better resolution at 100KHz.
Martin.
Adjusting period register (and Prescaler divide) will alter PWM frequency: But the lower the period register, then resolution of PWM duty will be lower.
So with 8 bit PWM if period register = 48 then there are only 48 steps from 0 to 100%.
For the higher frequencies, if 10bit resolution is not good enough then I would recommend using a microcontroller with a PLL function.
This will allow higher clock frequencies (Xtal or internal osc is usually multiplied by 4)
So you you have a 10MHz xtal, then PLL will run the chip at 40MHz.
Then you will have a better resolution at 100KHz.
Martin.
Martin
Re: oscillator frequency 16F628
thanks for your help Medelec35,
Am having some troubles. I wanna use Pic 16f877A to generate two PWM signals ( i.e when PWM 1 is ON'' then PWM 2 should be OFF and vice versa)
Any ideas??
Am having some troubles. I wanna use Pic 16f877A to generate two PWM signals ( i.e when PWM 1 is ON'' then PWM 2 should be OFF and vice versa)
Any ideas??
Re: PWM & ADC using PIC 16F88
Hi guys, need some help. (Using pic16f88 on flowcode V5)
I have already created a basic pwm on flowcode but need to add some ADC function which will then vary the pwm depending on ADC output value.
I intend adding a voltage divider to the output section of a converter, which will be fed to the analogue input of the PIC pin (eg AN1).
The program or microcontroller should then vary the duty cycle depending on the value of the potential divider output (ADC result).
for example, I can set say 3v to be coming out from the potential divider when the converter's output is exactly 20V (required),
it means, the microcontroller should increase the duty cycle of the PWM whenever the input to the AN1 is less than 3V hence to compensate for any output voltage sag. And should decrease the duty cycle of the PWM whenever the input to the AN1 is greater than 3V.
Am a novice at programming PIC Any help or advise will be appreciated.
I have already created a basic pwm on flowcode but need to add some ADC function which will then vary the pwm depending on ADC output value.
I intend adding a voltage divider to the output section of a converter, which will be fed to the analogue input of the PIC pin (eg AN1).
The program or microcontroller should then vary the duty cycle depending on the value of the potential divider output (ADC result).
for example, I can set say 3v to be coming out from the potential divider when the converter's output is exactly 20V (required),
it means, the microcontroller should increase the duty cycle of the PWM whenever the input to the AN1 is less than 3V hence to compensate for any output voltage sag. And should decrease the duty cycle of the PWM whenever the input to the AN1 is greater than 3V.
Am a novice at programming PIC Any help or advise will be appreciated.
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: oscillator frequency 16F628
Hello,
You cannot do this directly using a second PWM channel as they will always be in phase i.e. both channels go high at the start of the duty. However using a NPN transistor and resistor you can split the signal up in hardware so that when the PWM signal is on the signal out the transistor is off and visa versa. An inverting buffer or nand gate would also work well.thanks for your help Medelec35,
Am having some troubles. I wanna use Pic 16f877A to generate two PWM signals ( i.e when PWM 1 is ON'' then PWM 2 should be OFF and vice versa)
Any ideas??
You would just need a loop which sampled the ADC and then compared it to what you require. If the ADC is less than you require then add one to the PWM duty, otherwise if the ADC is more than you require you subtract one from the PWM duty. If you need a faster response time then you can use proportional control i.e. you add or subtract from the PWM duty the difference between your setpoint and the ADC reading, this might need to be tweaked a bit to avoid oscillation.it means, the microcontroller should increase the duty cycle of the PWM whenever the input to the AN1 is less than 3V hence to compensate for any output voltage sag. And should decrease the duty cycle of the PWM whenever the input to the AN1 is greater than 3V.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Re: oscillator frequency 16F628
Thanks Ben, Could you pls show me a screenshoot of a simple ADC (reading voltages) looks like? thanks