Skip to content

devcoons/stm32-drv-pwm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

DRIVER PWM

PWM driver reusable in different platforms.

Supported Hardware

  • STM32L552

Functions Guide

  • pwm_initialize : used for initialize the peripheral.
  • pwm_deinitialize : used for de-initialize the peripheral.
  • pwm_start : used for start the peripheral.
  • pwm_stop : used for stop the peripheral.
  • pwm_set_period : used for set the period (sets the prescaler at 50-1 and the period at 100-1).
  • pwm_set_duty_cycle : used for set the duty cycle.
  • pwm_set_frequency : used for set the duty cycle.

How to use

  • Include the header file drv_pwm.h
  • Configure the timer (TIMx) peripheral to operate in PWM mode with CHx output.
  • Create the pwm_t instance. The following members of the structure must be defined:
    • instance.handler : handler of choice (ex. &tim1).
    • instance.channel : enabled PWM channel (ex. TIM_CHANNEL_3).
    • instance.mx_init : PWM initializing function generated by the configuration tool (ex. MX_TIM1_Init).
pwm_t hpwm =
{
		.handler =&htim1,
		.channel= TIM_CHANNEL_1,
		.init = MX_TIM1_Init,
		.clock_freq_mhz = 40
};
  • Use the function pwm_initialize to initialize the peripheral and pwm_set_duty_cycle to set the desired duty cycle.

Example

Let's consider a NUCLEO - L552ZE-Q. The TIM1 timer peripheral has been configured to operate in PWM mode on channel 3 (TIM_CHANNEL_3).

pwm_initialize(&hpwm); //structure defined above
pwm_start(&hpwm);
pwm_set_period(&hpwm , 100) //the function currently sets the period at 100-1 independetly from the inseryed value
pwm_set_duty_cycle(&hpwm ,20);
pwm_set_frequency(&hpm,15000);
pwm_set_duty_cycle(&hpwm ,75);

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages