S32K144 Peripherals

UART Peripheral in S32K144 MCU

So hello guys, welcome back to NXP Semiconductors S32K144 MCU Tutorial series. In the last blog we had started with S32K144 MCU GPIO Peripheral. In this blog we are going to explore the UART Peripheral. Going to Start with UART peripheral. Objective would be to get.

  • familiarity with UART peripheral for S32K144 MCU.
  • Would be understanding UART peripheral from Hardware point of view in S32K144 MCU.
  • Going to understand then how to use UART peripheral via S32K SDK/uart driver.
  • Would also be demonstrating the uart_echo_pall sketch.

So read along the blog and do tell me its reviews!

Table of Contents

UART Peripheral Theory

UART is a serial communication protocol which is used to interface external sensor & IoT modules to the Host MCU. IoT modules like: GSM Module, GPS Module, BLE Modules, WiFi Modules are connected to Host MCU via UART protocol. Thus, understanding of UART communication protocol and its driver implementation, plays a crucial role.

To know about UART peripheral in theory, viewers can refer to this blog.

LPUART Peripheral in S32K144 MCU

In S32K144 MCU, UART can be used via 2 peripherals: LPUART & FlexIO.

UART in S32K144 MCU

LPUART is referred as Low Power Universal Asynchronous Receiver/Transmitter. LPUART is onchip peripheral only to do UART communication protocol. UART is a serial communication protocol which is done via UART peripheral in the Microcontrollers.

Also, in S32K144, there is FlexIO peripheral through which on-board serial communication protocols like UART, I2C & SPI can be emulated. So, through FlexIO peripheral, also UART peripheral can be implemented. To know about FlexIO peripheral in S32K144, refer to this blog.

