ADD: comments from TomTinkering

This commit is contained in:
Niklas Fauth 2018-05-08 12:51:01 +02:00
parent 47f243b2fe
commit aff32b2bb4
2 changed files with 30 additions and 53 deletions

View File

@ -143,6 +143,9 @@ int timer = 0;
const int max_time = PWM_FREQ / 10;
volatile int vel = 0;
//scan 8 channels with 2ADCs @ 20 clk cycles per sample
//meaning ~80 ADC clock cycles @ 8MHz until new DMA interrupt =~ 100KHz
//=640 cpu cycles
void DMA1_Channel1_IRQHandler() {
DMA1->IFCR = DMA_IFCR_CTCIF1;
// HAL_GPIO_WritePin(LED_PORT, LED_PIN, 1);
@ -174,7 +177,7 @@ void DMA1_Channel1_IRQHandler() {
#endif
//disable PWM when current limit is reached (current chopping)
if(ABS((adc_buffer.dcl - offsetdcl) * MOTOR_AMP_CONV_DC_AMP) > DC_CUR_LIMIT || timeout > TIMEOUT || enable == 0) {
LEFT_TIM->BDTR &= ~TIM_BDTR_MOE;
//HAL_GPIO_WritePin(LED_PORT, LED_PIN, 1);
@ -192,6 +195,7 @@ void DMA1_Channel1_IRQHandler() {
int ul, vl, wl;
int ur, vr, wr;
//determine next position based on hall sensors
uint8_t hall_ul = !(LEFT_HALL_U_PORT->IDR & LEFT_HALL_U_PIN);
uint8_t hall_vl = !(LEFT_HALL_V_PORT->IDR & LEFT_HALL_V_PIN);
uint8_t hall_wl = !(LEFT_HALL_W_PORT->IDR & LEFT_HALL_W_PIN);
@ -215,8 +219,8 @@ void DMA1_Channel1_IRQHandler() {
//setScopeChannel(2, (adc_buffer.rl1 - offsetrl1) / 8);
//setScopeChannel(3, (adc_buffer.rl2 - offsetrl2) / 8);
//create square wave for buzzer
buzzerTimer++;
if (buzzerFreq != 0 && (buzzerTimer / 5000) % (buzzerPattern + 1) == 0) {
if (buzzerTimer % buzzerFreq == 0) {
HAL_GPIO_TogglePin(BUZZER_PORT, BUZZER_PIN);
@ -225,33 +229,10 @@ void DMA1_Channel1_IRQHandler() {
HAL_GPIO_WritePin(BUZZER_PORT, BUZZER_PIN, 0);
}
// //measure vel
// timer++;
// if(timer > max_time){
// timer = max_time;
// vel = 0;
// }
// if(posl != last_pos){
// vel = 1000 * PWM_FREQ / timer / P / 6 * 2;
// if((posl - last_pos + 6) % 6 > 2){
// vel = -vel;
// }
// timer = 0;
// }
// last_pos = posl;
//YOLOTEST
// errorl = cmdl - curl;
// pwml = kp * errorl;
//update PWM channels based on position
blockPWM(pwml, posl, &ul, &vl, &wl);
blockPWM(pwmr, posr, &ur, &vr, &wr);
int weakul, weakvl, weakwl;
if (pwml > 0) {
blockPWM(weakl, (posl+5) % 6, &weakul, &weakvl, &weakwl);
@ -271,7 +252,6 @@ void DMA1_Channel1_IRQHandler() {
ur += weakur;
vr += weakvr;
wr += weakwr;
// blockPWM(pwmr, posr, &ur, &vr, &wr);
LEFT_TIM->LEFT_TIM_U = CLAMP(ul + pwm_res / 2, 10, pwm_res-10);
LEFT_TIM->LEFT_TIM_V = CLAMP(vl + pwm_res / 2, 10, pwm_res-10);
@ -280,5 +260,4 @@ void DMA1_Channel1_IRQHandler() {
RIGHT_TIM->RIGHT_TIM_U = CLAMP(ur + pwm_res / 2, 10, pwm_res-10);
RIGHT_TIM->RIGHT_TIM_V = CLAMP(vr + pwm_res / 2, 10, pwm_res-10);
RIGHT_TIM->RIGHT_TIM_W = CLAMP(wr + pwm_res / 2, 10, pwm_res-10);
// HAL_GPIO_WritePin(LED_PORT, LED_PIN, 0);blockPhaseCurrent
}

View File

@ -25,40 +25,38 @@
void SystemClock_Config(void);
int cmd1;
int cmd2;
int cmd3;
int steer;
int speed;
extern TIM_HandleTypeDef htim_left;
extern TIM_HandleTypeDef htim_right;
extern ADC_HandleTypeDef hadc1;
extern ADC_HandleTypeDef hadc2;
extern volatile adc_buf_t adc_buffer;
extern volatile adc_buf_t adc_buffer;
int cmd1;
int cmd2;
int cmd3;
int steer; // global variable for steering. -1000 to 1000
int speed; // global variable for speed. -1000 to 1000
extern volatile int pwml; // global variable for pwm left. -1000 to 1000
extern volatile int pwmr; // global variable for pwm right. -1000 to 1000
extern volatile int weakl; // global variable for field weakening left. -1000 to 1000
extern volatile int weakr; // global variable for field weakening right. -1000 to 1000
extern uint8_t buzzerFreq; // global variable for the buzzer pitch. can be 1, 2, 3, 4, 5, 6, 7...
extern uint8_t buzzerPattern; // global variable for the buzzer pattern. can be 1, 2, 3, 4, 5, 6, 7...
extern uint8_t enable; // global variable for motor enable
extern volatile uint32_t timeout; // global variable for timeout
extern float batteryVoltage; // global variable for battery voltage
extern uint8_t nunchuck_data[6];
#ifdef CONTROL_PPM
extern volatile uint16_t ppm_captured_value[PPM_NUM_CHANNELS+1];
#endif
extern volatile int pwml;
extern volatile int pwmr;
extern volatile int weakl;
extern volatile int weakr;
volatile int pwmrl = 0;
extern uint8_t buzzerFreq;
extern uint8_t buzzerPattern;
extern uint8_t enable;
extern volatile uint32_t timeout;
extern float batteryVoltage;
extern uint8_t nunchuck_data[6];
int milli_vel_error_sum = 0;
int main(void) {