Problem with the PWM waveform frequency for PIC16f1936
I am using the latest version of Flowcode 7
I have a test plate made of PIC16f1936 with an external 12MHz generator.
The program that outputs the 50Hz waveform at the RA0 output
At the RB0 output, a waveform of approximately 11 kHz should appear.
The actual waveform has a frequency of about 3kHz
Apparently, the PWM component shows the false frequencies
Please help.
The presented fragment is part of a larger project that works properly.
Unfortunately, the PWM generation does not work
Justin
Problem with the PWM waveform frequency for PIC16f1936
Moderator: Benj
-
- Flowcode v5 User
- Posts: 40
- Joined: Wed Sep 12, 2012 1:59 pm
- Has thanked: 1 time
- Been thanked: 7 times
- Contact:
Problem with the PWM waveform frequency for PIC16f1936
- Attachments
-
- PWMPIC16F1933.fcfx
- (10.27 KiB) Downloaded 211 times
-
- capture_014_10022018_161047.jpg (93.69 KiB) Viewed 6041 times
-
- capture_009_10022018_160628.jpg (39.27 KiB) Viewed 6041 times
-
- Matrix Staff
- Posts: 9520
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: Problem with the PWM waveform frequency for PIC16f1936
So you not using an external crystal?
If you are your Configuration settings are wrong.
You should have HS Oscillator selected.
Have you completed a 1 second test?
I know you said other parts are working but its always worth doing test.
Its the first thing I do when starting a new project.
Just in case there was a PWM bug and sice been fixed, have you downloaded the latest updates from here?
If you are your Configuration settings are wrong.
You should have HS Oscillator selected.
Have you completed a 1 second test?
I know you said other parts are working but its always worth doing test.
Its the first thing I do when starting a new project.
Just in case there was a PWM bug and sice been fixed, have you downloaded the latest updates from here?
Martin
- QMESAR
- Valued Contributor
- Posts: 1287
- Joined: Sun Oct 05, 2014 3:20 pm
- Location: Russia
- Has thanked: 384 times
- Been thanked: 614 times
- Contact:
Re: Problem with the PWM waveform frequency for PIC16f1936
Hi
Just to add to what Martin said
from my calculations with the timer period you are running as the source of the PWM will give you the 11Khz as you mentioned however the Duty cycle
resolution at this Frequency and Clock Frequency is 10 bit (0 -1023) I think you should use the makro setDutycycle10() ,then 50% duty cycle will be 511.
and 100% will be 1023 , I have modified your Flowchart can you please try it at least you will have a better resolution on your PWM
Just to add to what Martin said
from my calculations with the timer period you are running as the source of the PWM will give you the 11Khz as you mentioned however the Duty cycle
resolution at this Frequency and Clock Frequency is 10 bit (0 -1023) I think you should use the makro setDutycycle10() ,then 50% duty cycle will be 511.
and 100% will be 1023 , I have modified your Flowchart can you please try it at least you will have a better resolution on your PWM
https://www.flowcodexchange.com/
Regards QMESAR
Regards QMESAR
-
- Flowcode v5 User
- Posts: 40
- Joined: Wed Sep 12, 2012 1:59 pm
- Has thanked: 1 time
- Been thanked: 7 times
- Contact:
Re: Problem with the PWM waveform frequency for PIC16f1936
The generator is configured well.
I do not use a quartz oscillator. I use an external generator 12Mhz
It seems to me that the PWM macro does not work well.
When I changed the clock frequency of 12MHz to 8MHz, the PWM component did not change the frequency and still shows 11.718kHz
I need 11.718kHz frequency. In the test system on the RB0 pin should be 11718,75 Hz and the actual frequency is 3000Hz
I do not use a quartz oscillator. I use an external generator 12Mhz
It seems to me that the PWM macro does not work well.
When I changed the clock frequency of 12MHz to 8MHz, the PWM component did not change the frequency and still shows 11.718kHz
I need 11.718kHz frequency. In the test system on the RB0 pin should be 11718,75 Hz and the actual frequency is 3000Hz
- QMESAR
- Valued Contributor
- Posts: 1287
- Joined: Sun Oct 05, 2014 3:20 pm
- Location: Russia
- Has thanked: 384 times
- Been thanked: 614 times
- Contact:
Re: Problem with the PWM waveform frequency for PIC16f1936
I can only say this,I am quite sure there is nothing wrong with the PWM component as I use it on a PIC16F1937 and 1938 and your 1936 is not different from the 1937 as it is the same family .but I could be wrong unfortunate I do not have a 1936 to testIt seems to me that the PWM macro does not work well.
https://www.flowcodexchange.com/
Regards QMESAR
Regards QMESAR
-
- Flowcode v5 User
- Posts: 40
- Joined: Wed Sep 12, 2012 1:59 pm
- Has thanked: 1 time
- Been thanked: 7 times
- Contact:
Re: Problem with the PWM waveform frequency for PIC16f1936
Dear Friends
I am asking you for quick help.
I introduced the updates that Ben recommended.
I changed the generator to an internal 32000000Hz (PLL ON). Attaching a new file
The 32MHz clock works ok because RA0 is the correct frequency.
PWM output instead of 31.25kHz is only 2kHz
I am asking you for quick help.
I introduced the updates that Ben recommended.
I changed the generator to an internal 32000000Hz (PLL ON). Attaching a new file
The 32MHz clock works ok because RA0 is the correct frequency.
PWM output instead of 31.25kHz is only 2kHz
- Attachments
-
- PWMPIC16F1936_int_osc.fcfx
- (10.43 KiB) Downloaded 216 times
-
- capture_003_12022018_121519.jpg (86.18 KiB) Viewed 5994 times
-
- Flowcode v5 User
- Posts: 40
- Joined: Wed Sep 12, 2012 1:59 pm
- Has thanked: 1 time
- Been thanked: 7 times
- Contact:
Re: Problem with the PWM waveform frequency for PIC16f1936
Dear Friends
It is possible to use PWM without a macro. I am asking for help in creating the C code.
Ultimately, I want to work in ECCP Mode Half-Brigde.
I will use RC6 (PA3) and RC7 (P3B) pins and I can not use the PWM macro
It is possible to use PWM without a macro. I am asking for help in creating the C code.
Ultimately, I want to work in ECCP Mode Half-Brigde.
I will use RC6 (PA3) and RC7 (P3B) pins and I can not use the PWM macro
- 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: Problem with the PWM waveform frequency for PIC16f1936
Hello,
I believe at the moment the frequency is only re-calculated when one of the component properties change and not when the project clock speed changes. If you say change the period and then change it back then the frequency should now be calculated correctly for the new clock speed.When I changed the clock frequency of 12MHz to 8MHz, the PWM component did not change the frequency and still shows 11.718kHz
I need 11.718kHz frequency. In the test system on the RB0 pin should be 11718,75 Hz and the actual frequency is 3000Hz
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
-
- Flowcode v5 User
- Posts: 40
- Joined: Wed Sep 12, 2012 1:59 pm
- Has thanked: 1 time
- Been thanked: 7 times
- Contact:
Re: Problem with the PWM waveform frequency for PIC16f1936
Dear Benj
The PWM macro after refreshing shows the correct frequency.
However, on the PWM PCB test the frequency has a completely different value.
The problem with showing is not important
The PWM macro after refreshing shows the correct frequency.
However, on the PWM PCB test the frequency has a completely different value.
The problem with showing is not important
- QMESAR
- Valued Contributor
- Posts: 1287
- Joined: Sun Oct 05, 2014 3:20 pm
- Location: Russia
- Has thanked: 384 times
- Been thanked: 614 times
- Contact:
Re: Problem with the PWM waveform frequency for PIC16f1936
Hi
Attached is a FLowchart that runs the INTOSC at 16MHZ it uses C code that Configure the Timer 4 as the PWM period Timer with a Frequency of 5KHZ and it initialize the PWM module with a Duty cycle of 50% .
If you program this into your device you will see a PWM at RC6 (P3A) with a Duty cycle of 50% then on RB0 you should see a Toggle of the PIN at 7,68 Hz or 130 mSec
If you do not have this on your device can you please post some scope prints that shows what you have measured
Hope this helps you
Attached is a FLowchart that runs the INTOSC at 16MHZ it uses C code that Configure the Timer 4 as the PWM period Timer with a Frequency of 5KHZ and it initialize the PWM module with a Duty cycle of 50% .
If you program this into your device you will see a PWM at RC6 (P3A) with a Duty cycle of 50% then on RB0 you should see a Toggle of the PIN at 7,68 Hz or 130 mSec
If you do not have this on your device can you please post some scope prints that shows what you have measured
Hope this helps you
https://www.flowcodexchange.com/
Regards QMESAR
Regards QMESAR