Page 2 of 2

Re: PIC32MZ2048EFH064 PWM not working properly

Posted: Fri Jun 18, 2021 2:32 pm
by SpeedPIC32
hello again

If I'm not mistaken, PWM is generated via the Compare module.
This is supplied via the PBCLK3 and has a divider of 1 - 128.
PBCLK§ is one of 7 peripheral busclk
the Internal Fast RC Oscillator does not have the 128 divider.
See https://ww1.microchip.com/downloads/en/ ... 61111E.pdf

Greetings SpeedPIC32
Periph.png
Periph.png (297.48 KiB) Viewed 5102 times
FRC.png
FRC.png (153.01 KiB) Viewed 5102 times
Compare.png
Compare.png (71.86 KiB) Viewed 5102 times

Re: PIC32MZ2048EFH064 PWM not working properly

Posted: Fri Jun 18, 2021 2:44 pm
by SpeedPIC32
PWMDemo.fcfx
(5.72 KiB) Downloaded 528 times

Re: PIC32MZ2048EFH064 PWM not working properly

Posted: Mon Jun 21, 2021 8:22 pm
by BenR
Hello,

The PWM is based on a timer peripheral which has a prescaler. The timer is clocked via PBCLK3 which I have now configured to run at a 1:1 divider so that the timings shown by the component are correct. Previously it was a 1:2 and so the output frequency was half of what it should have been.

The code you sent is for a 8-bit PIC? Can you send me your PIC32 code which you are having trouble with.

Re: PIC32MZ2048EFH064 PWM not working properly

Posted: Mon Jun 21, 2021 10:06 pm
by SpeedPIC32
Hello Ben,

The basic settings can be found under PWM1 properties.
Period Overflow is set to 65535
Prescaler on 1
results in a frequency of 3.051758KHz
Now I can change the two values and I am shown the period and frequency.
If I change one of the two values, I have to make this change 2 times each time so that they are accepted or recalculated and displayed. I would change this in any case. Any calculator I get as a free gift can do this.
It should also work like this in the software.
Compiling no problem, but PWM does not work.
Change Period to 25000.1 Duty to 32678 Has Frequency 0
The scales have just fallen from my eyes.
If the value of Change Period is equal to or less than Duty, I have frequency 0.
FC9 is not calculating something fundamental here.
The PIC has a frequency. I can reduce it with the prescaler.
In the case of my PIC, this is 200MHz dur 1,2,4,8 etc.
With Period Overflow, I set Timer2 so that it overflows at 25000, for example.
In addition, there is the setting Duty, which determines at which value within 25000 the PWM output is switched on or off. To put it simply, it should do 50% duty, i.e. 12500 on 12500 off, with an accuracy of 16 bits, in this case 50%, I enter 32768.
That's where FC9 has the problem.

Greetings SpeedPIC32

Re: PIC32MZ2048EFH064 PWM not working properly

Posted: Mon Jun 21, 2021 10:41 pm
by SpeedPIC32
Hello Ben ,
Duty 0-255 does not work either,
exactly the same here. PIC32 MX does not work either.


Greeting SpeedPic32

Re: PIC32MZ2048EFH064 PWM not working properly

Posted: Tue Jun 22, 2021 9:28 am
by SpeedPIC32
A frequency is always set and Duty remains the same.
The error is also present in the 8-bit demo.
If I change the period overflow to achieve a higher frequency, I change the potentiometer range.
Overflow to 128 changes the potentiometer range to half. Quite a great effect.
To change a frequency I have to change the clock frequency of the PIC?

Greetings Speed Pic32


Look here
https://www.exploreembedded.com/wiki/PIC16F877A_PWM

Re: PIC32MZ2048EFH064 PWM not working properly

Posted: Wed Jun 23, 2021 9:30 am
by SpeedPIC32
Hello Ben

Sorry, it's a comprehension problem.
At the moment the prescaler is working fine.
The on-off ratio remains the same.
The problem is that nowhere is described for a BEGINNER that the first value in changePeriot is also the maximum value in DutyCycle.
If FC 9 were to say 0 - 100%, I don't think that would be a problem if you entered a minimum of 100 in Change Period. I made a new demo with 2 potentiometers to see how it works. Or not.

Greetings SpeedPic32

Re: PIC32MZ2048EFH064 PWM not working properly

Posted: Wed Jun 23, 2021 12:04 pm
by SpeedPIC32
Hello Ben
small calculation help for setting the PWM data for all


Greetings SpeedPic32