more debug printfs, disabled function usage of gpio0/1, disabled usb interface to save some 25kb in the firmware image
This commit is contained in:
1 parent
23b69d6823
commit
995dca15c8
4 files changed
+43
-14
No files matched your search
+2
-2
@@ -44,8 +44,8 @@ target_link_libraries(
|
||||
)
|
||||
|
||||
# enable usb output, disable uart output
|
||||
pico_enable_stdio_usb(RP2040-Decoder 1)
|
||||
pico_enable_stdio_usb(RP2040-Decoder 0)
|
||||
pico_enable_stdio_uart(RP2040-Decoder 1)
|
||||
|
||||
# create map/bin/hex file etc.
|
||||
pico_add_extra_outputs(RP2040-Decoder)
|
||||
#pico_add_extra_outputs(RP2040-Decoder)
|
||||
@@ -364,7 +364,9 @@ void instruction_evaluation(uint8_t number_of_bytes,const uint8_t * const byte_a
|
||||
if (command_byte_n == 0b00111111){
|
||||
static bool prev_dir;
|
||||
uint32_t speed_step = byte_array[command_byte_start_index - 1];
|
||||
// LOG(1, "new speed %d", speed_step);
|
||||
multicore_fifo_push_blocking(speed_step);
|
||||
// LOG(1, " submitted to list\n");
|
||||
// In case of a direction change, functions need to be updated because functions might depend on direction state
|
||||
if (get_direction(0) != prev_dir) {
|
||||
update_active_functions(0,0,true);
|
||||
@@ -541,6 +543,7 @@ uint16_t measure_base_pwm(bool direction, uint8_t iterations){
|
||||
for (int i = 0; i < iterations; ++i) {
|
||||
uint16_t max_level = _125M/(CV_ARRAY_FLASH[8]*100+10000);
|
||||
uint16_t level = max_level/20;
|
||||
LOG(1, "iteration %d: maxlevel %d level %d\n", i, max_level, level);
|
||||
float measurement;
|
||||
do {
|
||||
pwm_set_gpio_level(gpio, level);
|
||||
@@ -552,11 +555,13 @@ uint16_t measure_base_pwm(bool direction, uint8_t iterations){
|
||||
CV_ARRAY_FLASH[63],
|
||||
direction);
|
||||
// Abort measurement and write default value of 0 to flash
|
||||
LOG(1, "level %d measurement %f loop-cond: %f\n", level, measurement, measurement-(float)CV_ARRAY_FLASH[171]);
|
||||
if (level > max_level) {
|
||||
LOG(1, "measure_base_pwm: abort measurement and return 0\n");
|
||||
return 0;
|
||||
}
|
||||
} while((measurement - (float)CV_ARRAY_FLASH[171]) < 5.0f);
|
||||
LOG(1, "level_arr[%d] = %f\n", i, level);
|
||||
level_arr[i] = (float)level;
|
||||
busy_wait_ms(100);
|
||||
}
|
||||
@@ -572,7 +577,8 @@ uint16_t measure_base_pwm(bool direction, uint8_t iterations){
|
||||
// When ADC Setup is not configured run adc offset adjustment function and write adc offset into flash
|
||||
void cv_setup_check(){
|
||||
// Check for flash factory setting and set CV_FLASH_ARRAY to default values when factory condition ("0xFF") is found.
|
||||
if ( CV_ARRAY_FLASH[64] == 0xFF ){
|
||||
// if ( CV_ARRAY_FLASH[64] == 0xFF ){
|
||||
if(1) {
|
||||
LOG(1, "found cv[64] equals to 0xff, reseting CVs (and CV[8] = 8)\n");
|
||||
uint8_t arr[4] = {125,8,7,124};
|
||||
program_mode(4,arr); //reset to CV_ARRAY_DEFAULT (write CV_8 = 8)
|
||||
@@ -608,8 +614,8 @@ void cv_setup_check(){
|
||||
uint8_t arr1[4] = {125,base_pwm_rev_low_byte,178,124};
|
||||
program_mode(4,arr1);
|
||||
}
|
||||
LOG(1, "int_lim_max %f\n", 10*(float)CV_ARRAY_FLASH[51]);
|
||||
LOG(1, "int_lim_min %f\n", -10*(float)CV_ARRAY_FLASH[52]);
|
||||
LOG(1, "int_lim_max %d\n", CV_ARRAY_FLASH[51]);
|
||||
LOG(1, "int_lim_min %d\n", CV_ARRAY_FLASH[52]);
|
||||
}
|
||||
|
||||
|
||||
@@ -652,7 +658,7 @@ void init_main(){
|
||||
|
||||
int main() {
|
||||
stdio_init_all();
|
||||
LOG(0, "core0 init\n");
|
||||
LOG(0, "\n\n======\ncore0 init\n");
|
||||
init_main();
|
||||
LOG(1, "init motor pwms\n");
|
||||
init_motor_pwm(MOTOR_FWD_PIN);
|
||||
|
||||
@@ -16,14 +16,18 @@ void update_speed_dir(pid_params *pid, uint32_t speed_step_target){
|
||||
// Forward
|
||||
if(speed_step_target > 127) {
|
||||
pid->direction = true^reverse_dir;
|
||||
if (pid->speed_step_target == 128) pid->end_target_index = 0;
|
||||
else pid->end_target_index = (pid->speed_step_target-129);
|
||||
if (pid->speed_step_target == 128)
|
||||
pid->end_target_index = 0;
|
||||
else
|
||||
pid->end_target_index = (pid->speed_step_target-129);
|
||||
}
|
||||
// Reverse
|
||||
else {
|
||||
pid->direction = false^reverse_dir;
|
||||
if (pid->speed_step_target == 0) pid->end_target_index = 0;
|
||||
else pid->end_target_index = (pid->speed_step_target-1);
|
||||
if (pid->speed_step_target == 0)
|
||||
pid->end_target_index = 0;
|
||||
else
|
||||
pid->end_target_index = (pid->speed_step_target-1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -192,6 +196,15 @@ bool pid_control(struct repeating_timer *t){
|
||||
if (output < 0 || !pid->setpoint) output = 0.0f;
|
||||
else if (output > pid->max_output) output = pid->max_output;
|
||||
|
||||
if(LOGLEVEL >= 1) {
|
||||
static int counter = 0;
|
||||
counter++;
|
||||
if(counter > 100) {
|
||||
LOG(1, "pid error(%f) output(%f)\n", e, output);
|
||||
counter = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Set PWM Level and discard results in adc fifo
|
||||
adjust_pwm_level((uint16_t)roundf(output),pid);
|
||||
adc_fifo_drain();
|
||||
@@ -226,6 +239,9 @@ void init_pid(pid_params *pid){
|
||||
double v_min = (double)CV_ARRAY_FLASH[1];
|
||||
double v_mid = (double)CV_ARRAY_FLASH[5]*16;
|
||||
double v_max = (double)CV_ARRAY_FLASH[4]*16;
|
||||
|
||||
LOG(1, "speedtable min(%f) mid(%f) max(%f)\n", v_min, v_mid, v_max);
|
||||
|
||||
double delta_x = 63;
|
||||
double m_1 = (v_mid-v_min)/delta_x;
|
||||
double m_2 = (v_max-v_mid)/delta_x;
|
||||
@@ -305,7 +321,7 @@ void core1_entry() {
|
||||
multicore_fifo_push_blocking((uint32_t) &(pid->direction));
|
||||
uint64_t packet_timeout_threshold_in_us = CV_ARRAY_FLASH[10]*1000000;
|
||||
absolute_time_t time_last_update = get_absolute_time();
|
||||
printf("core1 done\n");
|
||||
// printf("core1 done\n");
|
||||
while (1){
|
||||
// Check for time difference between last packet and current time (Packet Timeout)
|
||||
absolute_time_t current_time = get_absolute_time();
|
||||
|
||||
@@ -16,7 +16,8 @@
|
||||
#include "hardware/irq.h"
|
||||
|
||||
#define LOGLEVEL 3
|
||||
#define LOG(level, x, ...) {if(level <= LOGLEVEL) { printf((x), ##__VA_ARGS__);}}
|
||||
//#define LOG(level, x, ...) {if(level <= LOGLEVEL) { printf((x), ##__VA_ARGS__);}}
|
||||
#define LOG(level, ...) printf(__VA_ARGS__)
|
||||
|
||||
// Constant Value of 125 x 10⁶
|
||||
#define _125M 125000000
|
||||
@@ -28,8 +29,14 @@
|
||||
#define FWD_V_EMF_ADC_PIN 28u
|
||||
#define REV_V_EMF_ADC_PIN 29u
|
||||
|
||||
// GPIO used directly (GPIO 0-5 incl.) as outputs or to switch auxiliary output transistors (GPIO 24-27 incl.)
|
||||
#define GPIO_OUTPUT_PIN_MASK (1u<<24) | (1u<<25) | (1u<<26) | (1u<<27) | (1u<<5) | (1u<<4) | (1u<<3) | (1u<<2) | (1u<<1) | (1u<<0)
|
||||
#if LOGLEVEL != 0
|
||||
// GPIO used directly (GPIO 0-5 incl.) as outputs or to switch auxiliary output transistors (GPIO 24-27 incl.)
|
||||
#define GPIO_OUTPUT_PIN_MASK (1u<<24) | (1u<<25) | (1u<<26) | (1u<<27) | (1u<<5) | (1u<<4) | (1u<<3) | (1u<<2)
|
||||
#else
|
||||
// GPIO used directly (GPIO 0-5 incl.) as outputs or to switch auxiliary output transistors (GPIO 24-27 incl.)
|
||||
#define GPIO_OUTPUT_PIN_MASK (1u<<24) | (1u<<25) | (1u<<26) | (1u<<27) | (1u<<5) | (1u<<4) | (1u<<3) | (1u<<2) | (1u<<1) | (1u<<0)
|
||||
#endif
|
||||
|
||||
// GPIO pin mask to prevent setting illegal GPIOs (ADC, Motor, DCC Input Pin)
|
||||
#define GPIO_ILLEGAL_MASK (1u<<DCC_INPUT_PIN) | (1u<<MOTOR_FWD_PIN) | (1u<<MOTOR_REV_PIN) | (1u<<FWD_V_EMF_ADC_PIN) | (1u<<REV_V_EMF_ADC_PIN)
|
||||
|
||||
|
||||
Reference in new issue
Block a user