Setup

Initialization functions and setup

This code works with the Feelix C Library and the FeelixEffect C Library.

/* Change CS to pin 10 for Teensy controlled motors */
#define CS_MAGNETIC_SENSOR_PIN      PA4
#define CS_MAGNETIC_SENSOR_ADDRESS  0x3FFF

/* initialize commander for usage with SimpleFOC library */
/* only required in Feelix C library */
Commander command = Commander(Serial, '&', false);

/* initialize motor */
/* specify the number of pole-pairs between the brackets: BLDCMotor(pole-pairs) */
BLDCMotor _bldc = BLDCMotor(7);

/* for STM32F401 v1.1 boards */
BLDCDriver3PWM _driver = BLDCDriver3PWM(PC8, PC7, PC6, PB15);
/* uncomment for Teensy 3.2 controlled motors */
/* BLDCDriver3PWM _driver = BLDCDriver3PWM(21, 22, 23, 20); */

/* similar for boards with AS5047 and AS5048A */
MagneticSensorSPI _sensor = MagneticSensorSPI(CS_MAGNETIC_SENSOR_PIN, 14, CS_MAGNETIC_SENSOR_ADDRESS);

/* inline current sense: optional, */
/* only available on new board (check values resistor and current sensors) */
/* InlineCurrentSense _current_sense  = InlineCurrentSense(0.05, 50, PC1, PC2); */

/* initialize Feelix */
Feelix feelix = Feelix(&_bldc, &_driver, &_sensor);

/* initialize Feelix with current sense*/
/* Feelix feelix = Feelix(&_bldc, &_driver, &_sensor, &_current_sense); */
  
  void setup() {
  
    Serial.begin(115200);
  
    feelix.init(); 
    
    /* only required in the Feelix C library */
    command.add('F', process_data, "feelix");
    
  }

Last updated