Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void init_pwm(void)
- {
- /* Set the PWM clock source */
- SysCtlPWMClockSet(SYSCTL_PWMDIV_1);
- delay(10);
- /* Enable the PWM peripheral */
- SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM1);
- delay(10);
- /* Enable output pins. PORTA already enabled for UART */
- SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION);
- delay(10);
- /* Configure PWM pins */
- GPIOPinConfigure(GPIO_PA6_M1PWM2);
- GPIOPinConfigure(GPIO_PA7_M1PWM3);
- GPIOPinConfigure(GPIO_PN4_M1PWM4);
- GPIOPinConfigure(GPIO_PN5_M1PWM5);
- GPIOPinConfigure(GPIO_PN6_M1PWM6);
- GPIOPinConfigure(GPIO_PN7_M1PWM7);
- /* Configure pin for PWM output */
- GPIOPinTypePWM(GPIO_PORTA_BASE, GPIO_PIN_7 | GPIO_PIN_6);
- GPIOPinTypePWM(GPIO_PORTN_BASE,
- GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7);
- PWMGenConfigure(PWM1_BASE,
- PWM_GEN_1,
- PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_SYNC | PWM_GEN_MODE_DBG_RUN);
- PWMGenConfigure(PWM1_BASE,
- PWM_GEN_2,
- PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_SYNC | PWM_GEN_MODE_DBG_RUN);
- PWMGenConfigure(PWM1_BASE,
- PWM_GEN_3,
- PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_SYNC | PWM_GEN_MODE_DBG_RUN);
- /* Invert the output? */
- PWMOutputInvert(PWM1_BASE,
- PWM_OUT_2 | PWM_OUT_3 | PWM_OUT_4 |
- PWM_OUT_5 | PWM_OUT_6 | PWM_OUT_7,
- true);
- /* Synchronize the time base between generators 1, 2 and 3 */
- PWMSyncTimeBase(PWM1_BASE, PWM_GEN_1_BIT | PWM_GEN_2_BIT | PWM_GEN_3_BIT);
- /* Set the PWM frequency to 19532 Hz */
- PWMGenPeriodSet(PWM1_BASE, PWM_GEN_1, PWM_PERIOD);
- PWMGenPeriodSet(PWM1_BASE, PWM_GEN_2, PWM_PERIOD);
- PWMGenPeriodSet(PWM1_BASE, PWM_GEN_3, PWM_PERIOD);
- PWMPulseWidthSet(PWM1_BASE, PWM_OUT_2, 200); /* PA6 */
- PWMPulseWidthSet(PWM1_BASE, PWM_OUT_3, 800); /* PA7 */
- PWMPulseWidthSet(PWM1_BASE, PWM_OUT_4, 300); /* PN4 */
- PWMPulseWidthSet(PWM1_BASE, PWM_OUT_5, 400); /* PN5 */
- PWMPulseWidthSet(PWM1_BASE, PWM_OUT_6, 500); /* PN6 */
- PWMPulseWidthSet(PWM1_BASE, PWM_OUT_7, 600); /* PN7 */
- PWMGenEnable(PWM1_BASE, PWM_GEN_1);
- PWMGenEnable(PWM1_BASE, PWM_GEN_2);
- PWMGenEnable(PWM1_BASE, PWM_GEN_3);
- PWMSyncUpdate(PWM1_BASE, PWM_GEN_1_BIT | PWM_GEN_2_BIT | PWM_GEN_3_BIT);
- /* Trigger an AD conversion on each cycle */
- PWMGenIntClear(PWM1_BASE, PWM_GEN_1, PWM_TR_CNT_LOAD);
- PWMGenIntTrigEnable(PWM1_BASE, PWM_GEN_1, PWM_TR_CNT_LOAD);
- PWMOutputState(PWM1_BASE,
- PWM_OUT_2_BIT | PWM_OUT_3_BIT | PWM_OUT_4_BIT |
- PWM_OUT_5_BIT | PWM_OUT_6_BIT | PWM_OUT_7_BIT,
- true);
- /****************** PWM0 TRIGGER TEST *************************************/
- SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);
- delay(10);
- SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOH);
- delay(10);
- GPIOPinConfigure(GPIO_PH1_M0PWM1);
- GPIOPinTypePWM(GPIO_PORTH_BASE, GPIO_PIN_1);
- PWMGenConfigure(PWM0_BASE,
- PWM_GEN_0,
- PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_SYNC | PWM_GEN_MODE_DBG_RUN);
- PWMSyncTimeBase(PWM0_BASE, PWM_GEN_0_BIT);
- PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, PWM_PERIOD);
- PWMPulseWidthSet(PWM0_BASE, PWM_OUT_1, 400);
- PWMGenEnable(PWM0_BASE, PWM_GEN_0);
- PWMSyncUpdate(PWM0_BASE, PWM_GEN_0_BIT);
- PWMGenIntClear(PWM0_BASE, PWM_GEN_0, PWM_TR_CNT_LOAD); /* | PWM_INT_CNT_LOAD); */
- PWMGenIntTrigEnable(PWM0_BASE, PWM_GEN_0, PWM_TR_CNT_LOAD); /* | PWM_INT_CNT_LOAD); */
- PWMOutputState(PWM0_BASE, PWM_OUT_1_BIT, true);
- SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_PWM0);
- /**************************************************************************/
- }
Advertisement
Add Comment
Please, Sign In to add comment