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

PWM configuration and service functions. More...

#include <stdbool.h>
#include <stdint.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include "gpio.h"
#include "lookup_tables.h"
#include "math.h"
#include "midi.h"
#include "pwm.h"
Include dependency graph for pwm.c:

Functions

void init_pwm_module (uint16_t(*const 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...
 

Variables

static uint16_t(* convert_pwm_range )(midi_value_t value)
 

Detailed Description

PWM configuration and service functions.

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]

Variable Documentation

◆ convert_pwm_range

uint16_t(* convert_pwm_range) (midi_value_t value)
static