Hi,
I would like to implement a precise blocking timer that can also be set for a delay of 1us. I am using the code written for the S32K1 MCU and have transferred it to the S32K3 MCU. Unfortunately it does not work properly and I measured about 389us for 1ms (expected time).
Maybe I have chosen the wrong clock source (Core_CLK) or the code is 1:1 transferable for the S32K3.
If someone has a tip for this problem or maybe a better way to implement a blocking timer, that would be great.
#define WAIT_FOR_MUL4_CYCLES(cycles) \
__asm( \
"movs r0, %[cycles] \n" \
"0: \n" \
"subs r0, r0, #4 \n" \
"nop \n\t" \
"bne 0b \n" \
: \
: [cycles] "r" (cycles) \
: "r0", "r1", "cc" \
)
void BCC_MCU_WaitMs(uint16_t delay)
{
g_sysClk = Clock_Ip_GetClockFrequency(CORE_CLK);
uint32_t cycles = (uint32_t) g_sysClk / 1000;
/* Advance to next multiple of 4. Value 0x04U ensures that the number
* is not zero. */
cycles = (cycles & 0xFFFFFFFCU) | 0x04U;
for (; delay > 0U; delay--) {
BCC_WAIT_FOR_MUL4_CYCLES(cycles);
}
}
int main(void){
uint8 tggGPIO = 0u;
while(1){
Siul2_Dio_Ip_WritePin( GPIO_BlINKY_PORT, GPIO_BlINKY_PIN, tggGPIO);
tggGPIO ^= 0x01;
WaitMs(1); // approx 389us
//WaitMs(2); // approx 760us
}
}
Solved! Go to Solution.
Hi @JoDo,
The S32K3 has a different core.
Why don't use Systick?
You can use the OSIF RTD driver.
BR, Daniel
Hi @JoDo,
The S32K3 has a different core.
Why don't use Systick?
You can use the OSIF RTD driver.
BR, Daniel