aversive_10-03-12/modules/devices/brushless_motors/brushless_3phase_digital_hall_double/brushless.c File Reference

#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_double_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)
void brushless_1_set_parameters (brushless_speed speed, brushless_torque torque)
brushless brushless_0_get_mesures (void)
brushless brushless_1_get_mesures (void)
void brushless_0_set_position (brushless_position p)
void brushless_1_set_position (brushless_position p)
void brushless_0_register_periodic_event (void(*f)(brushless))
void brushless_1_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_position g_brushless_1_position_previous
brushless g_brushless_0
brushless g_brushless_1
brushless_torque g_brushless_0_torque
brushless_torque g_brushless_1_torque
uint16_t g_brushless_0_pwm_divider = 1
uint16_t g_brushless_1_pwm_divider = 1
void(* periodic_event_0 )(brushless)=0
void(* periodic_event_1 )(brushless)=0
volatile uint8_t interrupt_pwm
volatile uint8_t pwm_previous_sensors_0 = 0
volatile uint8_t pwm_previous_sensors_1 = 0
brushless_speed speed_mem_0 = BRUSHLESS_MAX_SPEED
brushless_torque torque_mem_0 = 0
brushless_speed speed_mem_1 = BRUSHLESS_MAX_SPEED
brushless_torque torque_mem_1 = 0


Define Documentation

 
#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.

#define INT   SIG_OVERFLOW0

Definition at line 79 of file brushless.c.


Function Documentation

volatile uint8_t pwm_division_timer asm ( "pwm_div"   ) 

This function is made of 5 parts :

  • pwm divsion : gives a master frequency for the next parts, by dividing the PWM frequency (can also be set to 1)
  • sensors acquisition : done every time
  • angle update : done when there is a change in sensor state since last angle update
  • PWM update : done only every x (every g_brushless_recurrence -1) and skipped if there is no change since last pwm update
  • speed update : done only every y () this updates the speed

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 :

  • PWM at 30 kHz
  • angle update at 10 kHz
  • PWM update at 5 kHz or lower, depending on speed setting
  • speed update at 100 Hz

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 623 of file brushless.c.

References IRQ_LOCK, and IRQ_UNLOCK.

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 666 of file brushless.c.

References parse_symbols::f, IRQ_LOCK, IRQ_UNLOCK, and periodic_event_0.

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 555 of file brushless.c.

References g_brushless_0_pwm_divider, g_brushless_0_torque, IRQ_LOCK, IRQ_UNLOCK, and pwm_previous_sensors_0.

void brushless_0_set_position ( brushless_position  p  ) 

sets the position counter

Definition at line 648 of file brushless.c.

References g_brushless_0_position_previous, IRQ_LOCK, IRQ_UNLOCK, and brushless::position.

brushless brushless_1_get_mesures ( void   ) 

Definition at line 634 of file brushless.c.

References IRQ_LOCK, and IRQ_UNLOCK.

Referenced by brushless_get_pos(), and brushless_get_speed().

void brushless_1_register_periodic_event ( void(*)(brushless f  ) 

Definition at line 673 of file brushless.c.

References parse_symbols::f, IRQ_LOCK, IRQ_UNLOCK, and periodic_event_1.

void brushless_1_set_parameters ( brushless_speed  speed,
brushless_torque  torque 
)

void brushless_1_set_position ( brushless_position  p  ) 

int32_t brushless_get_pos ( void *  motor_num  ) 

get position function, compatible with control_system. Argument not used.

Definition at line 700 of file brushless.c.

References brushless_0_get_mesures(), brushless_1_get_mesures(), and brushless::position.

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 687 of file brushless.c.

References brushless_0_get_mesures(), brushless_1_get_mesures(), and brushless::speed.

void brushless_init ( void   ) 

initialisation, also executes pwm_init

Definition at line 528 of file brushless.c.

References INIT_INT, pwm_init(), and sbi.

void brushless_set_speed ( void *  motor_num,
int32_t  speed 
)

set speed function, compatible with control_system. first argument not used.

Definition at line 722 of file brushless.c.

References brushless_0_set_parameters(), and brushless_1_set_parameters().

void brushless_set_torque ( void *  motor_num,
int32_t  torque 
)

set torque function, compatible with control_system. first argument not used.

Definition at line 713 of file brushless.c.

References brushless_0_set_parameters(), and brushless_1_set_parameters().

void brushless_speed_update_manage ( void *  dummy  ) 

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

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 215 of file brushless.c.

References brushless_speed_update_manage(), g_brushless_0_pwm_divider, g_brushless_0_torque, g_brushless_1_pwm_divider, g_brushless_1_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, pwm_previous_sensors_1, and sei.


Variable Documentation

Definition at line 126 of file brushless.c.

brushless_position g_brushless_0_position_previous

Definition at line 122 of file brushless.c.

Definition at line 134 of file brushless.c.

brushless_torque g_brushless_0_torque

Definition at line 130 of file brushless.c.

Definition at line 127 of file brushless.c.

brushless_position g_brushless_1_position_previous

Definition at line 123 of file brushless.c.

Referenced by brushless_1_set_position().

Definition at line 135 of file brushless.c.

Referenced by brushless_1_set_parameters(), and SIGNAL().

brushless_torque g_brushless_1_torque

Definition at line 131 of file brushless.c.

Referenced by brushless_1_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.

const int8_t PROGMEM g_brushless_phase1[] = {0, 1, -1, 0, 0, 1, -1, 0}

Definition at line 111 of file brushless.c.

const int8_t PROGMEM g_brushless_phase2[] = {0, 0, 1, 1, -1, -1, 0, 0}

Definition at line 112 of file brushless.c.

const int8_t PROGMEM g_brushless_phase3[] = {0, -1, 0, -1, 1, 0, 1, 0}

Definition at line 113 of file brushless.c.

volatile uint8_t interrupt_pwm

Definition at line 168 of file brushless.c.

volatile uint8_t pwm_previous_sensors_0 = 0

Definition at line 169 of file brushless.c.

volatile uint8_t pwm_previous_sensors_1 = 0

Definition at line 170 of file brushless.c.

Referenced by brushless_1_set_parameters(), and SIGNAL().

brushless_speed speed_mem_0 = BRUSHLESS_MAX_SPEED

Definition at line 521 of file brushless.c.

brushless_speed speed_mem_1 = BRUSHLESS_MAX_SPEED

Definition at line 523 of file brushless.c.

brushless_torque torque_mem_0 = 0

Definition at line 522 of file brushless.c.

brushless_torque torque_mem_1 = 0

Definition at line 524 of file brushless.c.


Generated on Fri Mar 12 06:32:06 2010 for AVR by  doxygen 1.5.6