#pragma once
#include <stdint.h>
//! Dead time (Timer/counter1 clock cycles).
#define DEAD_TIME 10
//! Mask of all pins used for motor control PWM outputs.
#define PWM_PIN_MASK_PORTB 0x3F
//! Pin where hall sensor 1 is connected.
// All other bits must be contiguous!!!
#define H1_PIN PA0
//! Hall sensor pull-up enable.
#define HALL_PULL_UP_ENABLE 1
//! Pin where direction input signal is connected.
#define DIRECTION_PIN PA3
/*! \brief Selects inversion of PWM outputs.
*
* Setting this flag to "1" causes the PWM outputs from Timer/Counter1 to
* be inverted. Inversion happens after dead time insertion.
*/
#define PWM_INVERT_OUTPUT 0
/*! \brief The number of elements in the sine modulation table per phase.
*
* This is the number of elements in the sine modulation table used to
* represent the waveform for one phase. Note that this is not the same
* as the number of elements in the sineTable stored in flash.
*/
#define SINE_TABLE_LENGTH 192U
/*! Sine table size. Select what sine table size should be used.
*/
#define SINE_TABLE_SIZE_SMALL 0 // small (64 elements) sine table.
// Otherwise large (3 * 192 elements) sine table.
/*! The number of commutation 'ticks' that must pass without any hall changes
* before the motor is considered to be stopped.
*
* \todo Adjust the motor stopped limit.
*/
#define COMMUTATION_TICKS_STOPPED 6000
/*! This constant specifies the number of subsequent detections of correct
* direction of rotation needed before the firmware is considered synchronized
* with the motor. (SYNCHRONIZATION_COUNT + 1) hall sensor changes in the
* same direction are needed.
*/
#define SYNCHRONIZATION_COUNT 2
enum {
MOTOR_STOPPED = 1<<0,
MOTOR_SYNCHRONIZED = 1<<1,
DIR_REVERSE = 1<<2, //! Reverse direction flag
DIR_KNOWN = 1<<3, //! Known direction flag
WANTDIR_REVERSE = 1<<4,
WF_SINUSOIDAL = 1<<5, //! Waveform status for sinusoidal driving.
WF_BRAKING = 2<<5, //! Waveform status for braking.
WF_BLOCK_COMMUTATION = 3<<5, //! Waveform status for block commutation.
};
//! The number to multiply speed input with to produce duty cycle compare value (0-255).
#define BLOCK_COMMUTATION_DUTY_MULTIPLIER 3
/*! Turn mode. If not set, TURN with disabled drivers
*
* \todo Select turn mode.
*/
#define TURN_MODE_BRAKE 1
/*! Speed control selection for closed loop control.
\todo Select speed control method.
Otherwise, open loop is used.*/
#define SPEED_CONTROL_CLOSED_LOOP 1
/*! The number of ticks between each iteration of the speed loop.
* \todo Adjust speed control loop time base.
*/
#define SPEED_CONTROLLER_TIME_BASE 150
/*! PID controller proportional gain constant.
* \todo Adjust PID controller proportional gain. (Only for closed loop)
*/
#define PID_K_P 256
/*! PID controller integral gain constant.
* \todo Adjust PID controller integral gain. (Only for closed loop)
*/
#define PID_K_I 10
/*! PID controller derivative gain constant.
* \todo Adjust PID controller derivative gain. (Only for closed loop)
*/
#define PID_K_D 0
/*! The maximum increment (maximum speed) to use as setpoint when the maximum
* speed reference value is input.
*
* \todo Adjust maximum increment. (Maximum speed, used by speed controller)
*/
#define SPEED_CONTROLLER_MAX_INCREMENT 620
/*! Max speed reference input. From ADC.
*
* \todo Adjust Maximum speed reference input value.
*/
#define SPEED_CONTROLLER_MAX_INPUT 1024
Detected encoding: ASCII (7 bit) | 2
|