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
PIC32MZ2048EFH064 PWM not working properly
-
- Posts: 261
- http://meble-kuchenne.info.pl
- Joined: Thu Dec 10, 2020 2:35 pm
- Has thanked: 36 times
- Been thanked: 17 times
-
- Posts: 261
- Joined: Thu Dec 10, 2020 2:35 pm
- Has thanked: 36 times
- Been thanked: 17 times
-
- Matrix Staff
- Posts: 1940
- Joined: Mon Dec 07, 2020 10:06 am
- Has thanked: 506 times
- Been thanked: 688 times
Re: PIC32MZ2048EFH064 PWM not working properly
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.
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.
Regards Ben Rowland - MatrixTSL
Flowcode Online Code Viewer (Beta) - Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel
Flowcode Online Code Viewer (Beta) - Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel
-
- Posts: 261
- Joined: Thu Dec 10, 2020 2:35 pm
- Has thanked: 36 times
- Been thanked: 17 times
Re: PIC32MZ2048EFH064 PWM not working properly
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
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
- Attachments
-
- pwm mz2048efh064.fcfx
- (11.85 KiB) Downloaded 468 times
-
- Posts: 261
- Joined: Thu Dec 10, 2020 2:35 pm
- Has thanked: 36 times
- Been thanked: 17 times
Re: PIC32MZ2048EFH064 PWM not working properly
Hello Ben ,
Duty 0-255 does not work either,
exactly the same here. PIC32 MX does not work either.
Greeting SpeedPic32
Duty 0-255 does not work either,
exactly the same here. PIC32 MX does not work either.
Greeting SpeedPic32
-
- Posts: 261
- Joined: Thu Dec 10, 2020 2:35 pm
- Has thanked: 36 times
- Been thanked: 17 times
Re: PIC32MZ2048EFH064 PWM not working properly
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
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
-
- Posts: 261
- Joined: Thu Dec 10, 2020 2:35 pm
- Has thanked: 36 times
- Been thanked: 17 times
Re: PIC32MZ2048EFH064 PWM not working properly
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
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
- Attachments
-
- PWMDemo_n.fcfx
- (13.16 KiB) Downloaded 476 times
-
- Posts: 261
- Joined: Thu Dec 10, 2020 2:35 pm
- Has thanked: 36 times
- Been thanked: 17 times
Re: PIC32MZ2048EFH064 PWM not working properly
Hello Ben
small calculation help for setting the PWM data for all
Greetings SpeedPic32
small calculation help for setting the PWM data for all
Greetings SpeedPic32
- Attachments
-
- PIC32 PWM.zip
- (3.44 MiB) Downloaded 373 times