Half Bridge Driver

PWM timer functions for half bridge of DC/DC converter.

Generates the synchronous PWM signal for the half bridge in the DC/DC converter. Depending on the MCU, either the advanced timer TIM1 or the basic timer TIM3 is used.

Functions

void half_bridge_init(int freq_kHz, int deadtime_ns, float min_duty, float max_duty)

Initiatializes the registers to generate the PWM signal and sets duty cycle limits

Parameters:
  • freq_kHz – Switching frequency in kHz

  • deadtime_ns – Deadtime in ns between switching the two FETs on/off

  • min_duty – Minimum duty cycle (e.g. 0.5 for limiting input voltage)

  • max_duty – Maximum duty cycle (e.g. 0.97 for charge pump)

void half_bridge_set_ccr(uint16_t ccr)

Set raw timer capture/compare register

This function allows to change the PWM with minimum step size.

Parameters:

ccr – Timer CCR value (between 0 and ARR)

uint16_t half_bridge_get_ccr()

Get raw timer capture/compare register

Returns:

Timer CCR value (between 0 and ARR)

uint16_t half_bridge_get_arr()

Get raw timer auto-reload register

Returns:

Timer ARR value

void half_bridge_set_duty_cycle(float duty)

Set the duty cycle of the PWM signal

Parameters:

duty – Duty cycle between 0.0 and 1.0

float half_bridge_get_duty_cycle()

Read the currently set duty cycle

Returns:

Duty cycle between 0.0 and 1.0

void half_bridge_start()

Start the PWM generation

Important: Valid duty cycle / CCR has to be set before starting

void half_bridge_stop()

Stop the PWM generation

bool half_bridge_enabled()

Get status of the PWM output

Returns:

True if PWM output enabled