This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TM4C, PWM Gen Output Sync Question



Hello 

The starting point is the output  800ns Delay  generated the PWM between Gen0 and Gen 1.

How do I generate the same output ?

thanks.

 

Ch1(Gen0_PWM0), Ch2(Gen0_PWM1), Ch3(Gen1_PWM2), Ch4(Gen1_PWM3), 

int
main(void)
{
    //
    // Enable lazy stacking for interrupt handlers.  This allows floating-point
    // instructions to be used within interrupt handlers, but at the expense of
    // extra stack usage.
    //
    ROM_FPULazyStackingEnable();
 
    //
    // Set the clocking to run directly from the crystal.
    //
    ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
                       SYSCTL_XTAL_16MHZ);
 

    // Initialize the UART and write status.
			ConfigureUART();

		// PWM Clock set 
				ROM_SysCtlPWMClockSet(SYSCTL_PERIPH_PWM0);
		
		//  PWM0 Peripheral Enable
				ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);
		
    //PWM Corresponding GPIO Port Enable
				ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOH);
 
    //GPIO Anternate Function.  
				GPIOPinConfigure(GPIO_PH0_M0PWM0);
				GPIOPinConfigure(GPIO_PH1_M0PWM1);
				GPIOPinConfigure(GPIO_PH2_M0PWM2);
				GPIOPinConfigure(GPIO_PH3_M0PWM3);
			
		// Configuration Pin  for use by the PWM peripheral
				GPIOPinTypePWM(GPIO_PORTH_BASE, GPIO_PIN_0 | GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);
			
		
	// PWM Gen Configure Set,   8 config mode 
	// 1. Counting mode, 2, counter load &  comparator update sync mode, 3. debug behavior
	//	4. update synchronization mode for generator counting mode changes, 5. deadband parameter synchronization mode
	// 6.whether fault conditions are latched or not , 7. whether minimum fault period support is required, 
	// 8. whether extended fault source selection support is enabled or not
	
				PWMGenConfigure(PWM0_BASE, PWM_GEN_0, PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC);
				PWMGenConfigure(PWM0_BASE, PWM_GEN_1, PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC);
		
			// Sets the period of a PWM generator (1 Pulse)  , PWM generator  [PWM_GEN_0 ~ 3]
			// 1/16,000,000 Hz =  62.5E-9 (1 pluse period time 62.5nS),
			// Osclilloscope measure  1 pulse Period 25uS  ,
			// 62.5nS  : 1 pluse  = x(period) : 400 pluse   =    (62.5nS X 400 Plus) = 25uS
						
				PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, 400);
				PWMGenPeriodSet(PWM0_BASE, PWM_GEN_1, 400);
			
			
			//Set the pulse width of PWM0  duty cycle. , ui32PWMOut : PWM_OUT_0, ~7
			
		// PWM0 (20%)   25uS x 0.2 = 5uS
				PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0, 80);
				
		// PWM1 (40%)  25uS x 0.4 = 10uS
				PWMPulseWidthSet(PWM0_BASE, PWM_OUT_1, 160);
				
		// PWM2 (60%)  25uS x 0.6 = 15uS
				PWMPulseWidthSet(PWM0_BASE, PWM_OUT_2, 240);
				
		// PWM3 (80%)	25uS x 0.8 = 20uS			
				PWMPulseWidthSet(PWM0_BASE, PWM_OUT_3, 320);
			
			// Start the timers in generator 0.  Enable the timer/counter for a PWM generator block [ PWM_GEN_0 ~3]
				PWMGenEnable(PWM0_BASE, PWM_GEN_0);
				PWMGenEnable(PWM0_BASE, PWM_GEN_1);
			
			// Enable the outputs.             
			//ui32PWMOutBits : ( PWM_OUT_0_BIT  ~ PWM_OUT_7_BIT)   bEnable :  signal is enabled or disabled.
				PWMOutputState(PWM0_BASE, (PWM_OUT_0_BIT | PWM_OUT_1_BIT), true);
				PWMOutputState(PWM0_BASE, (PWM_OUT_2_BIT | PWM_OUT_3_BIT), true);
  
				UARTprintf(" PWM Out  , GPIO :  PH0(Gen0_PWM0) / PH1(Gen0_PWM1)/PH2(Gen1_PWM2)/PH3(Gen1_PWM3)\n");
		

				ROM_IntMasterEnable();
				ROM_PWMIntEnable(PWM0_BASE,PWM_INT_GEN_0);
				ROM_PWMIntEnable(PWM0_BASE,PWM_INT_GEN_1);

   
    //
    // Loop forever while the timers run.
    //
    while(1)
    {
    }
}

  • Did not your subject line lead you (very) close to your answer?

    Your code's parameter - "PWM_GEN_MODE_NO_SYNC" - is not that "highly" suspect?

    As past advised - your (wide) open copy of vendor's, "Peripheral Driver Lib User Guide" very well details the use & impact of the various API Commands.  Along w/negating that "errant" parameter - there is an API Function (designed) to achieve your objective.   (I know which one - surely - quickly/easily - you will, too...)

    And - do you not (owe) one here the courtesy of a, Verified Answer - for code correction - past provided?

      identifies the correctly answered - yet (abandoned) post...

  • Hello  cb1_mobile

    Did not your subject line lead you (very) close to your answer?

    (Answer) => I'm sorry, I do not know what you mean.

    Your code's parameter - "PWM_GEN_MODE_NO_SYNC" - is not that "highly" suspect?

    (Answer)=> I will try to change other parameters.

          PWMGenConfigure(PWM0_BASE, PWM_GEN_0, PWM_GEN_MODE_DOWN | xxxxxx );

          PWMGenConfigure(PWM0_BASE, PWM_GEN_1, PWM_GEN_MODE_DOWN  |xxxxxx );

     

    See attached image capture

    How do I have the same sync between Gen1 and Gen2  ?

     

    And - do you not (owe) one here the courtesy of a, Verified Answer - for code correction - past provided?

    (Answer) = > Previously, this was the question should not PWM output ( subject : PWM Output Question, TM4C).

    Thanks

    Gen0 (Ch1(PWM0), Ch2(PWM1))   &  Gen1 (Ch3(PWM2), Ch4(PWM3))

    1. xxxxxx  ->  PWM_GEN_MODE_SYNC

    2. xxxxxx  -> PWM_GEN_MODE_GEN_SYNC_LOCAL

    3. xxxxxx  -> PWM_GEN_MODE_GEN_SYNC_GLOBAL

    4. xxxxxx  ->  PWM_GEN_MODE_DB_SYNC_LOCAL

    5. xxxxxx  -> PWM_GEN_MODE_DB_SYNC_GLOBAL

  • Should you read the earlier suggested, "Peripheral User Guide" you'll encounter, "PWMSyncTimeBase() & PWMSyncUpdate()."  

    Name alone should raise both of those PWM functions w/in your consciousness.

    My earlier post (this thread) noted that the "Subject Line" of your thread included "Sync" - yet your, "PWMGenConfigure() used the parameter of "NoSync" - that's inconsistent (and ineffectual) is it not?

    Last two scope caps are labeled with that appears to be "Deadband enabled."  I believe you seek 4, independent PWM Outputs - all sync'ed.   If that's the case - Deadband is not required - will defeat your effort...