I implemented the delay function using "S32K144_Project_HelloClocks" inside the s32ds example project.
Here is the code (Not important)
===================================================
void LPIT0_init (uint32_t delay)
{
uint32_t timeout;
/*!
* LPIT Clocking:
* ==============================
*/
PCC->PCCn[PCC_LPIT_INDEX] = PCC_PCCn_PCS(6); /* Clock src=6 (SPLL2_DIV2_CLK)*/
PCC->PCCn[PCC_LPIT_INDEX] |= PCC_PCCn_CGC_MASK; /* Enable clk to LPIT0 regs */
/*!
* LPIT Initialization:
*/
LPIT0->MCR |= LPIT_MCR_M_CEN_MASK; /* DBG_EN-0: Timer chans stop in Debug mode */
/* DOZE_EN=0: Timer chans are stopped in DOZE mode */
/* SW_RST=0: SW reset does not reset timer chans, regs */
/* M_CEN=1: enable module clk (allows writing other LPIT0 regs) */
timeout=delay* 40000;
LPIT0->TMR[0].TVAL = timeout; /* Chan 0 Timeout period: 40M clocks */
LPIT0->TMR[0].TCTRL |= LPIT_TMR_TCTRL_T_EN_MASK;
/* T_EN=1: Timer channel is enabled */
/* CHAIN=0: channel chaining is disabled */
/* MODE=0: 32 periodic counter mode */
/* TSOT=0: Timer decrements immediately based on restart */
/* TSOI=0: Timer does not stop after timeout */
/* TROT=0 Timer will not reload on trigger */
/* TRG_src=0: External trigger soruce */
/* TRG_SEL=0: Timer chan 0 trigger source is selected*/
}
void delay_ms (volatile int ms){
LPIT0_init(ms); /* Initialize PIT0 for 1 second timeout */
while (0 == (LPIT0->MSR & LPIT_MSR_TIF0_MASK)) {} /* Wait for LPIT0 CH0 Flag */
lpit0_ch0_flag_counter++; /* Increment LPIT0 timeout counter */
LPIT0->MSR |= LPIT_MSR_TIF0_MASK; /* Clear LPIT0 timer flag 0 */
}
int main(void)
{
PORT_init(); /* Configure ports */
SOSC_init_8MHz(); /* Initialize system oscilator for 8 MHz xtal */
SPLL_init_160MHz(); /* Initialize SPLL to 160 MHz with 8 MHz SOSC */
NormalRUNmode_80MHz(); /* Init clocks: 80 MHz sysclk & core, 40 MHz bus, 20 MHz flash */
while(1)
{
PTD->PCOR |= 1<<0; /* Clr output on port D0 (blue LED ON) */
PTD->PSOR |= 1<<15; /* Set output on port D15 (RED LEDO OFF) */
delay_ms(500);
PTD->PCOR |= 1<<15; /* Clr output on port D15 (RED LED ON) */
PTD->PSOR |= 1<<0; /* Set output on port D0 (BLUE LED OFF) */
delay_ms(500);
}
}
======================================================================
Next, I wanted to express numbers using 4 digit-7 segment.
I wanted to implement the 4 digit 7 segment as shown in the video in the following link.
(By lighting up sequentially by digit and increasing the number.)
So I connected the segment pin and the digit pin to the DPORT and wrote the code (it's too long, so I won't upload it, it's the same principle).
As a result, there was no response and S32K stopped and it was impossible to enter Debug mode. Is this kind of delay a way to overdo S32K?
Separately, I have previously implemented a time delay by repeating the For statement by the number of system clocks (80mHz), which enabled the 7-segment implementation to work normally.
=========================================
That's iI implemented the delay function using "S32K144_Project_HelloClocks" inside the s32ds example project.
Here is the code (Not importan
===============================================
void LPIT0_init (uint32_t delay
uint32_t timeout
/*
* LPIT Clocking
* =============================
*
PCC->PCCn[PCC_LPIT_INDEX] = PCC_PCCn_PCS(6); /* Clock src=6 (SPLL2_DIV2_CLK)*
PCC->PCCn[PCC_LPIT_INDEX] |= PCC_PCCn_CGC_MASK; /* Enable clk to LPIT0 regs *
/
* LPIT Initialization
*
LPIT0->MCR |= LPIT_MCR_M_CEN_MASK; /* DBG_EN-0: Timer chans stop in Debug mode *
/* DOZE_EN=0: Timer chans are stopped in DOZE mode *
/* SW_RST=0: SW reset does not reset timer chans, regs *
/* M_CEN=1: enable module clk (allows writing other LPIT0 regs) *
timeout=delay* 4000
LPIT0->TMR[0].TVAL = timeout; /* Chan 0 Timeout period: 40M clocks *
LPIT0->TMR[0].TCTRL |= LPIT_TMR_TCTRL_T_EN_MASK
/* T_EN=1: Timer channel is enabled *
/* CHAIN=0: channel chaining is disabled *
/* MODE=0: 32 periodic counter mode *
/* TSOT=0: Timer decrements immediately based on restart *
/* TSOI=0: Timer does not stop after timeout *
/* TROT=0 Timer will not reload on trigger *
/* TRG_src=0: External trigger soruce *
/* TRG_SEL=0: Timer chan 0 trigger source is selected*
void delay_ms (volatile int ms
LPIT0_init(ms); /* Initialize PIT0 for 1 second timeout *
while (0 == (LPIT0->MSR & LPIT_MSR_TIF0_MASK)) {} /* Wait for LPIT0 CH0 Flag *
lpit0_ch0_flag_counter++; /* Increment LPIT0 timeout counter *
LPIT0->MSR |= LPIT_MSR_TIF0_MASK; /* Clear LPIT0 timer flag 0 *
int main(voi
PORT_init(); /* Configure ports *
SOSC_init_8MHz(); /* Initialize system oscilator for 8 MHz xtal *
SPLL_init_160MHz(); /* Initialize SPLL to 160 MHz with 8 MHz SOSC *
NormalRUNmode_80MHz(); /* Init clocks: 80 MHz sysclk & core, 40 MHz bus, 20 MHz flash *
while(
PTD->PCOR |= 1<<0; /* Clr output on port D0 (blue LED ON) *
PTD->PSOR |= 1<<15; /* Set output on port D15 (RED LEDO OFF) *
delay_ms(500)
PTD->PCOR |= 1<<15; /* Clr output on port D15 (RED LED ON) *
PTD->PSOR |= 1<<0; /* Set output on port D0 (BLUE LED OFF) *
delay_ms(500)
====================================================================
Next, I wanted to express numbers using 4 digit-7 segmen
I wanted to implement the 4 digit 7 segment as shown in the video in the following lin
(By lighting up sequentially by digit and increasing the number
So I connected the segment pin and the digit pin to the DPORT and wrote the code (it's too long, so I won't upload it, it's the same principle
As a result, there was no response and S32K stopped and it was impossible to enter Debug mode. Is this kind of delay a way to overdo S32
Separately, I have previously implemented a time delay by repeating the For statement by the number of system clocks (80mHz), which enabled the 7-segment implementation to work normall
=======================================
important!!
Could you please let me know if there is a way to implement the correct time delay in a simple way?
!==y.K?).kM.)k.t.==}};//;//{1)////{d)}////){}////////;/0;/////:*!///=:!;{)====t)
mportant!
Solved! Go to Solution.
You are using SPLL2_DIV2_CLK as the functional clock of the LPIT module, but the clock is not enabled in the main.c file that you sent.
Please try again with a valid LPIT clock.
Thank you,
BR, Daniel
Hi,
I tested the code you posted and it works.
But you don't have to reinitialize the LPIT and its clock every time.
If TSOI == 1, the counter stops on a Timer Interrupt flag (MSR[TIFn]) assertion.
Just set T_EN at the beginning of the delay function and clear it at the end.
Also, you can use the SDK and the OSIF component for delays.
Regards,
Daniel
Please review whether I modified it correctly.
This is my code
================================
void LPIT0_init (uint32_t delay)
{
uint32_t timeout;
/*!
* LPIT Clocking:
* ==============================
*/
PCC->PCCn[PCC_LPIT_INDEX] = PCC_PCCn_PCS(6); /* Clock src=6 (SPLL2_DIV2_CLK)*/
PCC->PCCn[PCC_LPIT_INDEX] |= PCC_PCCn_CGC_MASK; /* Enable clk to LPIT0 regs */
/*!
* LPIT Initialization:
*/
LPIT0->MCR |= LPIT_MCR_M_CEN_MASK; /* DBG_EN-0: Timer chans stop in Debug mode */
/* DOZE_EN=0: Timer chans are stopped in DOZE mode */
/* SW_RST=0: SW reset does not reset timer chans, regs */
/* M_CEN=1: enable module clk (allows writing other LPIT0 regs) */
timeout=delay* 40000;
LPIT0->TMR[0].TVAL = timeout; /* Chan 0 Timeout period: 40M clocks */
LPIT0->TMR[0].TCTRL |= 0x11;/*I edit here*/
/* T_EN=1: Timer channel is enabled */
/* CHAIN=0: channel chaining is disabled */
/* MODE=0: 32 periodic counter mode */
/* TSOT=0: Timer decrements immediately based on restart */
/* TSOI=0: Timer does not stop after timeout */
/* TROT=0 Timer will not reload on trigger */
/* TRG_src=0: External trigger soruce */
/* TRG_SEL=0: Timer chan 0 trigger source is selected*/
}
void delay_ms (volatile int ms){
LPIT0_init(ms); /* Initialize PIT0 for 1 second timeout */
while (0 == (LPIT0->MSR & 0x01/*I edit here*/)) {} /* Wait for LPIT0 CH0 Flag */
lpit0_ch0_flag_counter++; /* Increment LPIT0 timeout counter */
LPIT0->MSR |= 0x00;/*I edit here*//* Clear LPIT0 timer flag 0 */
}
Is it right??
But this method did not work with my 7 segment code.
The following warnings appear during the process of debugging and stopping the code because it is not running: Warning: Unable to go to background. Core is running
Since then, the operation was forced to unplug because it did not stop.
I am attaching my code and problem screen together
THX 4 helping
You are using SPLL2_DIV2_CLK as the functional clock of the LPIT module, but the clock is not enabled in the main.c file that you sent.
Please try again with a valid LPIT clock.
Thank you,
BR, Daniel
Your answer was very helpful.
then,
Is the previously edited part correct?
Hi,
If it works, then yes.
But again, you don't have to reinitialize the whole LPIT module and its clock every time you call the delay function.
Regards,
Daniel
OK THX 4 UR help