Hi all,
I struggle the adjust the PIT timers
My workstation consist of MATLAB 2020a MBDT, MPC5775E-EVB board.
I try to implement custom code(as a descibed in here https://community.nxp.com/t5/NXP-Model-Based-Design-Tools/How-to-use-your-own-C-code-in-our-Toolbox-...)
for MC33937 driver.
CPOL:DSPI_ACTIVE_LOW
CPHA:DSPI_CLOCK_PHASE_2ND_EDGE
CS:Active Low
Setting deadtime for mc33937 ,
1) Send 0x81
2) 20 us CS High
3) 12 us CS Low
4) Send 0x03
Third step didn't works as i expected. I configured the 12 us, but it works aprroximatelly 43 us.
How can i set properly? @mariuslucianand

Relevant code pieces
/* Configure the SPI init structure. */
dspi_master_config_t spiConfig1 = {
/*.bitsPerSec = 328125U,*/
.bitsPerSec = 300000U, //300kHz for debug purpose(normally 3MHz)
.whichPCS = 3,
.pcsPolarity = DSPI_ACTIVE_LOW,
.continuousPCS = false,
.bitcount = 8U,
.clkPhase = DSPI_CLOCK_PHASE_2ND_EDGE,
.clkPolarity = DSPI_ACTIVE_LOW,
.lsbFirst = false,
/*.transferType = DSPI_USING_INTERRUPTS,
.callback = (spi_callback_t)spi_master_transfer_callback1,*/
};
//SPI configured as a pooling mode, TX,RX FIFOs disabled , just used PUSHR POPR for TX-RX
//! User channel configuration 0
pit_channel_config_t pit0_ChnConfig1= {
.hwChannel = 1U,
.periodUnit = PIT_PERIOD_UNITS_MICROSECONDS,
.period = 30, /*20 us*/
.enableChain = false,
.enableInterrupt = false
};
//! User channel configuration 2
pit_channel_config_t pit1_ChnConfig2= {
.hwChannel = 2U,
.periodUnit = PIT_PERIOD_UNITS_MICROSECONDS,
/*.period = ((750<<4)/1000)+ 9 - 4, /*12 us*/
.period = 25,
/*.period = 5,*/
.enableChain = false,
.enableInterrupt = false
};
// Initialize PIT for user
PIT_DRV_Init(0u, &pit0_InitConfig);
// Initialize channel 1 for user
PIT_DRV_InitChannel(0U, &pit0_ChnConfig1);
// for user
//INT_SYS_SetPriority(PIT_RTI1_IRQn, 9U);
// Initialize PIT for deadtime delay
PIT_DRV_Init(0u, &pit1_InitConfig);
// Initialize channel 1 for deadtime delay
PIT_DRV_InitChannel(0U, &pit1_ChnConfig2);
MC33937_Tx_Rx(1,send_buff,recv_buff); // send 0x81
DeadTime_Delay_us(0U, 1U); // 20 us delay
MC33937_CS_Low(1);
DeadTime_Delay_us(0U, 2U); // 12 us delay?
MC33937_CS_High(1);
MC33937_Tx_Rx(1,(0x03),recv_buff);
//functions
void DeadTime_Delay_us(const uint32_t instance, const uint8_t channel)
{
//uint32_t getStatusFlag = 0;
PIT_Type * const s_pitBase[] = PIT_BASE_PTRS;
PIT_Type * const base = s_pitBase[instance];
status_t clkErr;
// check if the timer is already running. If it is, we cannot use it.
DEV_ASSERT((base->TIMER[channel].TCTRL & PIT_TCTRL_TEN_MASK) == 0u);
//Start timer
base->TIMER[channel].TCTRL |= PIT_TCTRL_TEN_MASK;
//get status flag
//getStatusFlag = (base->TIMER[channel].TFLG & PIT_TFLG_TIF_MASK);
for(;;)
{
if((base->TIMER[channel].TFLG & PIT_TFLG_TIF_MASK)) //if counter reached a zero
{
base->TIMER[channel].TCTRL &= ~PIT_TCTRL_TEN_MASK;//stop channel
base->TIMER[channel].TFLG = PIT_TFLG_TIF_MASK; //clear status flag
break;
}
}
}
void MC33937_CS_Low(dspi_instance_t instance)
{
DSPI_Type * base = DSPI_Instances[instance];
uint32_t polarity;
uint32_t config_pcsPolarity = (uint32_t)DSPI_ACTIVE_HIGH;
/*
// Configure PCS polarity.
for (int i = 0; i < 8U; i++)
{
polarity |= config_pcsPolarity << i;
}
*/
polarity = 0;
DSPI_Set_MCR_PCSIS(base, polarity);
}
void MC33937_CS_High(dspi_instance_t instance)
{
DSPI_Type * base = DSPI_Instances[instance];
uint32_t polarity;
uint32_t config_pcsPolarity = (uint32_t)DSPI_ACTIVE_LOW;
/*
// Configure PCS polarity.
for (int i = 0; i < 8U; i++)
{
polarity |= config_pcsPolarity << i;
}
*/
polarity = 255;
DSPI_Set_MCR_PCSIS(base, polarity);
}