AnsweredAssumed Answered

PWM Using FlexIO_D5 in s32k116

Question asked by Upendra Kumar on Jun 6, 2019
Latest reply on Jun 7, 2019 by Diana Batrlova

Dear Sir,

Below code I have used generating PWM using FlexIO_D5 , Can you please confirm it whether it is ok or not but I debug this code, its not responding.I have given the clock 8 Mhz. 

 

void PWM_INIT()
{
/* Output port for Timer1 only */

PCC-> PCCn[PCC_PORTD_INDEX] = PCC_PCCn_CGC_MASK;
PORTD->PCR[3] |= PORT_PCR_MUX(4); /* Port D3: MUX = ALT4, FXIO_D5 */


PCC->PCCn[PCC_FlexIO_INDEX] &= ~PCC_PCCn_CGC_MASK; /* Ensure clk disabled for config */
PCC->PCCn[PCC_FlexIO_INDEX] |= PCC_PCCn_PCS(1) /* Clock Src=1, 8 MHz SOSCDIV1_CLK */
| PCC_PCCn_CGC_MASK; /* Enable Clk*/

/* FlexIO Timer 0, counter decrements on FLexIO clock */

FLEXIO->CTRL = 0;
FLEXIO->TIMCFG[0] = 0x00000000;
// [21-20] TIMDEC 00b - Decrement counter on FlexIO clock

FLEXIO->TIMCMP[0] = 0x00000FFF;

 

FLEXIO->TIMCTL[0] = 0x00000003;
// [17-16] PINCFG 00b - Timer pin output disabled
// [1-0] TIMOD 11b - Single 16-bit counter mode.

/* FlexIO Timer 1, counter decrement on Timer0 output (both edges) */

FLEXIO->TIMCFG[1] = 0x00100000;
// [21-20] TIMDEC 01b - Decrement counter on Trigger input (both edges)

FLEXIO->TIMCMP[1] = 0x0000FFFF; // Duty cycle 50%

// FLEXIO->TIMCMP[0] = 0x00000009; // 2MHz / (9 + 1) = 200kHz (5us)
// FLEXIO->TIMCMP[1] = 0x00000004; // Low CMP[15-8] + 1 = 1 (5us)
// High CMP[7-0] + 1 = 5 (25us)

FLEXIO->TIMCTL[1] = 0x03430052;
// [27-24] TRGSEL 0011b - 4*N+3 (Timer 0 trigger output = 4*0+3 = 3)
// [23] TRGPOL 0b - Trigger active high
// [22] TRGSRC 1b - internal trigger selected (a timer output)
// [17-16] PINCFG 11b - Timer pin output
// [10-8] PINSEL 000b - Pin 0 as output /*PINSEL=i will select the FXIO_D5 pin*/
// [7] PINPOL 0b - Pin is active high
// [1-0] TIMOD 10b - Dual 8-bit counters PWM high mode.

/* FlexIO module */

FLEXIO->CTRL = 1;
}

Attachments

Outcomes