FLEXPWM EXT_SYNC

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

FLEXPWM EXT_SYNC

645 次查看
Motafared
Contributor I

I am Trying to create 8  synced PWM using IMXRT1062 on TEENSY4 board 
I created master PWM to sync them to it using XBAR and EXT_SYNC
i could build the PWM easily but i couldn't send the the trigger from the master pwm to the others  
i tested it between different modules but everytime i fail ,The slave PWM keep counting to the end of its 16 bit counter without receiving EXT_SYNC signal  and then wrap again from zero 
i even tried to send the trigger signal to external physical pin as a debugging but i could not see it on the scope 
can any one help me what i messed 
i am using ARDUINO IDE

  // ====== FLEXPWM2 Setup: PWM2_0_A on Pin 4  slave======
  // Enable clock for FLEXPWM2 (CG9: bits 19-18)
  CCM_CCGR4 |= (3 << 18);  // FLEXPWM2 for Pin 4 (PWM2_0_A)
   // Set pin 4 to ALT1 = FLEXPWM2_PWM0_A
  CORE_PIN4_CONFIG = 1;
  FLEXPWM2_MCTRL &= ~(FLEXPWM_MCTRL_RUN(1 << 0)); //stop it at the begining
  FLEXPWM2_SM0CTRL2 = FLEXPWM_SMCTRL2_INDEP|FLEXPWM_SMCTRL2_INIT_SEL(3); //independent + init select = EXT_SYNC
  FLEXPWM2_SM0CTRL  = FLEXPWM_SMCTRL_PRSC(0) | FLEXPWM_SMCTRL_FULL;
  FLEXPWM2_SM0INIT  = 0;
  FLEXPWM2_SM0VAL0  = 0;
  FLEXPWM2_SM0VAL1  = 0;
  FLEXPWM2_SM0VAL2  = 0+PHASE;
  FLEXPWM2_SM0VAL3  = (DUTY+PHASE);
  FLEXPWM2_OUTEN   |= FLEXPWM_OUTEN_PWMA_EN(1 << 0);
  FLEXPWM2_MCTRL   |= FLEXPWM_MCTRL_LDOK(1 << 0);
  FLEXPWM2_MCTRL   |= FLEXPWM_MCTRL_RUN(1 << 0);

 
//FLEXPWM3_PWM1 MASTER
  uint32_t freq_kHz = 500;
  // Enable clock for FLEXPWM3 (CG9: bits 20-21)
  CCM_CCGR4 |= (3 << 20);
//enable clock for xbar1
  CCM_CCGR2 |= CCM_CCGR2_XBAR1(CCM_CCGR_ON);

 
  // VAL1 determines frequency
  uint32_t M = IPG_CLOCK_HZ / (freq_kHz * 1000);
  // Configure PWM3 SM1 as EXT_SYNC generator
  FLEXPWM3_MCTRL &= ~(FLEXPWM_MCTRL_RUN(1 << 1));
  FLEXPWM3_SM1CTRL2 = FLEXPWM_SMCTRL2_INDEP;
  FLEXPWM3_SM1CTRL = FLEXPWM_SMCTRL_PRSC(0) | FLEXPWM_SMCTRL_FULL;
  FLEXPWM3_SM1INIT = 0;
  FLEXPWM3_SM1VAL0 = 0;
  FLEXPWM3_SM1VAL1 = M;
  FLEXPWM3_SM1VAL2 = 0;
  FLEXPWM3_SM1VAL3 = M/2;
  FLEXPWM3_SM1VAL5 = M/2;

 

  // Enable OUT_TRIG1 on VAL1 match
  FLEXPWM3_SM1TCTRL = (uint16_t)(1 << 1); // OUT_TRIG_EN bit 1 = PWM_OUT_TRIG1 on VAL1 match



  // Route FLEXPWM3_SM1_OUT_TRIG1:XBAR1_IN48 → XBARA1_OUT_FLEXPWM2_PWM0_EXT_SYNC 44
  XBARA1_SEL22 &= 0xff00; //Clear the SEL44 fields
  XBARA1_SEL22 |= 48; ///
  FLEXPWM3_OUTEN |= FLEXPWM_OUTEN_PWMB_EN(1 << 1);
  FLEXPWM3_MCTRL |= FLEXPWM_MCTRL_LDOK(1 << 1);
  FLEXPWM3_MCTRL |= FLEXPWM_MCTRL_RUN(1 << 1);
 
标签 (2)
标记 (3)
0 项奖励
回复
2 回复数

581 次查看
Motafared
Contributor I

1000182467.jpg

I found the problem

The submodules in all register names are 0 indexd submodule 0,1,2,3

But in the table of xbar inputs for output trigger they are 1 indexed

So if you are working with submodule 0 and you want to assign its output trigger to xbar1 you should choose

FLEXPWM1_PWM1_OUT_TRIG0 or

FLEXPWM1_PWM1_OUT_TRIG1

0 项奖励
回复

598 次查看
EdwinHz
NXP TechSupport
NXP TechSupport

Hi @Motafared,

I highly recommend you download MCUXpresso and try the pwm example codes we provide with the i.MX RT1060 SDK for more information on how to achieve this setup.

0 项奖励
回复