#ifndef PWM_6STEP_EXPERIMENT_H
#define PWM_6STEP_EXPERIMENT_H
#include <libopencm3/stm32/f4/rcc.h>
#include <libopencm3/stm32/f4/gpio.h>
#include <libopencm3/stm32/f4/timer.h>
#include <libopencm3/stm32/nvic.h>
#include <libopencm3/stm32/exti.h>
#include <math.h>
#define system_freq 168000000 //168MHz, System Clock frequency
#define pwm_freq 64000 //64KHz, frequency of the PWM wave, integer value,
#define prescale 1 //prescale value, used to be able to have a bigger range of values for the pwm wave periods, see below.
#define pwm_period_ARR system_freq/( pwm_freq*(prescale+1) ) //this defines de pwm wave period based on the frequency of the clock
#define pwmfreq_f 64000.0f //frequency of the pwn, floating that the hardware can handle
#define DOWN 0 //value if DOWN
#define UP 1 //value if UP
int direction=UP; //variable that will indicate if the button will rise the speed or not
#define sine_freq_increment 10.0f //defines the change of frecuency that will happen each time the button is pressed.
#define max_sine_freq 100.0f //defines the top frecuency
#define min_sine_freq 20.0f //defines the bottom frecuency
float current_freq = min_sine_freq+1.0f; //define current frecuency of the sinusoidal waves
#define repetition_counter_value 0 //repetition counter, not used in this example but can be used to start a triggered interruption after a certain number of events
#define deadtime_percentage 0.10f //defines the deadtime between the complementary outputs
#define attenuation_value 0.5f //attenuation value, allows to attenuate the amplitude of the wave witout changing it's frequency
#define initial_duty_cycle 0.5f
#define PI 3.1415926535f //PI value
#define FALLING 0
#define RISING 1
u16 exti_direction = FALLING;
#endif
Motor Control
INDEX