News:

;) This forum is the property of Proton software developers

Main Menu

How to change resolution of the PWM family PIC24FJ64GA004

Started by jam19857, Apr 24, 2024, 03:02 PM

Previous topic - Next topic

jam19857

Hello everyone, I am trying to understand how to configure PWM of the PIC24FJ64GA004 family, in the data sheet it indicates that it has 5 16 Bit PWM outputs.

I need to run 5 PWM with 10 bits of resolution.

Do you have any example that can help me?

diebobo

A snippet of my code for 2 outputs, should be just a changing of numbers game to add more .. My code is for 16 bit...

PPS_Output(cOut_Pin_RP24, cOut_Fn_OC1 ) ' HPWM Port activeren op B.5
PPS_Output(cOut_Pin_RP23, cOut_Fn_OC2 ) ' HPWM Port activeren op B.6

TMR3  = 0;
PR3   = -1;          /* period = full 16 bit PWM */
   
T3CON = 32768;  /* start timer */

OC1CON   = 0x0E; /* use Timer3 for PWM0 fault pin disabled */
OC2CON   = 0x0E; /* use Timer3 for PWM1 fault pin disabled */

OC1RS    = 0;  /* 0% Duty */
OC2RS    = 0;  /* 0% Duty */

OC1RS and OC2RS are the register for PWM value 0 = 0% , 65535 = 100%

jam19857

Thank you very much, I will review it and try it, as soon as I have results I will share it.

I am trying to change the pwm resolution to 10 bits for the PIC18F26k42. Do you have anything that can serve as a reference?

Stephen Moss

Quote from: jam19857 on Apr 24, 2024, 03:02 PMHello everyone, I am trying to understand how to configure PWM of the PIC24FJ64GA004 family, in the data sheet it indicates that it has 5 16 Bit PWM outputs.
Quote from: jam19857 on Apr 25, 2024, 03:32 AMI am trying to change the pwm resolution to 10 bits for the PIC18F26k42. Do you have anything that can serve as a reference?

I am confused, which device are you using and want help with?
If the latter (18F) then are you using its PWMx pin to output the PWM,  other peripherals to generate the PWM or both?

Assuming for now it is the 18Fxx device and using PWMx pins then from a brief skim through the datasheet, section 24 should give you all the information you need, and there are a couple of equations there to help you out as well.
Although the examples are based on using the default timer selection (TMR2) rather than Timers 4 or 6 it nonetheless appears that you can only get the 10-bit resolution by setting the T2PR (or T4PR/T6PR as applicable) register value to its maximum count of a 8bit timer of 255.

However, from both the description and Tables 24-1 & 24-2, the value in the T2PR register in conjunction the Timers prescaler also determines the PWM frequency.
Therefore, depending on the combination of the Devices Oscillator frequency and available Timer prescaler settings there is the possibility that you may have to decide on a trade off, either sacrificing resolution to get the desired PWM frequency or sacrificing you desired PWM frequency to get the 10-bit resolution, depending on which is the more important for your end application.

jam19857

Thank you very much for repley.

I have used the different PWM instructions in positrons with the help of a library that top204
Administrator published in the forum, for the Pic24 and for the Pic18Fxxk42.
I can't figure out how to modify the resolution and still use the library.
It would be great if the resolution could be modified and used in some application at the sacrifice of speed.

That is why I requested help with pic24 and later with pic18f26k42 and have a basic example of how to modify the resolution.

top204

With PWM, the resolution changes with frequency. So the higher the frequency, the lower the resolution.

So to get a fixed resolution, the frequency cannot change too much.