Hello, all the example codes use for loops for their delay functions and I do not know how reliable these would be.
https://community.nxp.com/t5/S32K/Delay-function-using-OSIF/td-p/1946299
However I am unable to actually add a value instead it gives me a blank drop down menu.
If I end up needing to use the simple for loop + counter method, there is a bit of confusion I have there too.
The internal clock of the mcu 48MHz or 16MHz? I thought this delay function was supposed to be 1 second flickering but it would be either 0.1 or 0.3 respectively. I want to convert my delay function to miliseconds for usability reasons but I can not really tell what my "base clock" I am working off of even is.
已解决! 转到解答。
Hi @pb632146
Apologies for my typo in the formula. You are correct, it will convert ticks to seconds. Therefore, you can just multiply by 1,000,000 or divide the ticks by 160 just as you mention.
To update to RTD 5.0.0, you must first uninstall the RTD 3.0.0 and then download the updatesite of version 5.0.0. Below is a step-by-step guide to assist you:
Uninstalling RTD 3.0.0:
Downloading and Installing RTD 5.0.0:
Code Update:
Please replace the following line of code with:
"Clock_Ip_Init(&Mcu_aClockConfigPB_BOARD_InitPeripherals[0]);"
This how the clock configuration structure is defined in your project.
Let me know if this helps and if you have more doubts.
- RomanVR.
Hi @pb632146.
The test delays used in examples are primarily for demonstration purposes and but are not recommended for final implementations as they are blocking, and their theoretical delay value are only rough estimates.
As mentioned in the community post, to add the Osif System Timer Clock Reference, you need to include the Mcu module in the MCAL. Alternatively, instead of adding a System Timer Clock Reference, you can directly use the Timer Clock Frequency, which is by default of 48MHz on the S32K344 device. Additionally, I suggest to refer to the S32K3xx Reference Manual available at S32K3 Microcontrollers for Automotive General Purpose to check the default system clock frequency and the available clock sources for each S32K3 device.
Regarding the delay you mentioned, a delay with a value of 4,800,000 with the 48MHz internal clock would theoretically result in a delay > 0.1 seconds. However, this value will be always bigger since instructions take more than one clock cycle to execute. For better accuracy, I suggest to use the Osif functions available by including Osif.h library to your project once configured as seen on the community post you shared, where you can find a blocking delay function with a better precision.
If you are interested in measuring your program’s runtime more accurately, you can configure a timer with a known value, increment a counter on each interrupt, and use this to estimate the runtime. Alternatively, you can toggle a GPIO pin at the start and end of the section you wish to measure and then observe the duration of the signal with an oscilloscope.
Please let me know if you have more doubts.
- RomanVR.
Hi @pb632146
Due to the fact that your MCU is configured with the PLL Clock (160MHz), I recommend adding the following line to your code:
Clock_Ip_Init(&Mcu_aClockConfigPB[0]);
Additionally, ensure you include "Clock_Ip.h" library. this will update the clock reference for all the MCU modules and registers.
Regarding your question: "While the code offer microseconds to ticks, to get the other way around I would want to convert the 160MHz to 1MHz so just divide by 160 correct?"
If you want to convert ticks to microseconds, you can do this by the following equation:
However, I recommend not to do this if you need the MCU for high speed applications. Also you can refer to the Chapter 24 of the S32K3XX Reference Manual to check the maximum clock ratings of each S32K3 device.
To enable the OsIf System Timer Clock Frequency to avoid adding the MCU driver, you can find it under the OsIfSystemTimerClockFreq if in Design Studio 3.5 with RTD 5.0.0
Please also share with us your development environment (Design Studio, RTD, etc.) to assist you further. Sometimes the location of certain fields may change depending on the RTD and/or the Design Studio version.
Please let me know if this helps and if you have more doubts.
- RomanVR.
I only want to convert ticks to micro/mili/seconds not change the clock frequency so the formula confirmation is appreciated, but wouldn't that formula convert ticks to seconds not microseconds since MHz is cycles per second.
Basically if I have 160Mhz then : 160 ticks = 1us, 160 * 1000 = 1ms, and 160 * 1000 * 1000 = 1 second correct?
I am on S32DS 3.5 but my rtd only appears to be version 3.0.0? I do not see any way to update to 5.0.0
Also Clock_Ip_Init(&Mcu_aClockConfigPB[0]); previously worked but now does not as it sees mcu_aclockconfigpb as undeclared and I do not know what changed
I have attached my project folder though I do not know how to export my entire development environment settings to help further.
Hi @pb632146
Apologies for my typo in the formula. You are correct, it will convert ticks to seconds. Therefore, you can just multiply by 1,000,000 or divide the ticks by 160 just as you mention.
To update to RTD 5.0.0, you must first uninstall the RTD 3.0.0 and then download the updatesite of version 5.0.0. Below is a step-by-step guide to assist you:
Uninstalling RTD 3.0.0:
Downloading and Installing RTD 5.0.0:
Code Update:
Please replace the following line of code with:
"Clock_Ip_Init(&Mcu_aClockConfigPB_BOARD_InitPeripherals[0]);"
This how the clock configuration structure is defined in your project.
Let me know if this helps and if you have more doubts.
- RomanVR.
Hi @pb632146
I'm glad that the information helped.
By updating the RTD version, I strongly suggest to check your applications configurations, since the location of certain configuration fields and/or definitions may change and the code will not compile.
- RomanVR.