#include <avr/io.h>
#include <avr/signal.h>
#include <pwm.h>
#include <utils.h>
#include <avr/pgmspace.h>
#include <brushless.h>
#include "brushless_3phase_digital_hall_config.h"
Go to the source code of this file.
Defines | |
#define | INIT_INT() sbi(TIMSK, TOIE0) |
#define | INT SIG_OVERFLOW0 |
Functions | |
void | brushless_speed_update_manage (void *dummy) |
volatile uint8_t pwm_division_timer | asm ("pwm_div") |
SIGNAL (INT) | |
void | brushless_init (void) |
void | brushless_0_set_parameters (brushless_speed speed, brushless_torque torque) |
brushless | brushless_0_get_mesures (void) |
void | brushless_0_set_position (brushless_position p) |
void | brushless_0_register_periodic_event (void(*f)(brushless)) |
int32_t | brushless_get_speed (void *motor_num) |
int32_t | brushless_get_pos (void *motor_num) |
void | brushless_set_torque (void *motor_num, int32_t torque) |
void | brushless_set_speed (void *motor_num, int32_t speed) |
Variables | |
const int8_t | g_brushless_angle [] = {0, 1, 5, 0, 3, 2, 4, 0} |
const int8_t PROGMEM | g_brushless_phase1 [] = {0, 1, -1, 0, 0, 1, -1, 0} |
const int8_t PROGMEM | g_brushless_phase2 [] = {0, 0, 1, 1, -1, -1, 0, 0} |
const int8_t PROGMEM | g_brushless_phase3 [] = {0, -1, 0, -1, 1, 0, 1, 0} |
brushless_position | g_brushless_0_position_previous |
brushless | g_brushless_0 |
brushless_torque | g_brushless_0_torque |
uint16_t | g_brushless_0_pwm_divider = 1 |
void(* | periodic_event_0 )(brushless)=0 |
volatile uint8_t | interrupt_pwm |
volatile uint8_t | pwm_previous_sensors_0 = 0 |
brushless_speed | speed_mem_0 = BRUSHLESS_MAX_SPEED |
brushless_torque | torque_mem_0 = 0 |
#define INIT_INT | ( | ) | sbi(TIMSK, TOIE0) |
This module handles a brushless motor with 3 phases, wired in triangle or star. 3 hall sensors are used wih digital output. 3 PWM are outputted, these MUST be synchronized !!
The control value is a voltage. This can be assimiled to a torque at low speeds.
There is a possibility of also of limiting the speed. This is accomplished by slowing down the sampling speed of the sensors. Doing this,the motor effective torque is reduced when the speed is such that the sensor actuation approaches the sampling frequency. use this technique carefully, because the motor has already his full voltage applied, an can dissipate a lot of energy, especially at low speeds.
there is no external manage function, as the manage is done at the PWM speed (overflow of one PWM timer is used.) This function is speed optimized. ceci est une commande de moteur brushless triphase en etoile, utilisant 3 capteurs a effet hall digitaux. En sortie on a 3 PWM (il est necessaire de les synchroniser !)
pour le commande en couple, on joue sur les pwm (pseudo-couple) et pour la commande en vitesse, on joue sur la frequence de rafraichissement des phases par rapport aux capteurs. cette astuce simple permet de faire facilement une consigne de vitesse (pas besoin d'asservissement) mais des vitesses faibles sont saccadees. calculating the event to use, based on PWM definition of the phase 1 The two motors function on the same timer!
Definition at line 78 of file brushless.c.
Referenced by brushless_init().
#define INT SIG_OVERFLOW0 |
Definition at line 79 of file brushless.c.
volatile uint8_t pwm_division_timer asm | ( | "pwm_div" | ) |
This function is made of 5 parts :
Typically, PWM update is slower than angle update, in order to not skip angle counting.
Typically, speed update is a lot slower than angle update in order to have a speed that is sampled at a correct rate. This event can trigger an action, this is especially used if you have a servo control.
examples for a pretty fast motor :
brushless brushless_0_get_mesures | ( | void | ) |
calculates the speed update info. To be called externally only if not internally, ie if the BRUSHLESS_MANAGE_EXTERNAL is set get current speed and position This function is very useful to get synchronous speed and torque info
Definition at line 475 of file brushless.c.
Referenced by brushless_get_pos(), and brushless_get_speed().
void brushless_0_register_periodic_event | ( | void(*)(brushless) | f | ) |
registers an event function that triggers periodically, and synchronously with the speed measurement
Definition at line 500 of file brushless.c.
void brushless_0_set_parameters | ( | brushless_speed | speed, | |
brushless_torque | torque | |||
) |
sets a consign speed and torque if you do not use the speed coarse limitation, please configure with BRUSHLESS_MAX_SPEED
Definition at line 438 of file brushless.c.
Referenced by brushless_set_speed(), and brushless_set_torque().
void brushless_0_set_position | ( | brushless_position | p | ) |
sets the position counter
Definition at line 489 of file brushless.c.
int32_t brushless_get_pos | ( | void * | motor_num | ) |
get position function, compatible with control_system. Argument not used.
Definition at line 524 of file brushless.c.
int32_t brushless_get_speed | ( | void * | motor_num | ) |
acess functions for the control system interface get speed function, compatible with control_system. Argument not used.
Definition at line 514 of file brushless.c.
void brushless_init | ( | void | ) |
initialisation, also executes pwm_init
Definition at line 417 of file brushless.c.
void brushless_set_speed | ( | void * | motor_num, | |
int32_t | speed | |||
) |
set speed function, compatible with control_system. first argument not used.
Definition at line 540 of file brushless.c.
void brushless_set_torque | ( | void * | motor_num, | |
int32_t | torque | |||
) |
set torque function, compatible with control_system. first argument not used.
Definition at line 534 of file brushless.c.
void brushless_speed_update_manage | ( | void * | dummy | ) |
Definition at line 377 of file brushless.c.
References parse_symbols::f, g_brushless_0_position_previous, IRQ_LOCK, IRQ_UNLOCK, periodic_event_0, brushless::position, and brushless::speed.
Referenced by SIGNAL().
SIGNAL | ( | INT | ) |
PWM division part
various definitions
sensors acquisition part extraction of the sensor signals, and built up of a 3 bit ordened byte this is done every time
the angle update part
speed update part
Definition at line 214 of file brushless.c.
References brushless_speed_update_manage(), g_brushless_0_pwm_divider, g_brushless_0_torque, g_brushless_angle, g_brushless_phase1, g_brushless_phase2, g_brushless_phase3, interrupt_pwm, IRQ_LOCK, IRQ_UNLOCK, PIN, brushless::position, PWM_MAX, pwm_previous_sensors_0, and sei.
Definition at line 126 of file brushless.c.
brushless_position g_brushless_0_position_previous |
Definition at line 122 of file brushless.c.
Referenced by brushless_0_set_position(), and brushless_speed_update_manage().
uint16_t g_brushless_0_pwm_divider = 1 |
Definition at line 134 of file brushless.c.
Referenced by brushless_0_set_parameters(), and SIGNAL().
brushless_torque g_brushless_0_torque |
Definition at line 130 of file brushless.c.
Referenced by brushless_0_set_parameters(), and SIGNAL().
const int8_t g_brushless_angle[] = {0, 1, 5, 0, 3, 2, 4, 0} |
2 LUT tables: sensors > relative electric angle sensors > phase information
decimal value : 0 1 2 3 4 5 6 7 sensors state : 000 001 010 011 100 101 110 111 is this a valid state? : NO yes yes yes yes yes yes NO
Definition at line 108 of file brushless.c.
Referenced by SIGNAL().
const int8_t PROGMEM g_brushless_phase1[] = {0, 1, -1, 0, 0, 1, -1, 0} |
const int8_t PROGMEM g_brushless_phase2[] = {0, 0, 1, 1, -1, -1, 0, 0} |
const int8_t PROGMEM g_brushless_phase3[] = {0, -1, 0, -1, 1, 0, 1, 0} |
volatile uint8_t interrupt_pwm |
void(* periodic_event_0)(brushless)=0 |
Referenced by brushless_0_register_periodic_event(), and brushless_speed_update_manage().
volatile uint8_t pwm_previous_sensors_0 = 0 |
Definition at line 169 of file brushless.c.
Referenced by brushless_0_set_parameters(), and SIGNAL().
brushless_speed speed_mem_0 = BRUSHLESS_MAX_SPEED |
Definition at line 412 of file brushless.c.
brushless_torque torque_mem_0 = 0 |
Definition at line 413 of file brushless.c.