Change C18 to be 0603 - 25V and rotate on PCB for easier soldering; Small logging changes; Speed step enums are actually used now for better clarity; Introduced cv_setup_check_done and flash_safe_execute_core_init_done flags for coordinating the two cores better; Incremented version no. CV_7 to 2;
This commit is contained in:
1 parent
0462d3f6b7
commit
f1961fa5bd
7 files changed
+868
-896
No files matched your search
File diff suppressed because it is too large.
Load diff
@@ -14280,6 +14280,111 @@
|
||||
)
|
||||
)
|
||||
)
|
||||
(symbol
|
||||
(lib_id "Device:C")
|
||||
(at 269.24 111.76 0)
|
||||
(mirror y)
|
||||
(unit 1)
|
||||
(exclude_from_sim no)
|
||||
(in_bom yes)
|
||||
(on_board yes)
|
||||
(dnp no)
|
||||
(uuid "926fab55-949a-4f0a-8fca-4df66294d600")
|
||||
(property "Reference" "C18"
|
||||
(at 266.7 109.855 0)
|
||||
(effects
|
||||
(font
|
||||
(size 1.27 1.27)
|
||||
)
|
||||
(justify left)
|
||||
)
|
||||
)
|
||||
(property "Value" "10u"
|
||||
(at 266.7 111.76 0)
|
||||
(effects
|
||||
(font
|
||||
(size 1.27 1.27)
|
||||
)
|
||||
(justify left)
|
||||
)
|
||||
)
|
||||
(property "Footprint" "Capacitor_SMD:C_0603_1608Metric"
|
||||
(at 268.2748 115.57 0)
|
||||
(effects
|
||||
(font
|
||||
(size 1.27 1.27)
|
||||
)
|
||||
(hide yes)
|
||||
)
|
||||
)
|
||||
(property "Datasheet" "~"
|
||||
(at 269.24 111.76 0)
|
||||
(effects
|
||||
(font
|
||||
(size 1.27 1.27)
|
||||
)
|
||||
(hide yes)
|
||||
)
|
||||
)
|
||||
(property "Description" ""
|
||||
(at 269.24 111.76 0)
|
||||
(effects
|
||||
(font
|
||||
(size 1.27 1.27)
|
||||
)
|
||||
(hide yes)
|
||||
)
|
||||
)
|
||||
(property "Voltage" "25V"
|
||||
(at 264.795 113.665 0)
|
||||
(effects
|
||||
(font
|
||||
(size 1.27 1.27)
|
||||
)
|
||||
)
|
||||
)
|
||||
(property "Alternative Part" ""
|
||||
(at 269.24 111.76 0)
|
||||
(effects
|
||||
(font
|
||||
(size 1.27 1.27)
|
||||
)
|
||||
(hide yes)
|
||||
)
|
||||
)
|
||||
(property "LCSC Part #" "C96446"
|
||||
(at 269.24 111.76 0)
|
||||
(effects
|
||||
(font
|
||||
(size 1.27 1.27)
|
||||
)
|
||||
(hide yes)
|
||||
)
|
||||
)
|
||||
(property "JLCPCB Rotation Offset" ""
|
||||
(at 269.24 111.76 0)
|
||||
(effects
|
||||
(font
|
||||
(size 1.27 1.27)
|
||||
)
|
||||
(hide yes)
|
||||
)
|
||||
)
|
||||
(pin "1"
|
||||
(uuid "f492e1f2-b394-44de-94ec-6ffdb5b23f04")
|
||||
)
|
||||
(pin "2"
|
||||
(uuid "d60e3d4f-f820-48b0-9c2c-279fefed7d0c")
|
||||
)
|
||||
(instances
|
||||
(project "RP2040-Decoder"
|
||||
(path "/11d18738-0f49-4d63-b61c-22a93efd5959"
|
||||
(reference "C18")
|
||||
(unit 1)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
(symbol
|
||||
(lib_name "Conn_01x01_4")
|
||||
(lib_id "Connector_Generic:Conn_01x01")
|
||||
@@ -17080,110 +17185,6 @@
|
||||
)
|
||||
)
|
||||
)
|
||||
(symbol
|
||||
(lib_id "Device:C")
|
||||
(at 269.24 111.76 0)
|
||||
(unit 1)
|
||||
(exclude_from_sim no)
|
||||
(in_bom yes)
|
||||
(on_board yes)
|
||||
(dnp no)
|
||||
(uuid "e20126a2-4f49-4660-92ef-240372de172a")
|
||||
(property "Reference" "C18"
|
||||
(at 271.78 109.855 0)
|
||||
(effects
|
||||
(font
|
||||
(size 1.27 1.27)
|
||||
)
|
||||
(justify left)
|
||||
)
|
||||
)
|
||||
(property "Value" "10u"
|
||||
(at 271.78 111.76 0)
|
||||
(effects
|
||||
(font
|
||||
(size 1.27 1.27)
|
||||
)
|
||||
(justify left)
|
||||
)
|
||||
)
|
||||
(property "Footprint" "Capacitor_SMD:C_0402_1005Metric"
|
||||
(at 270.2052 115.57 0)
|
||||
(effects
|
||||
(font
|
||||
(size 1.27 1.27)
|
||||
)
|
||||
(hide yes)
|
||||
)
|
||||
)
|
||||
(property "Datasheet" "~"
|
||||
(at 269.24 111.76 0)
|
||||
(effects
|
||||
(font
|
||||
(size 1.27 1.27)
|
||||
)
|
||||
(hide yes)
|
||||
)
|
||||
)
|
||||
(property "Description" ""
|
||||
(at 269.24 111.76 0)
|
||||
(effects
|
||||
(font
|
||||
(size 1.27 1.27)
|
||||
)
|
||||
(hide yes)
|
||||
)
|
||||
)
|
||||
(property "Voltage" "6V3"
|
||||
(at 273.685 113.665 0)
|
||||
(effects
|
||||
(font
|
||||
(size 1.27 1.27)
|
||||
)
|
||||
)
|
||||
)
|
||||
(property "Alternative Part" ""
|
||||
(at 269.24 111.76 0)
|
||||
(effects
|
||||
(font
|
||||
(size 1.27 1.27)
|
||||
)
|
||||
(hide yes)
|
||||
)
|
||||
)
|
||||
(property "LCSC Part #" "C15525"
|
||||
(at 269.24 111.76 0)
|
||||
(effects
|
||||
(font
|
||||
(size 1.27 1.27)
|
||||
)
|
||||
(hide yes)
|
||||
)
|
||||
)
|
||||
(property "JLCPCB Rotation Offset" ""
|
||||
(at 269.24 111.76 0)
|
||||
(effects
|
||||
(font
|
||||
(size 1.27 1.27)
|
||||
)
|
||||
(hide yes)
|
||||
)
|
||||
)
|
||||
(pin "1"
|
||||
(uuid "27ece8d2-a3e3-4c30-9c00-f23b6d1cfce4")
|
||||
)
|
||||
(pin "2"
|
||||
(uuid "a11478be-7cda-4871-9d21-cadbb32abcc8")
|
||||
)
|
||||
(instances
|
||||
(project "RP2040-Decoder"
|
||||
(path "/11d18738-0f49-4d63-b61c-22a93efd5959"
|
||||
(reference "C18")
|
||||
(unit 1)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
(symbol
|
||||
(lib_name "+1V1_1")
|
||||
(lib_id "power:+1V1")
|
||||
|
||||
+3
-2
@@ -16,7 +16,7 @@ uint8_t CV_ARRAY_DEFAULT [CV_ARRAY_SIZE] = {
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
0b01100100, //CV_5 - V_max - Default = 100*16
|
||||
0b00111111, //CV_6 - V_mid - Default = 63*16
|
||||
0b00000001, //CV_7 - Version no. (read-only)
|
||||
0b00000010, //CV_7 - Version no. (read-only)
|
||||
// Writing a value of 8 to CV_8 resets all CV values to the default values in CV.h
|
||||
0b00001101, //CV_8 - Manufacturer (13 = Public Domain & Do-It-Yourself Decoders) (read-only)
|
||||
0b10010110, //CV_9 - PWM frequency in Hz = CV_9*100+10000 - Default = (150*100+10000)Hz = 25kHz
|
||||
@@ -62,7 +62,8 @@ uint8_t CV_ARRAY_DEFAULT [CV_ARRAY_SIZE] = {
|
||||
0b00000000, //CV_44 -
|
||||
0b00000000, //CV_45 -
|
||||
0b00000000, //CV_46 -
|
||||
// Speed controller - Configuration ////////////////////////////////////////////////////////////////////////////////
|
||||
// TODO: Update controller CVs
|
||||
// Speed controller - Configuration /////////////////////////////////////////////////////////////////////////////////
|
||||
0b00110010, //CV_47 - Feed-forward gain k_ff = CV_47/10000 Default = 50 -> 0.005 //
|
||||
0b00001010, //CV_48 - PID Control low pass filter time constant (tau) in ms //
|
||||
0b00000101, //CV_49 - PID Control sampling time t in ms //
|
||||
|
||||
+18
-9
@@ -149,7 +149,7 @@ static uint16_t two_std_dev(const uint16_t arr[], const uint32_t length) {
|
||||
|
||||
static void adc_offset_adjustment(uint32_t const n) {
|
||||
// Measures constant adc offset and programs the offset into flash
|
||||
LOG(1, "ADC offset adjustment...\n");
|
||||
LOG(1, "ADC offset adjustment with %u iterations...\n", n);
|
||||
|
||||
uint16_t offsets_fwd[n];
|
||||
uint16_t offsets_rev[n];
|
||||
@@ -537,7 +537,8 @@ static bool reset_message_check(size_t const number_of_bytes, const uint8_t *con
|
||||
speed_step_target_prev = speed_step_target;
|
||||
// Set speed step target to emergency stop speed step ( 1 for Reverse direction / 129 for forward direction)
|
||||
// for details see get_direction_of_speed_step() comment in "shared.h"
|
||||
speed_step_target = 1 + 128*dir;
|
||||
if(dir == DIRECTION_FORWARD) speed_step_target = SPEED_STEP_FORWARD_EMERGENCY_STOP;
|
||||
else if(dir == DIRECTION_REVERSE) speed_step_target = SPEED_STEP_REVERSE_EMERGENCY_STOP;
|
||||
update_active_functions(0,0,0); // Disables all functions
|
||||
return true;
|
||||
}
|
||||
@@ -665,11 +666,12 @@ static void cv_setup_check() {
|
||||
}
|
||||
|
||||
// Check for existing ADC offset setup
|
||||
if (CV_ARRAY_FLASH[171] == 0xFF) {
|
||||
if (true || CV_ARRAY_FLASH[171] == 0xFF) {
|
||||
LOG(1, "Detected ADC offset factory condidition (CV_172 == %u), running offset adjustment measurement function...\n", CV_ARRAY_FLASH[171]);
|
||||
adc_offset_adjustment(ADC_CALIBRATION_ITERATIONS);
|
||||
}
|
||||
LOG(1, "CV check done!\n");
|
||||
LOG(1, "CV check done! Setting wait_for_cv_setup_check flag to false!\n");
|
||||
cv_setup_check_done = true;
|
||||
}
|
||||
|
||||
static void init_motor_pwm(uint8_t const gpio) {
|
||||
@@ -753,10 +755,6 @@ int main() {
|
||||
|
||||
LOG(1, "core0 Initialization...\n");
|
||||
|
||||
// Enable the watchdog, requiring the watchdog to be updated every WATCHDOG_TIMER_IN_MS milliseconds or the chip will reboot
|
||||
// second arg is pause on debug which means the watchdog will pause when stepping through code
|
||||
watchdog_enable(WATCHDOG_TIMER_IN_MS, 1);
|
||||
|
||||
// Check for reboot by watchdog and set error when true
|
||||
if (watchdog_caused_reboot()) {
|
||||
LOG(1, "Reboot by watchdog detected!\n");
|
||||
@@ -780,7 +778,13 @@ int main() {
|
||||
|
||||
// Launch core1
|
||||
multicore_launch_core1(core1_entry);
|
||||
// Wait 100ms to give core1 some time to call flash_safe_execute_core_init()
|
||||
|
||||
// Wait for core1 to call flash_safe_execute_core_init() and set the flash_safe_execute_core_init_done flag
|
||||
LOG(1, "Waiting for flash_safe_execute_core_init_done flag...\n");
|
||||
while (!flash_safe_execute_core_init_done) {
|
||||
watchdog_update();
|
||||
}
|
||||
|
||||
busy_wait_ms(100);
|
||||
|
||||
|
||||
@@ -798,6 +802,11 @@ int main() {
|
||||
gpio_set_irq_enabled(DCC_INPUT_PIN, GPIO_IRQ_EDGE_RISE | GPIO_IRQ_EDGE_FALL, true);
|
||||
irq_set_enabled(IO_IRQ_BANK0, true);
|
||||
|
||||
// Enable the watchdog, requiring the watchdog to be updated every WATCHDOG_TIMER_IN_MS milliseconds or the chip will reboot
|
||||
// second arg is pause on debug which means the watchdog will pause when stepping through code
|
||||
// Watchdog is updated by core0 and core1 whenever there is time and hopefully soon enough to prevent a reboot.
|
||||
watchdog_enable(WATCHDOG_TIMER_IN_MS, 1);
|
||||
|
||||
// Endless loop
|
||||
while (true) {
|
||||
// Check for new messages in ring buffer
|
||||
|
||||
+8
-20
@@ -82,7 +82,7 @@ void speed_helper(controller_parameter_t * ctrl_par) {
|
||||
const bool direction_changed = get_direction_of_speed_step(speed_step_target) !=
|
||||
get_direction_of_speed_step(speed_step_target_prev);
|
||||
|
||||
if (speed_step_target == 129 || speed_step_target == 1) {
|
||||
if (speed_step_target == SPEED_STEP_FORWARD_EMERGENCY_STOP || speed_step_target == SPEED_STEP_REVERSE_EMERGENCY_STOP) {
|
||||
// Emergency Stop
|
||||
speed_table_index = 0;
|
||||
speed_helper_counter = 0;
|
||||
@@ -353,34 +353,22 @@ bool speed_helper_timer_callback(__unused struct repeating_timer *t) {
|
||||
void core1_entry() {
|
||||
LOG(1, "core1 Initialization...\n");
|
||||
|
||||
if (flash_safe_execute_core_init() != true){
|
||||
flash_safe_execute_core_init_done = flash_safe_execute_core_init();
|
||||
if (flash_safe_execute_core_init_done != true){
|
||||
set_error(FLASH_SAFE_EXECUTE_CORE_INIT_FAILURE);
|
||||
return;
|
||||
}
|
||||
|
||||
// Wait for core0 to finish CV check (see cv_setup_check)
|
||||
LOG(1, "Waiting for CV check flag...\n");
|
||||
while(!cv_setup_check_done){
|
||||
watchdog_update(); // Update watchdog while waiting on core0
|
||||
}
|
||||
|
||||
controller_parameter_t control_parameter;
|
||||
controller_parameter_t *ctrl_par = &control_parameter;
|
||||
init_controller(ctrl_par);
|
||||
|
||||
|
||||
/*
|
||||
alarm_pool_add_repeating_timer_ms(alarm_pool_create(0, 1),
|
||||
CV_ARRAY_FLASH[48],
|
||||
controller_general,
|
||||
ctrl_par,
|
||||
&pid_control_timer);
|
||||
// Set TIMER_IRQ_0 to highest priority of 0x00
|
||||
irq_set_priority(TIMER_IRQ_0, 0x00);
|
||||
alarm_pool_add_repeating_timer_ms(alarm_pool_create(1, 1),
|
||||
CV_ARRAY_FLASH[174],
|
||||
speed_helper,
|
||||
ctrl_par,
|
||||
&speed_helper_timer);
|
||||
|
||||
*/
|
||||
|
||||
|
||||
struct repeating_timer timer_controller, timer_speed_helper;
|
||||
add_repeating_timer_ms(-CV_ARRAY_FLASH[48], controller_timer_callback, NULL, &timer_controller);
|
||||
add_repeating_timer_ms(-CV_ARRAY_FLASH[174], speed_helper_timer_callback, NULL, &timer_speed_helper);
|
||||
|
||||
+7
-4
@@ -7,8 +7,10 @@
|
||||
#include "shared.h"
|
||||
|
||||
// TODO: Implement enum typedef for speed steps, also getter and setter functions checking validity of speed step values.
|
||||
uint8_t speed_step_target = 0;
|
||||
uint8_t speed_step_target_prev = 0;
|
||||
speed_step_t speed_step_target = SPEED_STEP_REVERSE_STOP;
|
||||
speed_step_t speed_step_target_prev = SPEED_STEP_REVERSE_STOP;
|
||||
bool cv_setup_check_done = false;
|
||||
bool flash_safe_execute_core_init_done = false;
|
||||
static error_t error_state = 0;
|
||||
|
||||
// Functions in shared.c are accessed by both cores
|
||||
@@ -30,8 +32,9 @@ uint16_t get_16bit_CV (uint16_t CV_start_index){
|
||||
return (byte_0) + (byte_1<<8);
|
||||
}
|
||||
|
||||
direction_t get_direction_of_speed_step(uint8_t speed_step){
|
||||
// Shift by 7 Bytes to move bit7 into bit0 position and return
|
||||
direction_t get_direction_of_speed_step(speed_step_t speed_step){
|
||||
// Bit 7 is the direction bit.
|
||||
// Shift by 7 bits to move bit7 into bit0 position and return direction.
|
||||
return speed_step >> 7;
|
||||
}
|
||||
|
||||
|
||||
+5
-3
@@ -309,8 +309,10 @@ typedef enum {
|
||||
extern repeating_timer_t pid_control_timer;
|
||||
extern repeating_timer_t speed_helper_timer;
|
||||
extern const uint8_t *CV_ARRAY_FLASH;
|
||||
extern uint8_t speed_step_target;
|
||||
extern uint8_t speed_step_target_prev;
|
||||
extern speed_step_t speed_step_target;
|
||||
extern speed_step_t speed_step_target_prev;
|
||||
extern bool cv_setup_check_done;
|
||||
extern bool flash_safe_execute_core_init_done;
|
||||
|
||||
|
||||
void core1_entry();
|
||||
@@ -347,7 +349,7 @@ uint16_t get_16bit_CV (uint16_t CV_start_index);
|
||||
* @param speed_step The speed step byte.
|
||||
* @return `DIRECTION_FORWARD` for forward direction, `DIRECTION_REVERSE` for reverse direction.
|
||||
*/
|
||||
direction_t get_direction_of_speed_step(uint8_t speed_step);
|
||||
direction_t get_direction_of_speed_step(speed_step_t speed_step);
|
||||
|
||||
void set_error(error_t err);
|
||||
|
||||
|
||||
Reference in new issue
Block a user