Skip to main content
PChia.2237
Senior
September 2, 2022
Solved

How to SYNC PWM?

  • September 2, 2022
  • 5 replies
  • 4088 views

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

This topic has been closed for replies.
Best answer by PChia.2237

Sorry my mistake.

I have to enable also other channel...

5 replies

PChia.2237
PChia.2237AuthorBest answer
Senior
September 2, 2022

Sorry my mistake.

I have to enable also other channel...

MRay.1
Visitor II
September 2, 2022

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.

0693W00000SuPsHQAV.pngMore you can learn at Pulse-Width Modulation (PWM) Tips and Tricks (microchip.com)

Angle
Associate III
September 5, 2022

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?

PChia.2237
Senior
September 5, 2022

Output LED ->PWM

Push button:

->if you read in polling just set as digital input.

->if you want to have interrupt set as eirq

Angle
Associate III
September 5, 2022

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 ?

PChia.2237
Senior
September 5, 2022

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

Angle
Associate III
September 6, 2022

Okay then how can i know what percentage duty cycle need to set to follow the push button when i press it?