S32K ナレッジベース

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

S32K Knowledge Base

ラベル

ディスカッション

ソート順:
******************************************************************************* The purpose of this demo application is to present a usage of the EMIOS IP Driver in Interrupt mode for the S32K3xx MCU. The example use to :-- EMIOS-1 - ch-0  --> PTC24 --> Generate the PWM EMIOS-1 - ch-1  --> PTC25 --> is the ICU channel to measure the duty Pins used :--     This example is tested for SAIC & IPWM mode both. You can change the mode by this setting in MEX file :--     Difference between SAIC & IPWM,  ICU Driver User Manual :--   These Two Macro :-- SAIC_MODE  --> this maco will enable variables to store for SAIC mode CUSTOM_IRQ  --> this MACRO will enable customized IRQ or RTD available IRQ   Result :--     Sometimes Compiling error comes, in Autogenerated RTD file.    Change the Header file name :--    ------------------------------------------------------------------------------ * Test HW: S32K3X2EVB-Q172 * MCU: S32K312 * Compiler: S32DS3.5 * SDK release: RTD 3.0.0 * Debugger: PE micro * Target: internal_FLASH ********************************************************************************
記事全体を表示
******************************************************************************* The purpose of this demo application is to present a usage of the EMIOS IP Driver in Polling mode for the S32K3xx MCU. The example use to :-- EMIOS-1 - ch-0  --> PTC24 --> Generate the PWM EMIOS-1 - ch-1  --> PTC25 --> is the ICU channel to measure the duty Pins used :--     This example is tested for IPWM mode .  :--       IPWM mode ,  ICU Driver User Manual :--   Result :-- Sometimes Compiling error comes, in Autogenerated RTD file.    Change the Header file name :--      ------------------------------------------------------------------------------ * Test HW: S32K3X2EVB-Q172 * MCU: S32K312 * Compiler: S32DS3.5 * SDK release: RTD 3.0.0 * Debugger: PE micro * Target: internal_FLASH ********************************************************************************
記事全体を表示
******************************************************************************* The purpose of this demo application is to present a usage of the EMIOS IP Driver in Polling mode for the S32K3xx MCU. The example use to :-- EMIOS-1 - ch-0  --> PTC24 --> Generate the PWM EMIOS-1 - ch-1  --> PTC25 --> is the ICU channel to measure the duty Pins used :--     This example is tested for IPWM mode .  :--       IPWM mode ,  ICU Driver User Manual :--   Result :--    ------------------------------------------------------------------------------ * Test HW: S32K3X2EVB-Q172 * MCU: S32K312 * Compiler: S32DS3.5 * SDK release: RTD 3.0.0 * Debugger: PE micro * Target: internal_FLASH ********************************************************************************
記事全体を表示
******************************************************************************* The purpose of this demo application is to present a usage of the EMIOS IP Driver in Interrupt mode for the S32K3xx MCU. The example use to :-- EMIOS-1 - ch-0  --> PTC24 --> Generate the PWM EMIOS-1 - ch-1  --> PTC25 --> is the ICU channel to measure the duty Pins used :--     This example is tested for SAIC & IPWM mode both. You can change the mode by this setting in MEX file :--     Difference between SAIC & IPWM,  ICU Driver User Manual :--   These Two Macro :-- SAIC_MODE  --> this maco will enable variables to store for SAIC mode CUSTOM_IRQ  --> this MACRO will enable customized IRQ or RTD available IRQ   Result :--    ------------------------------------------------------------------------------ * Test HW: S32K3X2EVB-Q172 * MCU: S32K312 * Compiler: S32DS3.5 * SDK release: RTD 3.0.0 * Debugger: PE micro * Target: internal_FLASH ********************************************************************************
記事全体を表示
*******************************************************************************  The purpose of this demo application is to present a usage of the EMIOS IP Driver for the S32K3xx MCU. This example uses the custom IRQ.  The example uses:-- EMIOS-1 - ch-0  --> PTC24 --> Generate the PWM EMIOS-1 - ch-1  --> PTC25 --> is the ICU channel to measure the duty           Result :--        ------------------------------------------------------------------------------ * Test HW: S32K3X2EVB-Q172 * MCU: S32K312 * Compiler: S32DS3.5 * SDK release: RTD 3.0.0 * Debugger: PE micro * Target: internal_FLASH ********************************************************************************
記事全体を表示
*******************************************************************************  The purpose of this demo application is to present a usage of the ICU & PWM MCAL Driver for the S32K3xx MCU. This example uses the custom IRQ. The example uses:-- EMIOS-1 - ch-0  --> PTC24 --> Generate the PWM EMIOS-1 - ch-1  --> PTC25 --> is the ICU channel to measure the duty       Result :--      ------------------------------------------------------------------------------ * Test HW: S32K3X2EVB-Q172 * MCU: S32K312 * Compiler: S32DS3.5 * SDK release: RTD 3.0.0 * Debugger: PE micro * Target: internal_FLASH ********************************************************************************
記事全体を表示
*******************************************************************************  The purpose of this demo application is to present a usage of the  ADC_SAR and BCTU IP Driver for the S32K3xx MCU. The example uses the TWO PIT0 trigger to trigger BCTU conversion list to perform parallel conversions on ADC0/ADC1. Each Trigger has one LIST associated with it in the BCTU. Conversion result for EACH list is stored in individual FIFO of the BCTU. DMA will transfer the ADC conversion result. LIST-1 ADC channels are selected to be converted on each ADC:     LIST-2 ADC channels are selected to be converted on each ADC:--      Converted results from BCTU FIFO are moved by DMA into result array.  ADC channel S10 is connected to board's potentiometer. Result :--    ------------------------------------------------------------------------------ * Test HW: S32K3X4EVB-Q172 * MCU: S32K312 * Compiler: S32DS3.5 * SDK release: RTD 3.0.0 * Debugger: PE Micro * Target: internal_FLASH ********************************************************************************
記事全体を表示
ADC Module clock is ideally the CORE clock :--   Prescaler In S32DS  is this MCR[ADCLKSEL]) :-- See below snippet from specs for calculation of ADC conversion clock  :-- ADC is controlled by one clock signal, the module clock. Internally, the conversion circuit is controlled by the conversion clock, which is derived from the module clock. You must configure the ADC conversion clock divider (MCR[ADCLKSEL]) so that the frequency of the conversion clock is within allowed limits.     S32K3 Datasheet, ADC MAX MIN clock limit :--  
記事全体を表示
******************************************************************************************************* * Detailed Description: The purpose of this demo application is to present some usage modes of the eMIOS for the S32K3xx MCU. The application uses the eMios_Pwm driver as OPWMCB ( Center aligned Output PWM Buffered with dead time), OPWMB (Output Pulse Width Modulation Buffered) and OPWMT (Output Pulse Width Modulation Trigger) to generate waveforms.  PWM signal generated by EMIOS 0 CH 1 (OPWMCB mode), EMIOS 0 CH 2 (OPWMCB mode), EMIOS 0 CH 3 (OPWMB mode) and EMIOS 0 CH 4 (OPWMT mode). Each waveform was manipulated to demonstrate a capability (dead time insertion and phase shift) of the configured mode. The application also uses the eMios_Icu driver as ICU_MODE_SIGNAL_MEASUREMENT in SAIC (Single Action Input Capture) mode with interrupts and IPWM (Input Pulse Width Measurement) mode without interrupts to obtain the duty cycle of the captured signal. PWM signal generated by EMIOS 2 CH 8 (OPWMB mode) measured by EMIOS 1 CH 5 (SAIC mode) AND CH 6 (IPWM mode). * Test HW: S32K3X4EVB-T172 * MCU: S32K344 * Debugger: S32DS 3.5, OpenSDA * Target: internal_FLASH *******************************************************************************************************
記事全体を表示
******************************************************************************************************* * Detailed Description: The purpose of these demo applications is to present a usage of the LPSPI Driver together with DMA Driver (IP and MCAL) for the S32K3xx MCU. The applications uses the LPSPI driver to transfer data between LPSPI2 (master, no DMA) and LPSPI0 (slave, with DMA) physical units. * Connections * Test HW: S32K3X4EVB-T172 * MCU: S32K344 * Debugger: S32DS 3.5, PEMicro Multilink Universal FX rev.B * Target: internal_FLASH *******************************************************************************************************
記事全体を表示
Detailed Description:                      This config tool simplifies DCF records calculation for S32K344 device.                 Look at HowToUse sheet for simple guideline, then work with DCF sheet                 Notes: - Macros have to be enabled!         BR, Petr
記事全体を表示
******************************************************************************** The purpose of this demo application is to show you the usage of the FlexCAN module configured to use CAN FD using the S32 RTD API. - This demo application requires two boards, or single board connected with CAN tool. - CAN FD is enabled with bitrate 500/2000 kbps - It configures FlexCAN0 module and its transceiver (TJA1153). - MB0 is used to transmit CANFD std. ID - MB1 is configured to receive any std. ID - Callback function is used as well to handle TX and RX process in MBs. Received ID is echoed back. - setupCanXCVR function is called to Init TJA1153 connected to FlexCAN0 on the board. It expects transceiver in Vanilla state and set TPL to pass all std and ext ID and do not block any message coming from bus. Finally leaving configuration mode without writing to non-volatile memory nor locking the transceiver. * * ------------------------------------------------------------------------------ * Test HW: S32K3X8EVB-Q289 rev B2 * MCU: P32K358HVS 0P14E * Compiler: S32DS.ARM.3.5 * SDK release: S32K3_RTD_4.0.0_D2311 / S32K3_RTD_5_0_0_D2408 * Debugger: Lauterbach * Target: internal_FLASH * ********************************************************************************
記事全体を表示
Hi everyone, Welcome to the NXP Tech Days 2024 training session AUT-T4977: Hands - On Workshop: S32K3 Ethernet- How to Configure Hardware and Software. This session was initially planned for 15 attendees. But due to the popularity of the lecture, we have increased the number of available seats . Therefore, we will work in pairs during the Hands-On. My name is Alejandro Flores Triana (Alex) and I will be your guide during this conference. I am an Automotive Applications Engineer supporting different OEMs, Tier1s, Partners and other internal NXP teams on topics related to communication protocols (e.g. CAN, LIN, SPI, I2C, Ethernet, etc.). The idea of this session is for you to understand how to program the S32K3 Ethernet interface using NXP Real-Time Drivers (RTDs) – Autosar MCAL Layer. We will use a base project and together modify it to create a simple Ethernet application. Therefore, to be ready follow the steps below to get your environment up and running before the session. On your laptop, install the NXP Software environment described in the attached presentation: Hands - On Workshop: S32K3 Ethernet Prerequisites.   Once you have the NXP software environment installed, download the attached project: S32K344_ETH_MCAL_TechDays.exe   Run the .exe project with administrator rights. Accept the license and install in the desired folder         Open the NXP Design Studio. Click File -> Import -> Existing Projects into Workspace   Select root directory and browse the folder where you downloaded the project   Select Copy projects into workspace   Click Finish. Select the project. Click on the arrow next to the hammer. Click on Debug_FLASH. Then you are ready for the session! See you soon. Best Regards, Alejandro Flores Triana
記事全体を表示
The following article is intended to give an example on the use of the FS26 in standby mode with the S32K3 MCU also in standby to get lower consumptions on costumer designs and waking up both through an external wake (EXTWAKE) and the PGOOD SBC signal. Software requirements: The attached codes uses the following SW requirements: S32K3 RTD 4.0.0 HF02 FS26 SBC RTD 3.0.0 HW Requirements: There are a few reworks needed on the EVB in order to make the code work.  S32K3X8EVB-Q289 Rev B2: 1.- Remove resistor R2301 and place R2304 instead, this change is because the PTA8 signal has the EXTWAKE option on the user push-button, this allows that when you send a WKPU request from the MCU (with the push-button) what the MCU does when it has PGOOD activated is that it sends an EXTWAKE signal to WAKE1 of the FS26.     2.- Change the J685 jumper position to 2-3, this jumper is the VDEBUG mode.       3*.- Optional: FS26 DS recommend FCCU lines with certain values of resistors on their lines that are not present by default on the S32K3X8EVB-Q289.          I've attached the example program on a ZIP file, hope it helps.  
記事全体を表示
This page supports the NXP Tech Days training session AUT-T4984_Hands-On Workshop_Battery Management System Software Stack. The full installation pre-requisites are attached in the .zip bellow. Please follow closely BMS_SWInstalationGuide.pdf.
記事全体を表示
This page supports the NXP Tech Days training session AUT-T4978 for "Hands-On Workshop: The Safety Peripheral Driver in the S32K3 - The Next Level to Achieve Safety". The full installation pre-requisites are attached below, as well as the required S32DS demo application project.
記事全体を表示
1 Abstract After learning S32K3 PWM and have written some MCAL codes, this is the first MCAL article record starts with the combination of K344 EMIOS+ICU+TRIMUX+LCU, which can involve comprehensive configurations such as PORT, DIO, EMIOS, interrupt ICU, TRIGMUX, LCU, etc. The board platform is still based on NXP official S32K344EVB, RTD400, and the function is: use two channels of EMIOS0 and one channel of EMIOS1. After one channel of EMIOS 0 outputs PWM, it connects LCU through TRIGUMX to generate a set of complementary PWM, and the other channel can realize hardware interrupt control of PWM duty cycle through SW5 PT26 button. One channel of EMIOS1 is directly connected to the PTA29 onboard red light, and the brightness is gradually changed by changing the PWM duty cycle, and then the breathing light effect is realized by directly changing the on and off cycle. At the same time, when the PWM turns off the red light, the onboard green light is turned on through DIO, and when the PWM turns on the red light, the DIO turns off the onboard green light. Text description is always less intuitive than graphic description, so here is the picture:      Fig 1 2. Function realization This article is based on porting the MCAL code to the S32DS demo. Then, on the S32DS platform, MCAL related modules are configured through EB, and then compiled and downloaded for simulation through S32DS. Of course, if you like the command line mode, you can directly use the xmd file configured by EB, and then compile with VScode. The process is also very simple. This article will not go into details about the command line method.     2.1 Hardware and software platform Board:S32K344EVB,also can use other K3 boards. IDE:S32DS3.5 RTD: K344 RTD 400 MCAL tool: EBtresos Studio 29.0 2.2 Software control process Before talking about the specific MCAL configuration, here is the software flow chart of the functions in this article:                                                                             Fig 2 Here you can see that the default situation is the one configured through MCAL, and then the PWM frequency is also modified in the code, and the PWM duty cycle is modified by keystrokes and loop delays. 2.3 Resource Allocation Overview The hardware resources and functions used in this article are listed as follows: Fig 3 The configuration of emios related buses is as follows: Fig 4 It should be noted here that for the master bus and bus mode in MCL emios, it is necessary to select the appropriate PWM mode and counter bus in the PWM module, otherwise either the configuration will be wrong or the correct PWM waveform cannot be generated. From the official S32K3 RM, you can check the clock channel and bus type: Fig 5 For example, if EMIOS_CH23 is selected in PWM0, then this bus corresponds to bus A, and this clock can be used for all channels, so PWM0 is CH12 and can use Bus A. CH22 corresponds to bus F, and this clock can also be used for all channels, so it is no problem to select Bus F for PWM1 CH4. CH0 corresponds to bus B, and this clock corresponds to channels 0-7, so it can also be used for PWM2 is CH2. When selecting the counter bus clock source for your EMIOS channel, you must consider the channel coverage of the counter bus. In addition to the selection of the counter bus, there is also the PWM mode selection, which is easier to handle. For clock counting up, select OPWMB, and for clock counting up and down, select OPWMCB center-aligned PWM.      In actual use, the mode selection is usually determined based on one's own PWM requirements, and then based on the following RM table: Fig 6 You can find the channel types that the corresponding mode can support, and then select the corresponding channel, counter bus, etc. according to the channel type in Figure 5. With these basic knowledge, we can directly enter the EB configuration. 2.4 EB configuration    Here we list all the modules used in EB tresos related to this article, and focus on the modules that require specific configuration. Fig 7 2.4.1 Dio module The DioPort interface needs to be configured. The main purpose is to configure PTA30, onboard green light, select DioPort Id=1, Dio Channel Id=14. The rules for DioPortId and Dio Channel Id are as follows:     Channel = DioChannelId + DioPortId∗16 For S32K3X4 derivatives – Port AL=0 – Port AH=1 – Port BL=2 – Port BH=3 – Port CL=4 – Port CH=5 – Port DL=6 – Port DH=7 – Port EL=8 – Port EH=9 – Port FL=10 – Port FH=11 – Port GL=12 – Port GH=13 PTA30=>30=DioChannelId(14)+DioPortId*16 2.4.2 Icu module First, configure IcuSiul2, the goal is to enable the input interrupt of onboard SW5, PTB26. PTB26 corresponds to EIRQ[13], Then, the corresponding interrupt situation is as follows: Fig 8 Fig 9 (1) Icu->IcuSiul2->IcuSiul2Channels:13 (2) Icu->IcuChannel configuration is: Fig 10 Select IcuChannelRef as the previously configured IcuSiul2Channels, and add the interrupt notification function: User_EdgeDetect, note that this function is the name of the user interrupt processing function that needs to be added in the code.    (3)Icu->IcuHwInterruptConfigList-> ICU Peripheral ISR Name: SIUL2_0_IRQ_CH_13,IcuIsrEnable enable 2.4.3 Mcl module This module is mainly used to configure emios counting clock, trgmux, and LCU configuration. (1)Mcl->Trgmux Logic Instance->Hardware Instance: TRGMUX_IP_HW_INST_0   (2) Mcl->Trgmux Logic Group: Fig 11 The main purpose is to connect PWM1 Emios0_ch4 to LCU0_IN0 through Trigmux. (3)Mcl->LCU Configuration Here is the configuration of the LCU module. The main function is to configure the logic input and logic output. There is one input IN0 and two outputs OUT0 and OUT1. Fig 12 Fig 13 Fig 14 OUTPUT0  value is 0XAAAA=43690, OUTPUT1 value is 0X5555=21845 The purpose of this is to generate a pair of complementary PWMs from the input PWM. Fig 15 (4)Mcl->Emios Common Add two Emios, EMIOS_0 and EMIOS_1, which means two EMIOS are used. EMIOS0 is configured with two master bus channels: CH_22 and CH_0, and has different mode types, counting up and down and counting up. EMIOS1 is configured with one master bus channel: CH_23, counting up Corresponding to Figure 4. Fig 16 Fig 17 Note that the channel here is not the actual PWM output channel, but the counter bus channel of the PWM channel, which has the ability to provide clocks. 2.4.4 Mcu module   This module is the basis for the entire MCU to configure the clock. When using the default setting of the original RTD PWM demo, there is only one point that needs attention Mcu->McuClockSettingConfig_0->McuClockReferencePoint->McuClockReferencePoint_0->core clock 48MHZ. This clock is the source of the EMIOS clock. With the clock source, it is not difficult to calculate the actual PWM frequency according to the set period. For example, if a 1Khz PWM is required, you can configure period=48M/1K=48000 2.4.5 Platform module Platform->Interrupt Controller->IntCtrlConfig0, enable SIUL_1_IRQn, and add Handler as: SIUL2_EXT_IRQ_8_15_ISR Note that this SIUL2_EXT_IRQ_8_15_ISR is not written randomly, but must correspond to the one in Siul2_Icu_Ip_Irq.c, otherwise an error will be reported. Fig18 Different interrupts have different interrupt service functions. You need to find the function name defined in the code and fill it into EB. EB configuration is as follows: Fig 19 2.4.6 Port module The configuration of 8 pins is as follows: Fig 20 As you can see, there are 3 main EMIOS PWMs, one input interrupt, one output GPIO, and two output LCU complementary PWMs. 2.4.7 Pwm module Mcl configures the counter clock channel of EMIOS. The PWM channels to be output need to be configured in the Pwm module and linked to the MCU clock source and the emios counter bus source in Mcl. (1) Pwm->PwmEmios Add two groups for the corresponding EMIOS modules. For example, this article uses EMIOS0 and EMIOS1, so two need to be added: Fig 21 For PwmEmios_1, there is one channel, and the configuration is as follows: Fig 22 PwmEmiosBusRef: /Mcl/Mcl/MclConfig/EmiosCommon_1/EmiosMclMasterBus_0 Fig 23 As you can see, the busRef of PwmEmios_1 here is Emios_ch_23 in Mcl, that is, BusA. That is to say, the bus reference clock used by EMIOS1_CH12 comes from EMIOS1_CH23, that is, Bus A. There are two channels configured in PwmEmios_0, and the configuration is as follows: Fig 24 Fig 25 The bus reference clock used by EMIOS0_CH4 comes from EMIOS0_CH22, which is Bus F. Another EMIOS0 channel: Fig 26 Fig 27 The bus reference clock used by EMIOS0_CH2 comes from EMIOS0_CH0, that is, Bus B, so select Bus BCDE. At this point, we can clearly understand the relationship between the real PWM output channel and the internal MCL Emios counter bus channel. (2)Pwm->PwmEmios With the specific information of PWM configured above, we can directly configure the PWM channels. There are three channels in total: PWM0, PWM1, PWM2, which are also the flags needed in the code. Fig 28 2.5 main code   #include "Pwm.h" #include "Mcu.h" #include "Port.h" #include "Mcl.h" #include "Platform.h" #include "Dio.h" #include "Icu.h" //#include "check_example.h" #define NUM_BLINK_LED (uint32)10U #define DELAY_TIMER (uint32)5000000U #define MCL_EMIOS_1_CH_23 (uint16)279U #define MCL_EMIOS_0_CH_22 (uint16)22U Mcl_LcuSyncOutputValueType PWM_OutputList[2]; volatile uint8 UserCountIrqCH0; void TestDelay(uint32 delay); void TestDelay(uint32 delay) { static volatile uint32 DelayTimer = 0; while(DelayTimer<delay) { DelayTimer++; } DelayTimer=0; } void User_EdgeDetect(void) { /* increment IRQ counter */ UserCountIrqCH0++; if(UserCountIrqCH0 % 2 == 0) { Pwm_SetDutyCycle(PwmChannel_2, 0X6000); } else { Pwm_SetDutyCycle(PwmChannel_2, 0X2000); } } int main(void) { uint8 num_blink = 0U, i = 0; uint16 duty_cnt = 0; UserCountIrqCH0 = 0U; /* Initialize the Mcu driver */ Mcu_Init(&Mcu_Config_VS_0); /* Initialize the clock tree */ Mcu_InitClock(McuClockSettingConfig_0); /* Apply a mode configuration */ Mcu_SetMode(McuModeSettingConf_0); Platform_Init(NULL_PTR); /* Initialize all pins using the Port driver */ Port_Init(&Port_Config_VS_0); /* Initialize Mcl driver */ Mcl_Init(&Mcl_Config_VS_0); /* Initialize the Icu driver */ Icu_Init(NULL_PTR); Icu_EnableEdgeDetection(IcuChannel_0); Icu_EnableNotification(IcuChannel_0); /* Initialize Pwm driver , after that Led on*/ Pwm_Init(&Pwm_Config_VS_0); /* PTA29 duty cycle is 50% */ Pwm_SetDutyCycle(PwmChannel_0, 0X4000); // PTB16,pwm1 , emios0_ch4, use trigmux LCU output 2 Complementarity PWM Mcl_LcuSyncOutputValueType lcuEnable[2U]; lcuEnable[0].LogicOutputId = 0; lcuEnable[0].Value = 1U; lcuEnable[1].LogicOutputId = 1; lcuEnable[1].Value = 1U; Mcl_SetLcuSyncOutputEnable(lcuEnable, 2U); TestDelay(DELAY_TIMER); /* Set new period for all channels used external counter bus */ Mcl_Emios_SetCounterBusPeriod(MCL_EMIOS_1_CH_23, 4800, FALSE); // pwmchannel_0 10Khz Mcl_Emios_SetCounterBusPeriod(MCL_EMIOS_0_CH_22, 1200, FALSE);// for PwmChannel_1, 20Khz // PWM0: 10kHZ //PWM1: 20KHZ //PWM2:1KHZ // PTA29 10kHZ /* PTA29 duty cycle is 50% */ Pwm_SetDutyCycle(PwmChannel_0, 0X4000); /* Setup new duty cycle to the pin*/ Pwm_SetDutyCycle(PwmChannel_1, 0x4000); for(i=0; i <= 10; i++) { duty_cnt = i * 0x800; Pwm_SetDutyCycle(PwmChannel_0, duty_cnt); TestDelay(DELAY_TIMER); } /* Using duty cycle 0% and 100% to Blink LED */ while(1) { /* pwm1 when duty cycle is 75% */ Pwm_SetDutyCycle(PwmChannel_1, 0X6000); //Led off Pwm_SetDutyCycle(PwmChannel_0, 0X0000); //red off Dio_WriteChannel(DioConf_DioChannel_Digital_ledgreenPTA30, STD_HIGH); //green on TestDelay(DELAY_TIMER); /* pwm 1 when duty cycle is 25% */ Pwm_SetDutyCycle(PwmChannel_1, 0X2000); //Led ON Dio_WriteChannel(DioConf_DioChannel_Digital_ledgreenPTA30, STD_LOW); //Green OFF Pwm_SetDutyCycle(PwmChannel_0, 0X8000); //RED ON TestDelay(DELAY_TIMER); num_blink++; } /* De-Initialize Pwm driver */ Pwm_DeInit(); //Exit_Example(TRUE); return 0U; }   3. Test Result After power-on, the onboard red light flashes, then gradually turns bright from off, and flashes alternately with the green light. Test PWM1 PTB16: EMIOS0_CH4, the waveform is 20Khz after stabilization, and the duty cycle changes alternately between 25% and 75%. PWM2 PTB14: EMIOS0_CH2, after stabilization, the frequency is 1KHZ, and as the onboard SW5 is pressed, the duty cycle changes alternately between 25% and 75%. Test PTD3, PTD2, it can be seen that it is a pair of complementary waveforms, and the frequency is the same as PTB16, and the duty cycle change rule is also the same. It can be seen that the key interrupt, 3 main PWM, and 2 LCU PWM in this article are already working. Fig 29 Fig 30  
記事全体を表示
1. Abstract The S32K344 ADC is a SAR ADC with a resolution which can up to 14 bits. It has a variety of software and hardware triggering methods, supports various external trigger sources, and introduces BCTU so that the trigger resources can be externally connected to multi-channel EMIOS and TRIGMUX, adding more ADC trigger sources. This article mainly explains the following ADC software and hardware triggering methods, and provides supporting codes.     Fig 1 It is mainly divided into 5 parts: (1) SW+ADC: software trigger, by adding timer PIT, the software trigger ADC is called regularly to complete channel sampling, and the collected value is printed out through UART printf. (2) SW+BCTU+ADC: software trigger, by adding timer PIT, the software trigger BTCU is called regularly to complete ADC channel sampling, and the collected value is printed out through UART printf. (3) PIT+TRIGMUX+ADC: hardware trigger, connect PIT to ADC through TRIGMUX, trigger ADC channel sampling through PIT hardware, and print the conversion value after the sampling conversion is completed. (4) EMIOS+BCTUHW+ADC: hardware trigger, through EMIOS timing trigger BCTU to complete the corresponding ADC single channel sampling, due to the high sampling rate, only the BCTU sampling value is printed regularly. (5) EMIOS+BCTUHWLIST+ADC: hardware trigger, through EMIOS timing trigger BCTU to complete ADC list channel sampling, due to the high sampling rate, the list channel value sampled by BCTU is printed regularly. 2. ADC SW HW Trigger 2.1 Hardware and software platform SW: RTD400 LLD,S32DS3.5 HW:S32K3X4EVB-T172 2.2 SW+ADC software trigger     In fact, the original ADC demo of RTD400 already has ADC software and BCTU software trigger. This article adds PIT timing software trigger based on this function, and prints it out through UART printf, making it more convenient to check the ADC test value through serial port printing. The block diagram structure of the software triggering ADC in this article is as follows:     Fig 2      The S32K344EVB board has a potentiometer connected to ADC1_S10, PTA11:   Fig 3 Therefore, the software trigger in this section is mainly used to collect ADC1_S10. The UART printing port uses the serial port of the onboard emulator: LPUART6_RX PTA15, LPUART6_TX PTA16, with a baud rate of 115200. For the software trigger demo in this article, the main configuration involves the following modules: (1)Pins:   Fig 4 ADC1_s10: PTA11 is the voltage of the onboard potentiometer to be tested, which is adjustable. PTA29: Connect the onboard D13 red light to test the PIT timer interrupt and enter the flashing state, used as the breathing light of the PIT. PTA16: UART6_TX, used to send the collected ADC value. (2)clocks Used to configure the system clock. You need to pay attention to the UART6 clock source of 40Mhz, the ADC1 clock source of 160Mhz, and the PIT0 clock source of 40Mhz (3)Peripherals Involved peripheral modules Siul2_Port,Siul2_Dio, Pit, Lpuart_Uart, Adc_Sar_Ip, IntCtrl_Ip. Siul2_Port: Add 4 pins ADC PTA11 MSCR 11, RED LED PTA29 MSCR 29, UART6_RX PTA15 MSCR 15, UART6_RX PTA16 MSCR 16. Siul2_Dio: Add the module mainly to allow related API functions to come in, so as to control GPIO pins. Pit: Used to generate 1S timing, the main configuration is as follows:   Fig 5                                                             Fig 6 Lpuart_Uart: Fig 7 Adc_Sar_Ip:   Fig 8                                                                         Fig 9 It should be noted here that ADC calibration prescale and Adc prescaler vale need to meet the following conditions, which can be found on S32K3RM:   Fig 10 Since the clock source of ADC1 is 160MHz, the calibration division is configured as 4 and the conversion division is configured as 2. IntCtrl_Ip:   Fig 11 The purpose is to open the interrupt of PIT and LPUART6, and register the corresponding handler. CT configuration is completed, and the code is generated. Next, move to the main function and add the following code: void AdcEndOfChainNotif1(void) { notif_triggered1 = TRUE; data1 = Adc_Sar_Ip_GetConvData(ADCHWUNIT_1_BOARD_INITPERIPHERALS_INSTANCE, 34); /* Checks the measured ADC data conversion */ // while (ADC_TOLERANCE(data, ADC_BANDGAP)); } void Pit0ch0Notification(void) { toggleLed = 1U; Siul2_Dio_Ip_TogglePins(LED_Q172_PORT, (1<<LED_Q172_PIN)); } int main(void) { StatusType status; uint8 Index; Clock_Ip_StatusType clockStatus; /* Initialize and configure drivers */ clockStatus = Clock_Ip_Init(&Clock_Ip_aClockConfig[0]); while (clockStatus != CLOCK_IP_SUCCESS) { clockStatus = Clock_Ip_Init(&Clock_Ip_aClockConfig[0]); } Siul2_Port_Ip_Init(NUM_OF_CONFIGURED_PINS_PortContainer_0_BOARD_InitPeripherals, g_pin_mux_InitConfigArr_PortContainer_0_BOARD_InitPeripherals); /* set PIT 0 interrupt */ IntCtrl_Ip_Init(&IntCtrlConfig_0); IntCtrl_Ip_EnableIrq(PIT0_IRQn); status = (StatusType) Adc_Sar_Ip_Init(ADCHWUNIT_1_BOARD_INITPERIPHERALS_INSTANCE, &AdcHwUnit_1_BOARD_InitPeripherals); while (status != E_OK); IntCtrl_Ip_InstallHandler(ADC1_IRQn, Adc_Sar_1_Isr, NULL_PTR); IntCtrl_Ip_EnableIrq(ADC1_IRQn); for(Index = 0; Index <= 5; Index++) { status = (StatusType) Adc_Sar_Ip_DoCalibration(ADCHWUNIT_1_BOARD_INITPERIPHERALS_INSTANCE); if(status == E_OK) { break; } } Adc_Sar_Ip_EnableNotifications(ADCHWUNIT_1_BOARD_INITPERIPHERALS_INSTANCE, ADC_SAR_IP_NOTIF_FLAG_NORMAL_ENDCHAIN | ADC_SAR_IP_NOTIF_FLAG_INJECTED_ENDCHAIN); /* Initialize PIT instance 0 - Channel 0 */ Pit_Ip_Init(PIT_INST_0, &PIT_0_InitConfig_PB_BOARD_InitPeripherals); /* Initialize channel 0 */ Pit_Ip_InitChannel(PIT_INST_0, PIT_0_CH_0); /* Enable channel interrupt PIT_0 - CH_0 */ Pit_Ip_EnableChannelInterrupt(PIT_INST_0, CH_0); /* Start channel CH_0 */ Pit_Ip_StartChannel(PIT_INST_0, CH_0, PIT_PERIOD); Lpuart_Uart_Ip_Init(UART_LPUART_INTERNAL_CHANNEL, &Lpuart_Uart_Ip_xHwConfigPB_6_BOARD_INITPERIPHERALS); printf("S32K344 PIT TRIGMUX ADC demo RTD400.\r\n"); while(1) { #if 1 if( toggleLed == 1) { toggleLed = 0; /* Start a SW triggered normal conversion on ADC_SAR */ Adc_Sar_Ip_StartConversion(ADCHWUNIT_1_BOARD_INITPERIPHERALS_INSTANCE, ADC_SAR_IP_CONV_CHAIN_NORMAL); /* Wait for the notification to be triggered and read the data */ while (notif_triggered1 != TRUE); notif_triggered1 = FALSE; printf("ADC1_s10 ch34 data = %d .\r\n", data1); } #endif } } The test results are printed as follows:   Fig 12 This section content supporting code: S32K344_PIT_SW_ADC_RTD400.zip   2.3 SW+BCTU+ADC Software trigger BCTU Based on SW+ADC trigger, add BCTU, and use BCTU software trigger to complete ADC sampling. The block diagram structure is as follows:   Fig 13 This section uses BCTU software to trigger ADC0 sampling. The sampling channel does not actually use external pin input, but collects the bandgap value of ADC0. The software trigger calls the software trigger function through the PIT 1S cycle, and prints the ADC sampling conversion value to UART after completion. In the CT tool, the main modification points are peripherals, adding ADC0 in adc_sar_lp, and configuring it as BCTU trigger.   Fig 14                                                        Fig 15 Here we can see that in Figure 14, the adc ctu mode is: trigger mode. Add the Bctu_Ip module and configure it as follows:   Fig 16 The corresponding selected BCTU channel is 48, which corresponds to the internal bandgap module.   Fig 17 The typical value is 1.2V, so the reference voltage is 5V, and the corresponding 14-bit ADC bandgap expected value is: (2^14)*1.2/5=3932 around. After completing the CT configuration code generation, add the following code in main.c: void AdcEndOfChainNotif(void) { notif_triggered = TRUE; data = Adc_Sar_Ip_GetConvData(ADCHWUNIT_0_BOARD_INITPERIPHERALS_INSTANCE, ADC_SAR_USED_CH); } void Pit0ch0Notification(void) { toggleLed = 1U; Siul2_Dio_Ip_TogglePins(LED_Q172_PORT, (1<<LED_Q172_PIN)); } void BctuWatermarkNotif(void) { uint8 idx; notif_triggered = TRUE; for (idx = 0u; idx < BCTU_FIFO_WATERMARK; idx++) { data_bctu = Bctu_Ip_GetFifoData(BCTUHWUNIT_0_BOARD_INITPERIPHERALS_INSTANCE, BCTU_USED_FIFO_IDX); } } int main(void) { StatusType status; uint8 Index; Clock_Ip_StatusType clockStatus; /* Initialize and configure drivers */ clockStatus = Clock_Ip_Init(&Clock_Ip_aClockConfig[0]); while (clockStatus != CLOCK_IP_SUCCESS) { clockStatus = Clock_Ip_Init(&Clock_Ip_aClockConfig[0]); } Siul2_Port_Ip_Init(NUM_OF_CONFIGURED_PINS_PortContainer_0_BOARD_InitPeripherals, g_pin_mux_InitConfigArr_PortContainer_0_BOARD_InitPeripherals); Bctu_Ip_Init(BCTUHWUNIT_0_BOARD_INITPERIPHERALS_INSTANCE, &BctuHwUnit_0_BOARD_INITPERIPHERALS); status = (StatusType) Adc_Sar_Ip_Init(ADCHWUNIT_0_BOARD_INITPERIPHERALS_INSTANCE, &AdcHwUnit_0_BOARD_InitPeripherals); while (status != E_OK); /* set PIT 0 interrupt */ IntCtrl_Ip_Init(&IntCtrlConfig_0); IntCtrl_Ip_EnableIrq(PIT0_IRQn); /* Install and enable interrupt handlers */ IntCtrl_Ip_InstallHandler(ADC0_IRQn, Adc_Sar_0_Isr, NULL_PTR); IntCtrl_Ip_InstallHandler(BCTU_IRQn, Bctu_0_Isr, NULL_PTR); IntCtrl_Ip_EnableIrq(ADC0_IRQn); IntCtrl_Ip_EnableIrq(BCTU_IRQn); /* Call Calibration function multiple times, to mitigate instability of board source */ for(Index = 0; Index <= 5; Index++) { status = (StatusType) Adc_Sar_Ip_DoCalibration(ADCHWUNIT_0_BOARD_INITPERIPHERALS_INSTANCE); if(status == E_OK) { break; } } Adc_Sar_Ip_EnableNotifications(ADCHWUNIT_0_BOARD_INITPERIPHERALS_INSTANCE, ADC_SAR_IP_NOTIF_FLAG_NORMAL_ENDCHAIN | ADC_SAR_IP_NOTIF_FLAG_INJECTED_ENDCHAIN); /* Start a SW triggered conversion on BCTU using a single trigger */ Bctu_Ip_SetGlobalTriggerEn(BCTUHWUNIT_0_BOARD_INITPERIPHERALS_INSTANCE, TRUE); Bctu_Ip_EnableNotifications(BCTUHWUNIT_0_BOARD_INITPERIPHERALS_INSTANCE, BCTU_IP_NOTIF_FIFO1); /* Initialize PIT instance 0 - Channel 0 */ Pit_Ip_Init(PIT_INST_0, &PIT_0_InitConfig_PB_BOARD_InitPeripherals); /* Initialize channel 0 */ Pit_Ip_InitChannel(PIT_INST_0, PIT_0_CH_0); /* Enable channel interrupt PIT_0 - CH_0 */ Pit_Ip_EnableChannelInterrupt(PIT_INST_0, CH_0); /* Start channel CH_0 */ Pit_Ip_StartChannel(PIT_INST_0, CH_0, PIT_PERIOD); Trgmux_Ip_Init(&Trgmux_Ip_xTrgmuxInitPB);// Lpuart_Uart_Ip_Init(UART_LPUART_INTERNAL_CHANNEL, &Lpuart_Uart_Ip_xHwConfigPB_6_BOARD_INITPERIPHERALS); printf("S32K344 PIT TRIGMUX ADC demo RTD400.\r\n"); while(1) { if( toggleLed == 1) { toggleLed = 0; Bctu_Ip_SwTriggerConversion(BCTUHWUNIT_0_BOARD_INITPERIPHERALS_INSTANCE, BCTU_USED_SINGLE_TRIG_IDX); while (notif_triggered != TRUE); notif_triggered = FALSE; printf("ADC0_bandgap ch48 data_bctu = %d .\r\n", data_bctu); } } } Test result: Fig 18 It is close to the typical expected value, indicating that it has been successfully run. Used demo code:S32K344_PIT_TRIGMUX_BCTUSW_ADC_printf_RTD400.zip   2.4 PIT+TRIGMUX+ADC hardware PIT TRIGUMX trigger This section is about hardware triggering. PIT is used in combination with TRIGMUX to directly trigger ADC1 channel 34, i.e. ADC1_S10 sampling. The trigger structure diagram is as follows:   Fig 19 Also based on the previous code, you need to add an additional module Trgmux_Ip in the CT peripherals, and the rest of the configuration remains unchanged.   Fig 20 Here, the input of Trigmux is selected as PIT0_CH0 and the output is ADC1. The code is also much simpler. Add the following code in main: Trgmux_Ip_Init(&Trgmux_Ip_xTrgmuxInitPB);// while(1) { if(notif_triggered1 == TRUE) { notif_triggered1 = FALSE; printf("ADC1_s10 ch34 data = %d .\r\n", data1); } } In While(1), we can see that there is no software-triggered call. We can directly check the ADC1 conversion completion flag and then print the data. The test results are as follows: Fig 21 It can be seen that as the external potentiometer changes, the sampled value of ADC1_S10 also changes. Used demo:S32K344_PIT_TRIGMUX_ADC_printf_RTD400.zip   2.5 EMIOS+BCTUHW+ADC hardware EMIOS BCTU trigger The block diagram structure of this section is as follows:   Fig 22 Use eMIOS0_CH0 to generate a 10Khz clock to trigger BCTU to complete the sampling of ADC0_48 channel, that is, bandgap. In the CT tool, add Emios_Mcal_Ip and configure it as follows:       Fig 23 Change the BCTU configuration to enable HW triggering. The configuration is as follows:   Fig 24 Main code related codes are as follows: Emios_Mcl_Ip_Init(EMIOS_INST0, &Emios_Mcl_Ip_0_Config_BOARD_INITPERIPHERALS); while(1) { if( toggleLed == 1) { toggleLed = 0; printf("ADC0_bandgap ch48 data_bctu = %d .\r\n", data_bctu); } } Since the sampling rate is triggered at a frequency of 10Khz, the frequency is relatively fast, so the printing here is still based on 1s. The printing results are as follows:   Fig 25 As you can see, the result is also a variable bandgap value. Used demo:S32K344_PIT_TRIGMUX_BCTUHW_EMIOS_ADC_printf_RTD400.zip   2.6 EMIOS+BCTUHW LIST+ADC hardware EMIOS BCTU trigger LIST This section is similar to the EMIOS BCTU hardware trigger above, except that the BCTU is configured in the form of LIST, which can trigger the conversion of multiple channels at once. The main modifications are in the BCTU module:   Fig 26 Add the corresponding main code as follows: #define BCTU_FIFO_WATERMARK 3U void BctuWatermarkNotif(void) { uint8 idx; notif_triggered = TRUE; for (idx = 0u; idx < BCTU_FIFO_WATERMARK; idx++) { data_bctu[idx] = Bctu_Ip_GetFifoData(BCTUHWUNIT_0_BOARD_INITPERIPHERALS_INSTANCE, BCTU_USED_FIFO_IDX); } } while(1) { if( toggleLed == 1) { toggleLed = 0; printf("ADC0_bandgap ch48 data_bctu = %d .\r\n", data_bctu[0]); printf("ADC0_vrefl ch54 data_bctu = %d .\r\n", data_bctu[1]); printf("ADC0_vrefh ch55 data_bctu = %d .\r\n", data_bctu[2]); } } Test result is: Fig 27 It can be seen that the results are consistent with the collected bandgap, VREFL, and VREFH, indicating that the code function is running normally. Code in this section:S32K344_PIT_TRIGMUX_BCTUHWLIST_EMIOS_ADC_printf_RTD400.zip  
記事全体を表示
This article has been moved to a new location: https://community.nxp.com/t5/S32M-Knowledge-Base/S32M2xx-Motor-control-use-cases/ta-p/2039790
記事全体を表示
What is S32K1‘s IDLE feature: IDLE is set when the LPUART receive line becomes idle for a full character time after a period of activity.When CTRL[ILT] is cleared, the receiver starts counting idle bit times after the start bit. Why write this demo? Because the RTM driver does not support Lpuart's IDLE detect. What needs to be modified? -1.add "UART_EVENT_DMA_IDLE = 0x04U" to “callbacks.h”   -2 add "LPUART_DRV_RxIdleCallback" to ".lpuart_driver.c"   -3 Define “LPUART_DRV_RxIdleCallback” function   static void LPUART_DRV_RxIdleCallback(uint32_t instance) { DEV_ASSERT(instance < LPUART_INSTANCE_COUNT); LPUART_Type *base = s_lpuartBase[instance]; lpuart_state_t * lpuartState = (lpuart_state_t *)s_lpuartStatePtr[instance]; LPUART_ClearStatusFlag(base,LPUART_IDLE_LINE_DETECT); if(lpuartState->transferType == LPUART_USING_DMA) { lpuartState->rxSize = EDMA_DRV_GetRemainingMajorIterationsCount(lpuartState->rxDMAChannel); LPUART_DRV_StopRxDma(instance); lpuartState->rxCallback(lpuartState,UART_EVENT_DMA_IDLE,NULL);/*UART_EVENT_DMA_IDLE : 0x04*/ } }     -4 add below code to "LPUART_DRV_IRQHandler" and be sure these code must  be put before "LPUART_DRV_ErrIrqHandler(instance)" /* Handle idle line interrupt */ if (LPUART_GetIntMode(base, LPUART_INT_IDLE_LINE)) { if (LPUART_GetStatusFlag(base, LPUART_IDLE_LINE_DETECT)) { LPUART_DRV_RxIdleCallback(instance); } }   -5 configure IDLE releated register in main function. LPUART1->CTRL |= LPUART_CTRL_ILT(1); LPUART1->CTRL |= LPUART_CTRL_IDLECFG(7); LPUART1->CTRL |= LPUART_CTRL_ILIE(1);   Test environment: Hardware is base on S32K144EVB-Q100 Software is S32 Design Studio for Arm V 2.2 + RTM 3.0.X Demo Description:           The baud rate of the serial port is set to 19200, and the function implemented is to send back the received data using DMA methods .      
記事全体を表示