Update Docs; Add 3D-Models for flash and Motor driver; Update Readme; Check program code for exceeding size in CMakeLists.txt; Moved measure() function to core1.c/core1.h; Added direction enum typedef; Update Control Loop Block Diagram;
This commit is contained in:
1 parent
7d2c80574a
commit
acdbf3cffe
25 files changed
+1195
-632
No files matched your search
+2
-40
@@ -8,47 +8,9 @@
|
||||
|
||||
uint8_t speed_step_target = 0;
|
||||
uint8_t speed_step_target_prev = 0;
|
||||
|
||||
uint32_t error_state = 0;
|
||||
|
||||
|
||||
// Functions in shared.c can be accessed by both cores
|
||||
// Measures Back-EMF voltage (proportional to the rotational speed of the motor) on GPIO 28 and GPIO 29 respectively (depending on direction)
|
||||
float measure(uint8_t total_iterations,
|
||||
uint8_t measurement_delay_us,
|
||||
uint8_t l_side_arr_cutoff,
|
||||
uint8_t r_side_arr_cutoff,
|
||||
bool direction){
|
||||
uint32_t sum = 0;
|
||||
uint16_t adc_val[total_iterations];
|
||||
int32_t j = 0;
|
||||
uint16_t key;
|
||||
pwm_set_gpio_level(MOTOR_FWD_PIN, 0);
|
||||
pwm_set_gpio_level(MOTOR_REV_PIN, 0);
|
||||
adc_select_input((!direction)+2);
|
||||
busy_wait_us(measurement_delay_us);
|
||||
adc_run(true);
|
||||
for (int32_t i = 0; i < total_iterations; ++i) {
|
||||
//Take adc value out of fifo when available, then do one step of insertion sort.
|
||||
adc_val[i] = adc_fifo_get_blocking();
|
||||
key = adc_val[i];
|
||||
j = i - 1;
|
||||
while (j >= 0 && adc_val[j] > key) {
|
||||
adc_val[j + 1] = adc_val[j];
|
||||
j--;
|
||||
}
|
||||
adc_val[j + 1] = key;
|
||||
}
|
||||
adc_run(false);
|
||||
//discard x entries beginning from the lowest entry of the array (counting up); x = msr.l_side_arr_cutoff
|
||||
//discard y entries beginning from the highest index of the array (counting down); y = msr.r_side_arr_cutoff
|
||||
for (int32_t i = l_side_arr_cutoff; i < total_iterations - r_side_arr_cutoff ; ++i) {
|
||||
sum += adc_val[i];
|
||||
}
|
||||
float res = (float)sum / (float)( total_iterations - (l_side_arr_cutoff + r_side_arr_cutoff) );
|
||||
// return true to keep the repeating timer active
|
||||
return res;
|
||||
}
|
||||
// Functions in shared.c are accessed by both cores
|
||||
|
||||
// retrieve 4Bytes from CV_ARRAY_FLASH at once and return 32-Bit value
|
||||
uint32_t get_32bit_CV (uint16_t CV_start_index){
|
||||
@@ -67,7 +29,7 @@ uint16_t get_16bit_CV (uint16_t CV_start_index){
|
||||
return (byte_0) + (byte_1<<8);
|
||||
}
|
||||
|
||||
bool get_direction_of_speed_step(uint8_t speed_step){
|
||||
direction_t get_direction_of_speed_step(uint8_t speed_step){
|
||||
// Shift by 7 Bytes to move bit7 into bit0 position and return
|
||||
return speed_step >> 7;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user