remove OPA2 for rev 3
This commit is contained in:
@@ -85,17 +85,12 @@ void MX_ADC2_Init(void)
|
||||
if (HAL_ADC_Init(&hadc2) != HAL_OK)
|
||||
SIMPLEFOC_DEBUG("HAL ADC2 init failed!");
|
||||
|
||||
sConfig.Channel = ADC_CHANNEL_VOPAMP2;
|
||||
sConfig.Channel = ADC_CHANNEL_VOPAMP3_ADC2;
|
||||
sConfig.Rank = ADC_REGULAR_RANK_1;
|
||||
sConfig.SamplingTime = ADC_SAMPLETIME_2CYCLES_5;
|
||||
sConfig.SingleDiff = ADC_SINGLE_ENDED;
|
||||
sConfig.OffsetNumber = ADC_OFFSET_NONE;
|
||||
sConfig.Offset = 0;
|
||||
if (HAL_ADC_ConfigChannel(&hadc2, &sConfig) != HAL_OK)
|
||||
SIMPLEFOC_DEBUG("HAL ADC OPAMP2 init failed!");
|
||||
|
||||
sConfig.Channel = ADC_CHANNEL_VOPAMP3_ADC2;
|
||||
sConfig.Rank = ADC_REGULAR_RANK_2;
|
||||
if (HAL_ADC_ConfigChannel(&hadc2, &sConfig) != HAL_OK)
|
||||
SIMPLEFOC_DEBUG("HAL ADC OPAMP3 init failed!");
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#include "opamp.h"
|
||||
|
||||
OPAMP_HandleTypeDef hopamp1;
|
||||
OPAMP_HandleTypeDef hopamp2;
|
||||
OPAMP_HandleTypeDef hopamp3;
|
||||
|
||||
void configureOPAMPs(void)
|
||||
@@ -13,19 +12,9 @@ void configureOPAMPs(void)
|
||||
hopamp1.Init.InternalOutput = ENABLE;
|
||||
hopamp1.Init.TimerControlledMuxmode = OPAMP_TIMERCONTROLLEDMUXMODE_DISABLE;
|
||||
hopamp1.Init.UserTrimming = OPAMP_TRIMMING_FACTORY;
|
||||
if(HAL_OPAMP_Init(&hopamp1) != HAL_OK)
|
||||
if (HAL_OPAMP_Init(&hopamp1) != HAL_OK)
|
||||
SIMPLEFOC_DEBUG("OPAMP1 init failed.");
|
||||
|
||||
hopamp2.Instance = OPAMP2;
|
||||
hopamp2.Init.PowerMode = OPAMP_POWERMODE_NORMALSPEED;
|
||||
hopamp2.Init.Mode = OPAMP_FOLLOWER_MODE;
|
||||
hopamp2.Init.NonInvertingInput = OPAMP_NONINVERTINGINPUT_IO2;
|
||||
hopamp2.Init.InternalOutput = ENABLE;
|
||||
hopamp2.Init.TimerControlledMuxmode = OPAMP_TIMERCONTROLLEDMUXMODE_DISABLE;
|
||||
hopamp2.Init.UserTrimming = OPAMP_TRIMMING_FACTORY;
|
||||
if(HAL_OPAMP_Init(&hopamp2) != HAL_OK)
|
||||
SIMPLEFOC_DEBUG("OPAMP2 init failed.");
|
||||
|
||||
hopamp3.Instance = OPAMP3;
|
||||
hopamp3.Init.PowerMode = OPAMP_POWERMODE_NORMALSPEED;
|
||||
hopamp3.Init.Mode = OPAMP_FOLLOWER_MODE;
|
||||
@@ -33,7 +22,7 @@ void configureOPAMPs(void)
|
||||
hopamp3.Init.InternalOutput = ENABLE;
|
||||
hopamp3.Init.TimerControlledMuxmode = OPAMP_TIMERCONTROLLEDMUXMODE_DISABLE;
|
||||
hopamp3.Init.UserTrimming = OPAMP_TRIMMING_FACTORY;
|
||||
if(HAL_OPAMP_Init(&hopamp3) != HAL_OK)
|
||||
if (HAL_OPAMP_Init(&hopamp3) != HAL_OK)
|
||||
SIMPLEFOC_DEBUG("OPAMP3 init failed.");
|
||||
}
|
||||
|
||||
@@ -42,19 +31,16 @@ void OPAMP_GPIO_Init(void)
|
||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_2;
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_2; //PA2 -> ADC1_IN3
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_3;
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_3; //PA3 -> OPAMP1_VINP1
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_0;
|
||||
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_13;
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_13; //PB13 -> OPAMP3_VINP1
|
||||
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||
}
|
||||
|
||||
@@ -65,10 +51,6 @@ void HAL_OPAMP_MspDeInit(OPAMP_HandleTypeDef *opampHandle)
|
||||
{
|
||||
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_3);
|
||||
}
|
||||
else if (opampHandle->Instance == OPAMP2)
|
||||
{
|
||||
HAL_GPIO_DeInit(GPIOB, GPIO_PIN_0);
|
||||
}
|
||||
else if (opampHandle->Instance == OPAMP3)
|
||||
{
|
||||
HAL_GPIO_DeInit(GPIOB, GPIO_PIN_13);
|
||||
|
||||
@@ -65,11 +65,11 @@ STM32HWEncoder enc = STM32HWEncoder(ENC_PPR, ENC_A, ENC_B, ENC_Z);
|
||||
StepperDriver4PWM driver = StepperDriver4PWM(MOT_A1, MOT_A2, MOT_B1, MOT_B2);
|
||||
// StepperMotor motor = StepperMotor(POLEPAIRS, RPHASE, MOTORKV, 0.0045);
|
||||
StepperMotor motor = StepperMotor(POLEPAIRS);
|
||||
StepDirListener step_dir = StepDirListener(STEP_PIN, DIR_PIN, _2PI/200.0);
|
||||
Commander commander = Commander(SERIALPORT);
|
||||
|
||||
uint16_t counter = 0;
|
||||
extern volatile uint16_t adc1Result[3];
|
||||
extern volatile uint16_t adc2Result[2];
|
||||
float stepCounter;
|
||||
|
||||
DQCurrent_s foc_currents;
|
||||
float electrical_angle;
|
||||
@@ -81,6 +81,7 @@ uint8_t configureCAN(void);
|
||||
uint8_t calibrateEncoder(void);
|
||||
|
||||
void userButton(void);
|
||||
void onStep(void) {step_dir.handle();}
|
||||
|
||||
void setup()
|
||||
{
|
||||
@@ -105,6 +106,7 @@ void setup()
|
||||
// SIMPLEFOC_DEBUG("CAN init failed.");
|
||||
// digitalWrite(LED_FAULT, HIGH);
|
||||
// }
|
||||
|
||||
ret = configureFOC();
|
||||
if (!ret){
|
||||
SIMPLEFOC_DEBUG("FOC init failed.");
|
||||
@@ -160,16 +162,13 @@ void loop()
|
||||
motor.move();
|
||||
commander.run();
|
||||
|
||||
electrical_angle = motor.electricalAngle();
|
||||
// phase_currents = currentsense.getPhaseCurrents();
|
||||
// foc_currents = currentsense.getFOCCurrents(electrical_angle);
|
||||
|
||||
if(counter == 0xFFF){
|
||||
digitalToggle(LED_GOOD);
|
||||
// Serial.println(adc1Result[0]);
|
||||
counter = 0;
|
||||
}
|
||||
counter++;
|
||||
|
||||
counter++;
|
||||
|
||||
#ifdef HAS_MONITOR
|
||||
motor.monitor();
|
||||
#endif
|
||||
@@ -191,6 +190,11 @@ uint8_t configureFOC(void)
|
||||
|
||||
// Encoder initialization.
|
||||
// Ideally configuring the sensor over SPI then use STM32HWEncoder
|
||||
|
||||
step_dir.init();
|
||||
step_dir.enableInterrupt(onStep);
|
||||
step_dir.attach(&stepCounter);
|
||||
|
||||
enc.init();
|
||||
if (!enc.initialized)
|
||||
digitalWrite(LED_FAULT, HIGH);
|
||||
@@ -327,4 +331,6 @@ void userButton(void)
|
||||
{
|
||||
if(USB->DADDR != 0)
|
||||
jump_to_bootloader();
|
||||
else
|
||||
digitalToggle(LED_FAULT);
|
||||
}
|
||||
Reference in New Issue
Block a user