Features of UART via LPUART peripheral in S32K144 MCU:

  • LPUART peripheral of S32K144 supports full duplex mode and has NRZ data encoding (That is Logic 1 bit represents High value and Logic 0 bit represents Low value).
  • It has programmable Baud rates(
  • LPUART peripheral supports Interrupts mode, DMA mode or pooled operation mode for transmitting/receiving the data using LPUART protocol or for detecting below listed errors while LPUART communication session is happening:
  1. Transmit data register empty and transmission complete.
  2. Receive data register full.
  3. Receive overrun, parity error, framing error, and noise error.
  4. Idle receivers detect.
  5. Active edge on receive pin.
  6. Break detect supporting LIN.
  7. Receive data match.
  • S32K144 also supports hardware parity generation and checking to ensure the integrity of the data while LPUART communication is happening.
  • It has Programmable LPUART data length of 7-10 bits and LPUART stop bits of 1-2 bits.
  • S32K144 MCU has feature to use the LPUART peripheral to wake up the MCU (if it is programmed in sleep modes), it can be waked up in either of the 3 below mentioned events:
  1. Idle line wakeup
  2. Address mark wakeup
  3. Receive data match.
  • Support of request to send (RTS) and clear to send (CTS) signals, for hardware flow control,  example of hardware flow control is a half-duplex radio modem to computer interface.
  • Support of IrDA 1.4 format with programmable pulse width for IR communication.
  • LPUART peripheral of S32K144 supports independent FIFO buffer for transmission and receiving of Data.
  • Also, LPUART peripheral FIFO of S32K144 has additional features like:
  1. configurable watermark (lowest number of bytes) for transmit and receive buffer, when watermark is achieved corresponding status is changed of LPUART peripheral.
  2. Option for receiver to assert request after a configurable number of idle. 
    characters if receive FIFO is not empty.
  • Tx and Rx FIFO in S32K144 for all LPUART Instances both are of 4 words size. 1 Word is 1 byte(8 bits). So FiFo size is 4 byte long(32 bits).

LPUART Hardware Pinout in S32K144 MCU

LPUART Pinout and Hardware Instances

LPUART peripheral in S32K144 has 3 instances: LPUART0, LPUART1, LPUART2.

All the LPUART Instances has 4 pins: 

  • RX: Receiving of data
  • TX: Transmission of data
  • CTS: Clear to Send pin for hardware flow control.
  • RTS: Request to Send for hardware flow control.
    S32K144 UART Pins

Each LPUART instance supports all the 4 pins, with below mentioned pin details.

How to use LPUART Pins in S32K144 MCU for doing UART Communication?

Now for doing UART communication, we need to connect hardware UART pins of the MCU, for doing so follow the steps:

  1. At first select which instance of LPUART wanna use, once selected. As told above their are 3 instances of LPUART in S32K144 MCU.
  2. Once selected, then use above excel to short select which pin of corresponding LPUART has to be used. 
  3. Lets say we use LPUART1 and use PTC7 and PTC6 as Tx & Rx pins of LPUART.
  4. So connect these pins of MCU with external UART Module.
  5. Remember Tx pin of MCU is connected to Rx pin of external UART Module and Rx pin of MCU is connected to Tx pin of external UART Module.
  6. Here i am going to use USB to serial FTDI connector with Original S32K144 evaluation2 board.
  7. With ElecronicsV2 board, it has on-board UART driver IC at LPUART1 PTC7 and PTC6 pins.

How to configure UART Peripheral in S32K144 using S32 Design Studio IDE

UART Peripheral of S32K144 MCU can be configured using the Peripheral configuration tools of S32 Design Studio. These tools provide us with the GUI interface to configure the UART Peripheral of the MCU. To know in detail about the Peripheral configuration of S32 Design Studio refer to these.

BLE Module interfacing with S32K144 MCU
GPS Module interfacing with S32K144 MCU
WiFi Module interfacing with S32K144
GSM Module interfacing with S32K144

LPUART SDK for S32K144 MCU

LPUART SDK

S32K SDK/drivers provide an easy to use and quick way to use LPUART peripheral in S32K144, which is known as LPUART SDK.

LPUART SDK for S32K MCU’s

Each S32 SDK driver can be configured and enabled to use in the project via S32 Configuration Tool. Will be digging into that part, in next section. For now, let’s understand the LPUART SDK in some detail, so as to use UART peripheral via LPUART.

LPUART SDK files

In the SDK of LPUART there are header files and source files for LPUART Driver and LPUART Interrupt.

  • LPUART interrupt files contains functions for using &configuring of LPUART interrupts and IRQ handler in S32K144 MCU.
  • LPUART driver files contains functions for using/configuration of LPUART Peripheral.

LPUART Driver 

LPUART driver files are further divided into LPUART Peripheral Abstraction Layer (PAL) & LPUART Low-level drivers., as shown below:

LPUART Driver Files
  • LPUART Peripheral Abstraction Layer(PAL): contains functions and variables that are directly used in main.c or application code. And internally these functions use the LPUART Low-level drivers & LPUART IRQ . So if hardware is changed LPUART PAL would remain same and only internal low-level driver files need to be changed or modified. By this way we don’t have make many changes on application level.
  • LPUART Low-level driver: contains functions that configures the LPUART peripheral registers for initializing the peripheral, using the peripheral and processing the data of peripheral at hardware level. These files are the ones which actually interacts with the hardware and make it configurable to our needs. 

In the blogs we will be exploring the LPUART Peripheral Abstraction Layer files (PAL) in more details, as that would be directly used in our application project development(main.c) and driver creation of UART modules (GPS, GSM, IoT Modules and etc)

LPUART PAL

In LPUART PAL there are 2 files lpuart_driver.c and lpuart_driver.h files.

Lets get into these files:

  1. lpuart_driver.h: contains the enums, structures and function declarations that would be used in application code. Only functions which are declared in this header file can be used in main.c or application project.
  2. lpuart_driver.c: contains the function definations of the declared functions(uses the low-level driver functions) along with some static functions also that are restricted to use in this file only.

Functions

How to use LPUART PAL for doing UART Communication in S32K144 MCU.

  1. Features of LPUART PAL.
  2. Initialization and configuration API’s of UART peripheral using LPUART PAL.
  • LPUART_DRV_Init: This function is the first function that has to be used in main.c to initialize the LPUART peripheral. This function is just like Serial.begin(9600) of Arduino IDE environment.
				
					status_t LPUART_DRV_Init(uint32_t instance, lpuart_state_t * lpuartStatePtr,
                         const lpuart_user_config_t * lpuartUserConfig);

				
			

This function has 3 function parametrs as follows:

  1. instance: integer number indicating which instance of LPUART we are going to use.
  2. lpuart_user_config and lpuart_state_t: structure pointers have to be sent in this function as parameters. (For the info on these structures refers next section)
				
					#define INST_LPUART_LPUART_1  1

extern lpuart_state_t lpUartState1;

/* External declaration of LPUART configuration structure */
extern const lpuart_user_config_t lpUartInitConfig1;

lpuart_state_t lpUartState1;

const lpuart_user_config_t lpUartInitConfig1 = {
  .transferType = LPUART_USING_INTERRUPTS,
  .baudRate = 9600UL,
  .parityMode = LPUART_PARITY_DISABLED,
  .stopBitCount = LPUART_ONE_STOP_BIT,
  .bitCountPerChar = LPUART_8_BITS_PER_CHAR,
  .rxDMAChannel = 0UL,
  .txDMAChannel = 0UL
};

 /* Initialize LPUART instance */
  LPUART_DRV_Init(INST_LPUART_LPUART_1, &lpUartState1, &lpUartInitConfig1);
 
				
			

In LPUART PAL their are 3 ways by which we can send and receive data.

  1. Interrupt based
  2. DMA Based 
  3. Pooling Based.

In this blog, we are going to explore and understand pooling based method and it’s API. As to use by interrupt and DMA based, we have to know about Interrupt and DMA. So we are going to cover Interrupt and DMA based LPUART communication under topics: Interrupts in S32K144 and DMA in S32K144 MCU.

What is pooling method in Embedded?

LPUART PAL API’s for doing pooling based communication

  • LPUART_DRV_SendDataPolling
				
					status_t LPUART_DRV_SendDataPolling(uint32_t instance, const uint8_t *txBuff, uint32_t txSize);

				
			

This function has 3 parametrs:

  1. instance: integer number indicating which instance of LPUART we are going to use.
  2. txBuff: buffer pointer, pointing to the data which needs to be send out.
  3. txSize: size of data that has to be sent.
				
					  /* Welcome message displayed at the console */
#define welcomeMsg "This example is an simple echo using LPUART\r\n\
it will send back any character you send to it.\r\n\
The board will greet you if you send 'Hello Board'\r\
\nNow you can begin typing:\r\n"

  
  /* Send a welcome message */
  LPUART_DRV_SendDataPolling(INST_LPUART_LPUART_1, (uint8_t *)welcomeMsg, strlen(welcomeMsg));

				
			
  • LPUART_DRV_ReceiveDataPolling
				
					status_t LPUART_DRV_ReceiveDataPolling(uint32_t instance, uint8_t *rxBuff, uint32_t rxSize);

				
			

This function has 3 function parameters:

  1. instance: integer number indicating which instance of LPUART we are going to use.
  2. rxBuff: buffer pointer, would be containing the received data.
  3. rxSize: size of data that has to be received.
				
					  /* Receive buffer size */
#define BUFFER_SIZE 256U

/* Buffer used to receive data from the console */
uint8_t buffer[BUFFER_SIZE];

LPUART_DRV_ReceiveDataPolling(INST_LPUART_LPUART_1, buffer, 1U);
    
				
			
Data Types

There are 2 structures that are important and will be used often

  • lpuart_user_config_t: This structure has members to configure the LPUART according to user defined settings.
				
					/*! @brief LPUART configuration structure
 *
 * Implements : lpuart_user_config_t_Class
 */
typedef struct
{
    uint32_t baudRate;                           /*!< LPUART baud rate */
    lpuart_parity_mode_t parityMode;             /*!< parity mode, disabled (default), even, odd */
    lpuart_stop_bit_count_t stopBitCount;        /*!< number of stop bits, 1 stop bit (default) or 2 stop bits */
    lpuart_bit_count_per_char_t bitCountPerChar; /*!< number of bits in a character (8-default, 9 or 10);
                                                      for 9/10 bits chars, users must provide appropriate buffers
                                                      to the send/receive functions (bits 8/9 in subsequent bytes);
                                                      for DMA transmission only 8-bit char is supported. */
    lpuart_transfer_type_t transferType;         /*!< Type of LPUART transfer (interrupt/dma based) */
    uint8_t rxDMAChannel;                        /*!< Channel number for DMA rx channel.
                                                      If DMA mode isn't used this field will be ignored. */
    uint8_t txDMAChannel;                        /*!< Channel number for DMA tx channel.
                                                      If DMA mode isn't used this field will be ignored. */
} lpuart_user_config_t;


				
			
				
					/* External declaration of LPUART configuration structure */
extern const lpuart_user_config_t lpUartInitConfig1;

const lpuart_user_config_t lpUartInitConfig1 = {
  .transferType = LPUART_USING_INTERRUPTS,
  .baudRate = 9600UL,
  .parityMode = LPUART_PARITY_DISABLED,
  .stopBitCount = LPUART_ONE_STOP_BIT,
  .bitCountPerChar = LPUART_8_BITS_PER_CHAR,
  .rxDMAChannel = 0UL,
  .txDMAChannel = 0UL
};
				
			
  • lpuart_state_t: This structure has data members, which keep track of the on-going transfers . 
				
					/*!
 * @brief Runtime state of the LPUART driver.
 *
 * Note that the caller provides memory for the driver state structures during
 * initialization because the driver does not statically allocate memory.
 *
 * Implements : lpuart_state_t_Class
 */
typedef struct
{
    const uint8_t * txBuff;              /*!< The buffer of data being sent.*/
    uint8_t * rxBuff;                    /*!< The buffer of received data.*/
    volatile uint32_t txSize;            /*!< The remaining number of bytes to be transmitted. */
    volatile uint32_t rxSize;            /*!< The remaining number of bytes to be received. */
    volatile bool isTxBusy;              /*!< True if there is an active transmit.*/
    volatile bool isRxBusy;              /*!< True if there is an active receive.*/
    volatile bool isTxBlocking;          /*!< True if transmit is blocking transaction. */
    volatile bool isRxBlocking;          /*!< True if receive is blocking transaction. */
    lpuart_bit_count_per_char_t bitCountPerChar; /*!< number of bits in a char (8/9/10) */
    uart_callback_t rxCallback;          /*!< Callback to invoke for data receive
                                              Note: when the transmission is interrupt based, the callback
                                              is being called upon receiving a byte; when DMA transmission
                                              is used, the bytes are copied to the rx buffer by the DMA engine
                                              and the callback is called when all the bytes have been transferred. */
    void * rxCallbackParam;              /*!< Receive callback parameter pointer.*/
    uart_callback_t txCallback;          /*!< Callback to invoke for data send
                                              Note: when the transmission is interrupt based, the callback
                                              is being called upon sending a byte; when DMA transmission
                                              is used, the bytes are copied to the tx buffer by the DMA engine
                                              and the callback is called when all the bytes have been transferred. */
    void * txCallbackParam;              /*!< Transmit callback parameter pointer.*/
    lpuart_transfer_type_t transferType; /*!< Type of LPUART transfer (interrupt/dma based) */
#if FEATURE_LPUART_HAS_DMA_ENABLE
    uint8_t rxDMAChannel;                /*!< DMA channel number for DMA-based rx. */
    uint8_t txDMAChannel;                /*!< DMA channel number for DMA-based tx. */
#endif
    semaphore_t rxComplete;              /*!< Synchronization object for blocking Rx timeout condition */
    semaphore_t txComplete;              /*!< Synchronization object for blocking Tx timeout condition */
    volatile status_t transmitStatus;    /*!< Status of last driver transmit operation */
    volatile status_t receiveStatus;     /*!< Status of last driver receive operation */
} lpuart_state_t;

				
			
				
					extern lpuart_state_t lpUartState1;

lpuart_state_t lpUartState1;

				
			

UART Demo Code for S32K144 MCU

 S32 SDK/provides as example demo on LPUART driver to demonstarate how to use the LPUART driver for UART communicatio protocol. Demo Example is named as: lpuart_echo_s32k144

				
					/*
 * Copyright 2020 NXP
 * All rights reserved.
 *
 * NXP Confidential. This software is owned or controlled by NXP and may only be
 * used strictly in accordance with the applicable license terms. By expressly
 * accepting such terms or by downloading, installing, activating and/or otherwise
 * using the software, you are agreeing that you have read, and that you agree to
 * comply with and are bound by, such license terms. If you do not agree to be
 * bound by the applicable license terms, then you may not retain, install,
 * activate or otherwise use the software. The production use license in
 * Section 2.3 is expressly granted for this software.
 */
/* ###################################################################
**     Filename    : main.c
**     Project     : lpuart_echo_s32k144
**     Processor   : S32K144
**     Version     : Driver 01.00
**     Compiler    : GNU C Compiler
**     Date/Time   : 2020-02-20, 12:27, # CodeGen: 1
**     Abstract    :
**         Main module.
**         This module contains user's application code.
**     Settings    :
**     Contents    :
**         No public methods
**
** ###################################################################*/
/*!
** @file main.c
** @version 01.00
** @brief
**         Main module.
**         This module contains user's application code.
*/
/*!
**  @addtogroup main_module main module documentation
**  @{
*/
/* MODULE main */

/* Including needed modules to compile this module/procedure */
#include "sdk_project_config.h"
#include <stdio.h>
#include <string.h>

volatile int exit_code = 0;

/* Welcome message displayed at the console */
#define welcomeMsg "This example is an simple echo using LPUART\r\n\
it will send back any character you send to it.\r\n\
The board will greet you if you send 'Hello Board'\r\
\nNow you can begin typing:\r\n"

/* Error message displayed at the console, in case data is received erroneously */
#define errorMsg "An error occurred! The application will stop!\r\n"

/* Timeout in ms for blocking operations */
#define TIMEOUT     500U

/* Receive buffer size */
#define BUFFER_SIZE 256U

/* Buffer used to receive data from the console */
uint8_t buffer[BUFFER_SIZE];
uint8_t bufferIdx;

/* UART rx callback for continuous reception, byte by byte */
void rxCallback(void *driverState, uart_event_t event, void *userData)
{
    /* Unused parameters */
    (void)driverState;
    (void)userData;

    /* Check the event type */
    if (event == UART_EVENT_RX_FULL)
    {
        /* The reception stops when newline is received or the buffer is full */
        if ((buffer[bufferIdx] != '\n') && (bufferIdx != (BUFFER_SIZE - 2U)))
        {
            /* Update the buffer index and the rx buffer */
            bufferIdx++;
            LPUART_DRV_SetRxBuffer(INST_LPUART_LPUART_1, &buffer[bufferIdx], 1U);
        }
    }
}

/*!
 \brief The main function for the project.
 \details The startup initialization sequence is the following:
 * - startup asm routine
 * - main()
 */
int main(void)
{
  /* Write your local variable definition here */
  status_t status;
  /* Declare a buffer used to store the received data */
  uint32_t bytesRemaining;

  /* Write your code here */
  /* For example: for(;;) { } */

  /* Initialize and configure clocks
   *     -    see clock manager component for details
   */
  CLOCK_SYS_Init(g_clockManConfigsArr, CLOCK_MANAGER_CONFIG_CNT,
                 g_clockManCallbacksArr, CLOCK_MANAGER_CALLBACK_CNT);
  CLOCK_SYS_UpdateConfiguration(0U, CLOCK_MANAGER_POLICY_AGREEMENT);

  /* Initialize pins
   *    -    See PinSettings component for more info
   */
  PINS_DRV_Init(NUM_OF_CONFIGURED_PINS0, g_pin_mux_InitConfigArr0);

  /* Initialize LPUART instance */
  LPUART_DRV_Init(INST_LPUART_LPUART_1, &lpUartState1, &lpUartInitConfig1);
  /* Install the callback for rx events */
  LPUART_DRV_InstallRxCallback(INST_LPUART_LPUART_1, rxCallback, NULL);
  /* Send a welcome message */
  LPUART_DRV_SendDataBlocking(INST_LPUART_LPUART_1, (uint8_t *)welcomeMsg, strlen(welcomeMsg), TIMEOUT);

  /* Infinite loop:
   *     - Receive data from user
   *     - Echo the received data back
   */
  while (1)
  {
      /* Receive and store data byte by byte until new line character is received,
       * or the buffer becomes full (256 characters received)
       */
      LPUART_DRV_ReceiveData(INST_LPUART_LPUART_1, buffer, 1U);
      /* Wait for transfer to be completed */
      while(LPUART_DRV_GetReceiveStatus(INST_LPUART_LPUART_1, &bytesRemaining) == STATUS_BUSY);

      /* Check the status */
      status = LPUART_DRV_GetReceiveStatus(INST_LPUART_LPUART_1, &bytesRemaining);

      if (status != STATUS_SUCCESS)
      {
          /* If an error occurred, send the error message and exit the loop */
          LPUART_DRV_SendDataBlocking(INST_LPUART_LPUART_1, (uint8_t *)errorMsg, strlen(errorMsg), TIMEOUT);
          break;
      }

      /* Append string terminator to the received data */
      bufferIdx++;
      buffer[bufferIdx] = 0U;

      /* If the received string is "Hello Board", send back "Hello World" */
      if(strcmp((char *)buffer, "Hello Board\n") == 0)
      {
          strcpy((char *)buffer, "Hello World\n");
      }

      /* Send the received data back */
      LPUART_DRV_SendDataBlocking(INST_LPUART_LPUART_1, buffer, bufferIdx, TIMEOUT);
      /* Reset the buffer index to start a new reception */
      bufferIdx = 0U;
  }

  for(;;) {
    if(exit_code != 0) {
      break;
    }
  }
  return exit_code;
} /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/

/* END main */
/*!
 ** @}
 */

				
			
lpuart_echo_s32k144 demo code explanation:

Next blogs to read

ADC Peripheral in S32K144

Number of ADCs and Channels –> S32K144 contains two 12-bit SAR ADC modules, ADC0 and ADC1. Each ADC supports up to 16 external analog input channels. Note that ADCx_SEy refer to Channel y of ADCx. DMA support for ADC –> Continuous ADC sampling, like 4K samples/sec, can overload the CPU. Using the PDB to trigger the ADC helps reduce this load. For higher performance, the ADC can trigger DMA directly after each conversion, freeing up the CPU. There’s also a flexible option with TRGMUX, allowing DMA to trigger after multiple ADC conversions instead of just one. This gives more control based on what the application needs! ADC Interleaved Channel Functionality –> ADC interleaving allows multiple ADCs to sample the same signal alternately, improving performance by increasing sampling speed without overloading a single ADC. On devices with two ADCs, specific channels support this feature. For example, ADC0_SE4 and ADC1_SE14 can either work independently or interleave to sample a signal from PTB0. This interleaving is enabled by the SIM_CHIPCTL[ADC_INTERLEAVE_EN] bit, and other channels like ADC0_SE5/ADC1_SE15 can interleave on different pins (PTB1, PTB13, PTB14). Internal Supply Monitoring –> ADC peripheral can also be used to monitor the internal supply. This monitoring is done through ADC0 internal channel 0. Referencing Option for ADC –> The ADC offers two reference voltage options: VREFH/VREFL: The primary reference option. VALTH/VREFL: An alternate reference option. –> You can select between these references using the ADCx_SC2[REFSEL] bit. In S32K1xx devices, VALTH is equivalent to VDDA. If a package doesn’t have dedicated VREFH/VREFL pins, VREFH is internally tied to VDDA and VREFL to VSSA. When an external VREFH is available, it should either match VDDA or be within an allowed range below it. VREFH must not exceed VDDA, and VREFL should always connect to VSSA. –> In a nutshell, you can change the reference voltage for ADC conversion as per user requirements.  Trigger Sources Available for ADC -> In ADC systems, triggers are signals that start the conversion process, while pre-triggers are used to select or control specific ADC channels before conversion begins. They allow flexible control over when and how ADC conversions are initiated. -> ADC triggers and pre-triggers control when conversions start and which ADC channels are used. The Programmable Delay Block (PDB) or Trigger Multiplexer (TRGMUX) provides flexible trigger options: PDB Triggering: Automatically triggers ADC conversions and controls channels via up to 8 pre-triggers, reducing CPU involvement. Each PDB pairs with an ADC (PDB0-ADC0, PDB1-ADC1). TRGMUX Triggering: Offers flexible ADC triggers using external/internal signals. Modules like CMP, LPIT, RTC, and LPTMR can trigger the ADC. TRGMUX enables different peripherals to start ADC conversions without the PDB. -> The trigger source is controlled by SIM_ADCOPT[ADCxTRGSEL], allowing the selection of PDB or TRGMUX based on application needs. -> Hardware Triggering Schemes: Default Scheme (PDB): The most common method is using the PDB to trigger the ADC. This approach is suggested for general use because of its simplicity and automatic trigger mechanism. Alternative Scheme (TRGMUX): TRGMUX provides another option for hardware triggering, offering more flexibility in selecting which peripherals or pins will initiate ADC conversions. -> The SIM_ADCOPT[ADCxTRGSEL] field is used to control and configure the source of ADC triggers, allowing the system to choose between PDB or TRGMUX based on the application needs. To completely understand this Block Diagram, follow our course on AUTOSAR ADC. Trigger Selection for ADC –> You can select any combination of trigger enable and trigger for the ADC, but once selected, they cannot be changed on-the-fly. There are specific steps for switching the trigger or pre-trigger sources: –> To Change the Trigger Source: Stop the current trigger generation. Wait for 2.5 cycles of the ADC operating clock and 1.5 cycles of the ADC host interface clock, allowing the last trigger to latch. Check the ADC_SC2[TRGSTLAT] status until it becomes 0, indicating all queued conversions are completed. Update the trigger source as needed. Restart the trigger generation unit. –> For Immediate Trigger Change: Stop the current trigger generation. Flush the queued triggers by setting ADC_CFG1[CLRLTRG], except the one currently in progress. Wait for 2.5 cycles of the ADC operating clock. Check ADC_SC2[TRGSTLAT] until it becomes 0. Update the trigger source. Restart the trigger generation unit. –> Note: If these steps aren’t followed, some triggers might be missed without being reported. Trigger Handling and Capturing –> The four lower triggers can be latched, meaning trigger requests from any selected source are captured and processed one at a time. The ADC handles each latched trigger request sequentially, starting the next only after the current one is complete. This ensures that only one request is processed at a time while others wait in the queue. –> If a trigger request is repeated for the same trigger (0–3) while it’s being processed or already latched, the new request is ignored, and an error is flagged in the ADC_SC2[TRGSTERR] register. –> Trigger requests can arrive in two ways: (a) one at a time or (b) simultaneously. However, they are processed in a round-robin order. After completing the Pth request, the system looks for the next available request, starting from P+1 and cycling through until all latched triggers are processed, rolling back to 0 after reaching the last trigger (N-1). ADC Trigger and Pre-Trigger Configuration –> The ADC supports two main triggering schemes, as previously explained, through these two paths (using the ADC0_PDB0 triggering example): Direct Triggering Path: Used through the PDB starting from channel 4 onward. Multiplexed Triggering Path: Utilizes PDB/TRGMUX for channels 0 to 3 via a trigger latching mechanism. –> When configuring the ADC, you can either: Use the direct triggering path with PDB for channels 4 and above, while using PDB for channels 0 to 3, or Use only the TRGMUX path for channels 0 to 3. –> For the PDB direct triggering scheme, ensure that pre-triggers are spaced at least 4 bus clock cycles apart. The table below outlines the ADC triggering configurations and their behavior based on these paths. –> Note: The PDB only signals

Read More »

Servo Control Using PWM(MCAL Driver)

Overview Welcome to Module Interfacing using AUTOSAR MCAL driver. In this blog, we’ll learn how to interface an SG90 Servo Motor and control it with variations of different duty cycles.  What is Servo? The servo is a special motor used to move mechanical parts precisely. Unlike standard motors that continuously rotate after disconnecting it from the power supply, servos can position themselves at specific angles or positions, making them ideal for tasks requiring accuracy. This precision is achieved through a feedback system that constantly watches over the position of the output shaft, adjusting it as needed to match the required position. Widely used in robotics, automation, and hobbyist projects like remote-controlled cars and airplanes.  Why and How is Servo controlled? Controlling the Servo motor is essential for the application of precise movement and positioning. This helps you innovate different use cases in different places. Like determining torque exerted by the Servo motor which helped me create an automatic door latching system with traditional doors. Or determining the speed of shaft rotation for making a pinball game at home.  Different Servo Motor with PWM Frequency and Duty Cycle Servos are controlled using Pulse Width Modulation (PWM), where the position of the servo is determined by the width of the pulse in the PWM signal. However, different types of servos may operate at different PWM frequencies and have a wide range of PWM frequencies and duty cycles for control operation. PWM Frequency: Most hobby servos operate at a standard frequency of around 50 Hz, which corresponds to a pulse every 20 milliseconds (ms). However, specialized servos for high-speed applications or industrial uses may operate at higher frequencies to achieve faster response times. Standard Servos: Typically use 50 Hz. High-Speed Servos: Might use higher frequencies, up to 200 Hz or more for quicker positioning and response. PWM Duty Cycle (Pulse Width): The pulse width in a PWM signal determines the position of the servo. For standard servos: A pulse width of 0.5 ms corresponds to a 0-degree position. A pulse width of 1.5 ms corresponds to the 90-degree position (neutral or middle). A pulse width of 2.5 ms corresponds to the 180-degree position. Getting Started We are going to move toward the embedded software understanding of PWM frequency and duty cycle modulation, as per requirement, under the AUTOSAR MCAL standards, according to our DIY project statement. Make sure to follow the steps keenly and if any suggestion is invoked, please submit it on our community forum. Step 1: Cloning the Repo from our GettoByte Github Download the ElecronicsV board Demo codes from the GitHub Repo of Gettobyte Technologies. If you have installed the Git, then one can clone the repo. Otherwise, one can download the repo by its zip file. For cloning the repo, you can directly download it as a .zip file and extract it, else you can also use Tortoise Git to extract the files. Step 2: Opening the cloned repo in S32 Design Studio After getting the repo, now we are going to open the GitHub repo Example projects in S32 Design Studio. Make sure that you have downloaded the S32 Design Studio 3.4 and S32K1 RTD package versions 1.0.0 and 1.0.1 which we have stated in the tools installation. Follow the below steps mentioned in slider to Open the Example projects in S32 Design Studio. Step 1Click on File tab on top-left of S32 DS(Design Studio) and go to Open projects from File SystemStep 2Click on “Directory” button for accessing your storage and locate your folder to opened. In our case, it is the folder that is downloaded and extracted from GitHub Repo.Click HereStep 3You can also extract complete folder to S32 DS but it is recommended to extract to only use that folder which are completely build and requires no changes.Click HereStep 4Locating to CAN module only for focused working.Click HereStep 5CAN folder is located and click on “Select Folder”Click HereStep 6Click on “Finish” button and you have successfully imported the GitHub Repo.Click Here Previous slide Next slide Step 3: Building the specific code In Project Explorer, you can see all the files generated and included for the project but our main focus is on the .mex file which contains all portions of peripheral and MCU-related information. You can directly debug and run the code through the debug option. To understand the complete explanation of the .mex file and how these different peripherals have different parameters thorough which we can generate our required result, you can follow the details on the courses link mentioned. Code and Explanation main.c main.c C /* Including necessary configuration files. */ #include "Mcal.h" #include "Clock_Ip.h" #include "Port.h" #include "Pwm.h" /*Delay function*/ void TestDelay(uint32 delay); void TestDelay(uint32 delay) { static volatile uint32 DelayTimer = 0; while(DelayTimer<delay) { DelayTimer++; } DelayTimer=0; } uint16_t pwm_duty_cycle(uint8_t duty_cycle_percent) { uint16_t duty_cycle = ((32768 * duty_cycle_percent)/100); return (duty_cycle); } int main(void) { /********************************Clock Configuration for MCU****************************/ Clock_Ip_StatusType clockStatus; clockStatus = Clock_Ip_Init(&Mcu_aClockConfigPB_BOARD_InitPeripherals[0]); while (clockStatus != CLOCK_IP_SUCCESS) { clockStatus = Clock_Ip_Init(&Mcu_aClockConfigPB_BOARD_InitPeripherals[0]); } /* Busy wait until the System PLL is locked */ while (CLOCK_IP_PLL_LOCKED != Clock_Ip_GetPllStatus()); Clock_Ip_DistributePll(); /***************************************************************************************/ /* Initialize all pins using the Port driver */ Port_Init(NULL_PTR); /* Initialize all data structure and function of PWM */ Pwm_Init(&Pwm_Config_BOARD_InitPeripherals); /*Sets the our desired frequency 50Hz for Servo*/ Pwm_SetPeriodAndDuty(0,40000,pwm_duty_cycle(50)); TestDelay(700000); /* As our Servo, responds only from 0.5ms(2.5% Duty Cycle) * to 2.5ms(12.5% Duty Cycle), we create a up-down counter * for simulation */ double count = 2.5; /* * Direction = 0(UP) means the counter goes from 2.5 to 12.5 * whereas * Direction = 1(DOWN) means the counter goes from 12.5 to 2.5 */ uint8 direction = 0; /*Main Loop*/ for (;;) { if(direction == 0) { if(count <= 12.5){ Pwm_SetDutyCycle(0, pwm_duty_cycle(count)); TestDelay(700000); count += 0.5; } else{ direction = 1; } } else if(direction == 1) { if(count >= 2.5){ Pwm_SetDutyCycle(0, pwm_duty_cycle(count)); TestDelay(700000); count -= 0.5; } else{ direction = 0; } } } } Copy /* Including necessary configuration files. */ #include "Mcal.h" #include "Clock_Ip.h" #include "Port.h" #include "Pwm.h"

Read More »

What is Autosar Technology?

Before Autosar and challenges Before the development of AUTOSAR (AUTomotive Open System ARchitecture) in 2003, the automotive industry lacked a standardized approach to software architecture, hardware platforms, and development standards. AUTOSAR was created to address these challenges by providing a standardized software development infrastructure. It’s a global partnership between automotive industry participants, including OEMs, suppliers, semiconductor manufacturers, and software suppliers. Birth of Autosar/Timelines of Autosar // which companies united for autosar, with what motive it was invented and mention its timeline //organisation that are established because of autosar With respect to this background, the leading automobile companies and their first- tier suppliers formed a consortium in 2003, This partnership was established as an industry wide standard for the automobile electronics: AUTOSAR( Automotive Open System Architecture), which is headed by the following 10 “core partners”: BMW Group, Bosch, Continental, Daimler Chrysler, Ford Motor Company, General Motors, PSA Peugeot Citroen, Siemens, VDO, Toyota Motor Corporation and Volkswagen. Autosar Consortium has different members, mebers in the form of companies that contribute to it. The roles are varied in terms of their contribution and exploitation. These members are divided in 4 categories: Premium Members Associate Members Development Members Attendees Subscribers // give small brief about autosar members Timeline of Autosar: The first phase of Autosar started in 2003 and ended in 2006, during this phase 52 premium members, companies of the suppliers and software and semiconductor industries joined the development of this standard and made major contributions in the consortium.   Main Objective of Autosar Autosar was set up as a partenership to define an industry wide Themost important consequence of the stringent component-based approach of AUTOSAR, concerning the development process ,is as paration of application devel opment from the lower levels of the integration development (basics of software[BSW]). The separator between these two parts is the AUTOSAR run time environment (RTE), which concretely realizes the concept of a virtual functional bus( VFB) as an abstract ing communication principle. The idea of this concept is that an application does not need to know the concrete paths from data and signals below RTE when two applications communicate together. The main concept or object of the AUTOSAR architecture is to separate the application software from the basic software and make it independent of the hardware (standardized infrastructure). Autosar software architecture provides the scalability of ECU software for serveral car lines and variants. Meaning a customer can spend one time developmenr cost to develope and application like a parking assist system and reuse this application on different hardwares for all his car variants. What is Autosar Autosar was set up as a partenrship to define an industry wide standard for software programing of automotive electronics. Or in more technical way one can say a industry/global level standard for embedded system programing of electronics involved in building automotive systems. To overcome the challenges, Autosar defined a new development methodology for automotive software and software architecture. The Development methodology is focussed on a model-driven development style. The software architecture is defined without considertaion of the hardware on which the software components will run on later. This means that 2 software components might run on the same ECU or on different ECU’s. The communication between the components is then either an intra-ECU communication or an inter-ECU communication. To abstract from this The lightweight Classic AUTOSAR enables companies to perform thorough security testing on systems like electronic stability control (ESC), steering, electric parking brakes, park distance control, infotainment, anti-theft systems, remote keyless entry, and more. By using it, manufacturers can find security vulnerabilities accessible via external channels, such as Bluetooth or other public-facing interfaces. Analogy of Autosar Autosar Software Stack has 3 layers: BSW Layer RTE Layer Application Layer Let’s dwell into BSW Layer. BSW layer stands for Base Software. Which further is divided into 3 layers: MCAL Layer ECU Abstraction Layer Complex Drivers Service Layer Now we will understand these layers, with respect to software’s that are involved in an ECU of a Car. So let’s just dwell into simple building blocks of a ECU. ECU is made up of Microcontroller and with that microcontroller some external sensor/modules are connected to make it a complete functional product of the vehicle. Now to use Microcontroller from software side, Microcontroller driver is needed which is termed as MCU Real Time Drivers. And to use sensor/module from software side, their driver is needed which is termed as external driver. This external driver is developed using MCU RTD and Sensor Specific requirements. These Sensor and Modules are communicating with microcontroller using MCU drivers like UART, I2C, SPI and etc. and then according to sensor/module their driver is further developed above MCU driver. Further in an ECU, different software frameworks like: Operating System, Diagnostic, Logging, Memory analyzes is also used for fulfilling requirements that has to be provided by ECU. Now let’s relate the software requirements of ECU with Different layers of BSW layer. MCU Real Time Driver is MCAL layer in Automotive World. So MCAL layer has standardized the API’s that should be used to use MCU. For each peripheral of MCU, there are MCAL standard API’s. Any Microcontroller that has to be used in Automotive world, should have its MCU RTD designed according to MCAL standard. To use the sensors and modules software stack which is used is ECU Abstraction Layer. As to use a sensor with MCU, the peripheral through which sensor is connected that RTD stack would be needed to communicate with sensor. This RTD stack comes via MCAL layer and then sensor specific driver would be made using that MCAL layer module and specific driver that is developed lies in ECU Abstraction Layer. Also in an MCU peripheral there are number of features/ways to use. So to standardized those features and ways of accessing peripheral a software layer is made that also lies in ECU Abstraction Layer. After this comes other framework stacks of: OS, diagnostics and etc. Which comes in Service Layer. Layers in Autosar Application Layer: Different

Read More »

What is Microcontroller Technology?

Brief history of Microcontroller Microcontroller is an innovative technology that has revolutionize the world and made the electronic items so much feasible for us. Though microcontrollers have been in world since 1960’s. Its been around 60 years since the invention of Microcontroller technology and their are more then x amount of microcontroller being deployed right now in world. Lets explore and go back to history of microcontroller’s: What are Microcontrollers is an electronic chip which is designed in a way to do general tasks till eternity The life cycle of Microcontroller’s Microcontroller is designed from transistors, millions and millions and even billions of transistors are miniaturized into small size, to form building blocks of MCU, and these building blocks give them ability to control anything. The building blocks of MCU are: CPU, Memory and Peripherals. We will dive into these blocks after couple of minutes. The designing of these transistors is an art and science behind the chip designing. This art of technology is called as VLSI( Very Large Scale Integration). And Once the designing is done then these Chips are fabricated/manufactured to give us a final by product that is physical MCU chip. And This part is done by fabrication companies like TSMC. And after that fabrication, the packaging/assemble of integrated chip happens so that these millions and millions of transistors which are minitiasuered are enabled for practical usage in electronic devices. And after that programming on these MCU and extra circuitry around these MCU’s is developed to make the MCU do any specific task till eternity. These part are referred as Embedded Systems, in which software and hardware around the microcontroller is developed to make it use in final end product. Part of Software development for Microcontroller is called Embedded Software Development and part of Hardware development for MCU is called Embedded Hardware Development. In this video and chapter we will just get ourselves stick to microcontroller technology, and focus on what things are involved for learning and using microcontroller. Though their are many topics and technologies which can be deep dive, which we will do in separate videos.   Building blocks of Microcontroller chip are Microcontroller chips have 3 building block, first is CPU, second is Memory and third is peripherals. For better understanding take the analogy of microcontroller with human body. Just like their is human body, same way their is microcontroller. In human body we have brain which does all the processing, calculations and thinking. In the case of microcontroller, CPU does all that. Then in human body we have body parts to interact with outside world, same way microcontroller have different peripherals to interact with outside world. We humans have memory/yadash based on which we do the work and do the tasks. How to sit, how to walk, how to use legs, how to use different body parents, and all these things are feed in our memory, same way microcontrollers have memory, into which instructions are written on how to use its different peripherals and how to control those peripherals and what to do when some data comes from those peripherals. Now lets just deep dive into these functional blocks in more technical understanding and learning. CPU CPU stands for Central Processing Unit, it is an integral part of microcontroller which does all the hardcore computing work. computing work in terms of electronic chip means: addition, subtraction, multiplication, division of electronic data. How fast this can be done and level of complex calculations it can do. CPU does the computing work, by a set of basic rules on how a CPU should work. These set of rules are called as Instruction Set Architecture(ISA). Their are 2 most popular types of ISA: RISC( Reduced Instruction Set Computer) CISC(Complex Instruction Set Computer) In Current modern world, RISC architecture based CPUs and microcontroller are what is widely used and adapted. Examples of RISC is ARM CPU that we see in Apple MAC book the M1 chip. another example is RISC-5 CPU, that we can see in Vega processor, which is India’s first indigenous CPU designed by xyz organization Examples of CISC is Intel 4004, which is world’s first commercially available CPU launched in 1971. Another is x86 CPU, most desktops and laptops sold are based on x86 CPU. Their terminology which we hear intel I5 processor and all they all are part of these CPU’s. Often CPU word/terminology is used interchangeable with processor or core. So wherever we mention, processor/core or CPU words they mean same thing. Another important factor on which CPU computing work matters is bit size of CPU. Meaning how much size of data CPU can execute at a time. We measure this thing in bits unit. So their are 8 bits, 16 bits and 32 bits CPU’s. In which 8 bit CPU means it can at a time can execute data of 8 bit length. 16 and 32 bit CPU means they can execute data of 16 bit and 32 bit length. Now as the bit size of CPU increases, it means more powerful and fast they are. For now we are not going too much in detail about CPU types, history and its world as that will deviate us from current topic of microcontroller. We will explore in detail about these terminologies in what is microprocessor technology. Peripherals: Peripherals are body parts of Microcontroller, it is peripherals through which microcontroller interacts with outside world. There can be more then 20 peripherals in some MCU’s and in some MCU’s their can be just 5 peripherals. There are some general purpose peripheral which are their in all or most of the MCU’s: which are GPIO, ADC, TIMERS, I2C, SPI, UART. Using these peripherals one can process and control any sensor/module connected to MCU. I2C, SPI and UART are communication protocol via which we can connect almost any sensor/module to MCU. Be it LCD screen, ethernet module, audio devices, Wi-Fi modules or any other sensor. And via GPIO, TIMER and ADC peripherals we can

Read More »

FlexTimer peripheral of NXP S32K1xx MCU( S32K144 MCU and ElecronicsV3 Board)

About FlexTimer Peripheral of S32K144 MCU: What is FlexTIMER Peripheral? FlexTimer is a peripheral present in NXP S32K1xx MCU’s, which is used for input capture, output capture, generation of PWM signals and time delays. We are going to focus on PWM signals part and usecase of FTM Peripheral for generating PWM signals. As FTM is a peripheral of MCU, so it has intances and with each instance certain number of MCU pins which are referred as channels. In S32K144 their are 4 instances of FTM and each instance has 8 channels. Instances are abrievted as FTM0, FTM1, FTM2 and FTM3. Each Instance has its own Peripheral registers where the configuration of those instances is done.  Their are number of registers, in FTM peripheral through which its configuration for different features is done and we also get status. We are not going to dive into every register, will mention important registers, as in industry register level coding is not implemented but understanding of registers is what is important. Each Instance has 8 channels, which are reffered as CH0-CH7. So naming convection goes like this: Table showing FTM Instance and Then FTM Channels of that sinstance and all MCU pins which can be used for that channel. For PWM,  FTM Peripheral has following functnalities and features PWM Signal Type: Center Aligned and Edge Aligned PWM Signals: Combine Mode PWM signals in inverted/duplicate PWM Interrupts: Every channel has interrupt source. Interrupt can be generated on counter match or counter overflow. Detection of rising and failing edges of PWM signals: We can configure interrupt generation when counter matches or overflows based on the polaruty of PWM signal. Hardware-Software Trigger: Generation of PWM signals and variation of PWM parameters at the detection of some hardware specific events. Lets say we want to generate PWM pulse only when some ADC readings are taken. So we can configure PWM signal to generate when ADC hardware conversion si done. Fault control and synchronization points.  How FTM peripheral works is, For understanding the ftm peripheral features and functionalities we will understand them via storytelling!!! Story telling in terms of what steps have to be followed to use ftm peripheral and correspondingly covering its different features. We configure the clock values for ftm peripheral, that is whether the ftm peripheral is going to get clock from system clock, fixed clock or external clock and  also configures the prescaler values, to divide the ftm clock if needed. FTM CLOCK CONFIGURATION IS IMPORTANT step as based on this only, parameters of pwm signals are calculated. Their are 3 inputs of clocks for FTM peripheral: either system clock, or crystal oscillator clock( that is fixed clock) or some external clock ( connected to some pin of MCU). After that we configure in which mode FTM peripheral has to be used, whether input capture mode, output capture mode. Output capture mode is what we are going to use. Output capture mode means outputings some digital signals. And Input capture mode means inputting some digital signals. After output capture mode,  which type of pwm signal. These settings are done by setting the values of highlighted bits according to following table. These bits are part of these registers. Based on the mode of ftm peripheral, ftm peripheral will work. As in this module we are learning and focusing on pwm signals, so we highlighted sections of table is what is going to be of our concern.    Edge Aligned Mode Center Aligned Mode Combine Mode(Complementary) Each Instance has 8 channels, so every channel has its own peripheral registers by the name of CnSC. In CnSC register this pwm mode of configuration is done.  After that, we configure the values into counters of FTM. As stated Timer peripheral has 3 counters in it. MAX counter, Variable counter and Threshold counter. In FTM peripheral MAX counter is MOD peripheral register. Value put on this register determines the frequency /period of pwm signal. Variable register is COUNT peripheral register. This counter starts incrementing from 0 once ftm peripheral is enabled or triggered. Threshol Counter we will touch in couple of mins after. For each channel their is register CnV. This register act as Threshold counter for pwm signal coming from corresponding channel or we can say pin of mcu. Value put on this register will determine the duty cycle of the signal as when COUNT counter matches the value of this register, pwm signal state changes according to configured polarity. Now polarity of pwm channel will determine, whether pwm signal would have high to low transition or low to high transition on counter match. The polarity configuration is important as this will determine the duty cycle parameter. So there are 2 things in polarity, state of pwm signal before counter match and state of pwm signal after counter match. Based on polarity configuration, rising or failing edges would be generated on counter match and counter overflows. 6) Another important thing is updates of counter registers and pwm polarity. You see, counter registers like MOD, CnV and COUNT very much control the PWM signal parameters and PWM polarity register bits control the logic levels of pwm signal. Ftm peripheral has feature to configure when these register values should be updated, that is either on software trigger means software will write the Data on the registers and it would be loaded into them. Or hardware trigger that on detection of sone external signal, the values of these registers would be changed. This updation of register is also called as Reload point of counter registers and values in FTM peripheral. If we are using interrupts then interrupt configuration is also done for each indiviual channel for different events. By events we mean counter match or counter overfflow. For every channels of FTM Instance their are bits in x register, If we set these bits then interrupt functionaly would be on for those Channels. When Counter match happens then channel interrupt handlers are fired and when counter oveflow happens then overflow interrupt handler is fired. Overflow interrupt handler is comman

