PWM Overview

Micael Coutinho,autosarbswpwm

As part of the MCAL layer, learn how you can use the PWM module in Autosar for your projects that require PWM modulation

Recently, we have been covering all the MCAL modules. We started with the SPI, on SPI Overview (opens in a new tab) and went through DIO and port, on DIO and Port Overview (opens in a new tab). Today, we'll continue on this journey, this time with our eyes turned into the PWM (Pulse Width Modulation) module.

The PWM module is part of the MCAL in the Autosar layered architecture, and its purpose is to provide indirection on the hardware (i.e. no matter what microcontroller you're using, the interface will never change). It enables you to create and control the duty cycle and frequency of PWM signals. The flow is simple. Such as with SPI, you configure the port pins you want to use (in the Port module), configure the PWM signals within the PWM module, where you can specify the relevant parameters:

Optionally, you can have some more parameters, if supported by your hardware:

Some considerations when using the PWM module is that you need to know the underlying time unit in ticks, as that is the unit expected to control the period of your PWM signal. This is usually not a big deal, as you're supposed to interact with a PWM signal (and other MCAL modules, in fact) through a component in the IO Hardware Abstraction Layer (IOHwAbs), which converts the value in ticks into a period in an intuitive unit. Another is that some PWM drivers offers some operation modes with lower power consumption, at the cost of a slower reaction time. This is optional and might not be present in your PWM driver, but if you have it, that's something that will reduce overhead for your system, due to asynchronous operation (at the cost of speed). We'll see this in action in a second.

Now, let's explore the APIs available to the user:

Aside from the aforementioned APIs, there are also Pwm_Notification_<Channel> and IoHwAb_Pwm_NotifyReadyForPowerState<Mode>, which serve as callbacks for PWM signals edge changes and a callback for when a specific power state is ready

Alright, that's about all you need to know, regarding PWM in the Autosar Layered Architecture! We hope this article provided you with enough knowledge to enable you to configure the PWM module. And, with the exception of the underlying ticking source for the PWM, which is heavily microcontroller-dependent, everything is in here. See you soon, remember to subscribe to our mailing list and share this article with your coworkers, so that you all can evolve your Autosar knowledge together!

Author: Micael Coutinho (opens in a new tab)

References:

© AutosarToday —@LinkedIn