Page 1 of 1

Problem with the PWM waveform frequency for PIC16f1936

Posted: Sat Feb 10, 2018 5:03 pm
by JustinS
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

Re: Problem with the PWM waveform frequency for PIC16f1936

Posted: Sat Feb 10, 2018 6:11 pm
by medelec35
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?

Re: Problem with the PWM waveform frequency for PIC16f1936

Posted: Sat Feb 10, 2018 6:18 pm
by QMESAR
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
PWMPIC16F1933.fcfx
(10.28 KiB) Downloaded 255 times

Re: Problem with the PWM waveform frequency for PIC16f1936

Posted: Mon Feb 12, 2018 8:36 am
by JustinS
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

Re: Problem with the PWM waveform frequency for PIC16f1936

Posted: Mon Feb 12, 2018 12:07 pm
by QMESAR
It seems to me that the PWM macro does not work well.
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 test

Re: Problem with the PWM waveform frequency for PIC16f1936

Posted: Mon Feb 12, 2018 12:31 pm
by JustinS
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

Re: Problem with the PWM waveform frequency for PIC16f1936

Posted: Mon Feb 12, 2018 12:59 pm
by JustinS
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

Re: Problem with the PWM waveform frequency for PIC16f1936

Posted: Mon Feb 12, 2018 2:04 pm
by Benj
Hello,
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 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.

Re: Problem with the PWM waveform frequency for PIC16f1936

Posted: Mon Feb 12, 2018 4:09 pm
by JustinS
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

Re: Problem with the PWM waveform frequency for PIC16f1936

Posted: Mon Feb 12, 2018 6:17 pm
by QMESAR
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
PWMPIC16F1936_int_osc.fcfx
(11.7 KiB) Downloaded 277 times