Read More »

PWM Driver of Autosar MCAL Layer

What is PWM Driver? PWM Driver is the library for generating PWM signals via Automotive MCU’s. This Driver is part of Autosar MCAL layer and it is global level RTD standard that is followed by all semiconductor companies to generate the PWM signals using their microcontrollers for automotive applications. This specification describes the API for generating and handling different PWM signals via automotive MCU’s. This software module includes GUI interface for initialization, configuration of PWM channels and peripheral instances. It supports the framework for using advance to basic features which are their with PWM peripherals of different MCU’s through which PWM signals are generated.. Also PWM Driver handles the variation of PWM parameters like  Frequency, Duty Cycle, Timer Period and etc. PWM Driver can handles all the advance features like fault control, synchronization points, hardware trigger, softare control values, complementary PWM signals, DMA/Interrupts for PWM signals. . PWM Driver is built over the peripheral IP layer of the Microcontroller and driving functionalities. Main objectives of this monolithic SPI Handler/Driver are to take the best of each microcontroller features and to allow implementation optimization depending on static configuration to fit as much as possible to ECU needs. Hence, this specification defines selectable levels of functionalities and configurable features to allow the design of a high scalable module that exploits the peculiarities of the microcontroller. What are PWM Signals and how are they generated? Types of PWM Signals: Parameters of PWM Signals: To generate the PWM signals via Automotive MCU’s using Autosar MCAL Layer API’s: At first to configure the MCU pins in PWM peripheral mode via PORT Driver: We can generate the PWM Signals from Microcontroller through different peripherals like Timer Peripheral of the MCU or FlexIO peripheral. So at first selection of MCU pin has to be done from which PWM signal has to be genarted and then configuring that MCU pin in corresponding peripheral mode. After that comes the clock selection and configuration via MCU Driver: MCU Driver is responsible for clock configurations and clock settings of Microcontroller. Setting of systems clock, peripehral clocks all these settings are done by MCU Driver. And for generating the PWM Signals, what clock frequency has been input to it is very crucuial so as to calculate its parameters. After this MCL Driver selection is also important: We can generate PWM signals from Microcontroller via different peripherals. Either Timer based peripheral or FlexIO peripheral. By tradation Timer peripheral is recommended and widely used. But as PWM Driver has been designed with global level coverage, it is also dependent on FlexIO peripheral, so FlexIO peripheral concentric files are generated via MCL Driver. So we will just select the MCL Driver, so that dependent files are included in project. In this course, we will focus on PWM signal generation via Timer peripheral. In our case we will be using NXP S32K144 MCU which has FlexTIMER Peripheral. After all above three will be coming our PWM Driver configuration and selection. That is what is the main moto of the course module. We will understand what all configurations are their in PWM Driver. How PWM Driver works and important API;s of it for generating the PWM Signals. Their would also be use of Platform Module, that is responsible for interrupt settings and configuration. We are going to use Interrupts with PWM Signals to detect the rising and failing edges of PWM signals and do some application specific tasks on those edges. Functional concepts of PWM Driver: Now PWM Driver has general/global functional concepts which are applicable to all automotive MCU’s, which are important to understand and know so as to configure the PWM Driver. Selection of PWM hardware channel: Selection of PWM Channel polarity Selection of PWM IDLE Mode Selection of PWM feature enablement: PWM Signal modes: Apart from the above general functional concepts, the PWM peripheral level concepts of the corresponding Micrcocontroller is also important to understand. These peripheral level functional concepts are different from one MCU to another. As their are different peripherals for generating PWM signals in different MCU’s. But the usage of these concepts is used only at the time of PWM GUI configuration. At the time of writing the embedded application, same set of API’s, chronology and parameters is used. In our case we have ElecronicsV3 Board, which has S32K144 MCU and we are using FlexTIMER peripheral of this MCU. Concepts description with respect to Author: Kunal Gupta

Read More »
Kunal Gupta
Author: Kunal Gupta

Author

Kunal Gupta

Leave a comment

Stay Updated With Us

Error: Contact form not found.

      Blog