How to SYNC PWM?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-09-02 9:27 AM
Hello,
i have now this working code on SPC560P without sync flag.
pwm_lld_start(&PWMD1, &pwm_config_pwm_cfg0);
pwm_lld_start(&PWMD2, &pwm_config_pwm_cfg0);
pwm_lld_start(&PWMD3, &pwm_config_pwm_cfg0);
pwm_lld_start(&PWMD4, &pwm_config_pwm_cfg0);
pwm_lld_enable_channel(&PWMD1, 0, PWM_PERCENTAGE_TO_WIDTH(&PWMD1, 5000));
pwm_lld_enable_channel(&PWMD2, 0, PWM_PERCENTAGE_TO_WIDTH(&PWMD2, 5000));
pwm_lld_enable_channel(&PWMD1, 1, PWM_PERCENTAGE_TO_WIDTH(&PWMD1, 5000));
pwm_lld_enable_channel(&PWMD2, 1, PWM_PERCENTAGE_TO_WIDTH(&PWMD2, 5000));
pwm_lld_enable_channel(&PWMD3, 0, PWM_PERCENTAGE_TO_WIDTH(&PWMD3, 5000));
pwm_lld_enable_channel(&PWMD3, 1, PWM_PERCENTAGE_TO_WIDTH(&PWMD3, 5000));
pwm_lld_enable_channel(&PWMD4, 0, PWM_PERCENTAGE_TO_WIDTH(&PWMD3, 5000));
But of course output is not in phase (syncronized).
If i enable flag "Synchronized FlexPWM0" and i use this code :
pwm_lld_start(&PWMD1, &pwm_config_pwm_cfg0);
pwm_lld_enable_channel(&PWMD1, 0, PWM_PERCENTAGE_TO_WIDTH(&PWMD1, 5000));
pwm_lld_enable_channel(&PWMD1, 1, PWM_PERCENTAGE_TO_WIDTH(&PWMD1, 5000));
pwm_lld_enable_channel(&PWMD1, 2, PWM_PERCENTAGE_TO_WIDTH(&PWMD1, 5000));
pwm_lld_enable_channel(&PWMD1, 3, PWM_PERCENTAGE_TO_WIDTH(&PWMD1, 5000));
pwm_lld_enable_channel(&PWMD1, 4, PWM_PERCENTAGE_TO_WIDTH(&PWMD1, 5000));
pwm_lld_enable_channel(&PWMD1, 5, PWM_PERCENTAGE_TO_WIDTH(&PWMD1, 5000));
pwm_lld_enable_channel(&PWMD1, 6, PWM_PERCENTAGE_TO_WIDTH(&PWMD1, 5000));
pwm_lld_enable_channel(&PWMD1, 7, PWM_PERCENTAGE_TO_WIDTH(&PWMD1, 5000));
Only CH0 and CH1 output is working in phased.
No output on CH2,CH3,CH4,CH5,CH6,CH7.
What i have to do?
Thank you in advantages
Solved! Go to Solution.
- Labels:
-
TIM
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-09-02 9:33 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-09-02 9:33 AM
Sorry my mistake.
I have to enable also other channel...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-09-02 3:49 PM
To configure the PWM module to generate a right-aligned output, the MODE bits of the PWM Configuration registers are used to select the output alignment mode and the P1 or P2 parameter registers are used to determine the resulting period of the output signal.
More you can learn at Pulse-Width Modulation (PWM) Tips and Tricks (microchip.com)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-09-04 11:19 PM
Hi,
i have question regarding PWM, if i want to use the push button as input and led as a output PWM. In pinmap do i have to set as PWM or eirq for push button?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-09-04 11:22 PM
Output LED ->PWM
Push button:
->if you read in polling just set as digital input.
->if you want to have interrupt set as eirq
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-09-05 2:45 AM
if i want push button as a interrupt for led pwm, How to change the duty according to the push button? May i have any c code to refer ? i get confuse since in example pwm , it set the duty cycle automatically ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-09-05 3:00 AM
1->Set input following example RLA EIRQ Test Application
2->Set your output PWM following example RLA FlexPWM
In your code change duty-cicle every time push button is pressed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-09-05 5:18 PM
Okay then how can i know what percentage duty cycle need to set to follow the push button when i press it?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-09-06 7:43 PM
Hi,
Sorry again, now my project is not looping. When i pressed the button, led only will ON on time, after that it will turn off permanently even i press the button, Here my c code
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-09-07 2:46 AM
Hi.
I need to understand what yuo mean for reading push button duty cycle.
Have you a standard frequency?How much is it?
Because if frequency is low you can easy read digital input with pal library in polling every systick (1ms) then you can set your pwm.
Example:
uint32_t TickScanDigital=0;
uint16_t dConter=0;
uint16_t period=10000;
uint16_t duty=0;
bool d1OldState=false;
int main(void) {
/* Initialization of all the imported components in the order specified in
the application wizard. The function is generated automatically.*/
componentsInit();
/* Uncomment the below routine to Enable Interrupts. */
irqIsrEnable();
pwm_lld_start(&PWMD2, &pwm_config_pwm_cfg0);//config SM2
pwm_lld_enable_channel(&PWMD2, 0, PWM_PERCENTAGE_TO_WIDTH(&PWMD2, 0));
pwm_lld_enable_channel(&PWMD2, 1, PWM_PERCENTAGE_TO_WIDTH(&PWMD2, 0));
if((osalThreadGetMilliseconds()-TickScanDigital)>1){
TickScanDigital=osalThreadGetMilliseconds();
dConter++;
if(pal_readpad(PORT_D1,D1)==PAL_HIGH){
if(d1OldState==false){//trigger high
period=dConter;
dConter=0;
}
d1OldState=true;
}else{
if(d1OldState==true){
duty=dConter*10000/period;
pwm_lld_enable_channel(&PWMD2, 0, PWM_PERCENTAGE_TO_WIDTH(&PWMD2, duty));
pwm_lld_enable_channel(&PWMD2, 1, PWM_PERCENTAGE_TO_WIDTH(&PWMD2, duty));
}
d1OldState=false;
}
}
