uMIDI
The swiss army knife for quick and easy developement of MIDI applications.
Macros | Functions
pwm.h File Reference

PWM configuration and service functions. More...

#include <stdint.h>
#include "lookup_tables.h"
Include dependency graph for pwm.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define PWM_MAX_DUTY   ((1L << lookup_table_resolution) - 1)
 Maximum duty cycle of the PWM. More...
 

Functions

void init_pwm_module (uint16_t(*conversion_function)(midi_value_t value))
 Initializes the PWM. More...
 
void set_pwm_duty_cycle (midi_value_t duty)
 Updates the PWM duty cycle. More...
 

Detailed Description

PWM configuration and service functions.

Macro Definition Documentation

◆ PWM_MAX_DUTY

#define PWM_MAX_DUTY   ((1L << lookup_table_resolution) - 1)

Maximum duty cycle of the PWM.

Function Documentation

◆ init_pwm_module()

void init_pwm_module ( uint16_t(*)(midi_value_t value)  conversion_function)

Initializes the PWM.

CPU timer 1 is clocked with the system clock (32 MHz) and the compare output A is set up to output a dual slope PWM. Additionally, a conversion function which is used in set_pwm_duty_cycle() to compute the duty cycle compare values is registered.

Parameters
conversion_functionpointer to a function converting midi values to pwm compare register values
See also
wave

◆ set_pwm_duty_cycle()

void set_pwm_duty_cycle ( midi_value_t  duty)

Updates the PWM duty cycle.

Computes a suitable duty cycle compare value and writes the PWM counter compare register. This procedure can be used to manually control the modulation.

Parameters
dutythe desired duty cycle [0..MIDI_MAX_VALUE]