diff --git a/projects/dyno/Makefile b/projects/dyno/Makefile index d96dcad..9174be7 100644 --- a/projects/dyno/Makefile +++ b/projects/dyno/Makefile @@ -161,7 +161,7 @@ $(BUILDDIRS): echo "target remote localhost:3333" > .gdbinit echo "mon reset init" >> .gdbinit echo "" >> .gdbinit - echo "def flash" >> .gdbinit + echo "define flash" >> .gdbinit echo " file $(BUILD_PATH)/$(PRG).elf" >> .gdbinit echo " mon reset halt" >> .gdbinit echo " mon flash erase_address pad 0x08000000 [file size $(PWD)/$(BUILD_PATH)/$(PRG).bin]" >> .gdbinit @@ -169,11 +169,11 @@ $(BUILDDIRS): echo " mon reset init" >> .gdbinit echo "end" >> .gdbinit echo "" >> .gdbinit - echo "def reset" >> .gdbinit + echo "define reset" >> .gdbinit echo " mon reset halt" >> .gdbinit echo " mon reset init" >> .gdbinit echo "end" >> .gdbinit - echo "def erase_all" >> .gdbinit + echo "define erase_all" >> .gdbinit echo " mon reset halt" >> .gdbinit echo " mon stm32f2x mass_erase 0" >> .gdbinit echo " mon reset init" >> .gdbinit diff --git a/projects/dyno/main.cpp b/projects/dyno/main.cpp index 6e699ce..20007f3 100644 --- a/projects/dyno/main.cpp +++ b/projects/dyno/main.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012-2023, Michael E. Ferguson + * Copyright (c) 2012-2025, Michael E. Ferguson * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -56,8 +56,11 @@ ADS8684 adc; #include "dac121.hpp" DAC121 dac; +// Encoder is AMT102-V, set to 2048PPR = 8192CPR #include "encoder.hpp" Encoder absorber_enc; +#define ABSORBER_CPR 8192.0f +#define TO_RADIANS (2.0f * 3.141592653589793f) #include "copy_float.hpp" @@ -300,7 +303,7 @@ int main(void) dac.init(); // Setup systick - SysTick_Config(SystemCoreClock/25000); + SysTick_Config(SystemCoreClock / 25000); LwIP_Init(); if (!udp_interface_init()) @@ -319,6 +322,7 @@ int main(void) extern "C" { +// Systick runs at 25khz void SysTick_Handler(void) { // Update system time @@ -328,17 +332,17 @@ void SysTick_Handler(void) // Get system voltage // adc is 12 bit (4096 count) spread over 3.3V // voltage divider is 15k/1k - dyno.system_voltage = (ADC1->JDR1/4096.0f) * 3.3f * 16.0f; + dyno.system_voltage = (ADC1->JDR1 / 4096.0f) * 3.3f * 16.0f; ADC1->CR2 |= ADC_CR2_JSWSTART; // TODO: make the sampling time dynamic based on velocity + // Encoder update runs at 250hz if (dyno.system_time % 100 == 0) { int32_t pos = absorber_enc.read(); int32_t vel = absorber_enc.read_speed(); - // TODO: calculate position - dyno.position = 0.0f; - dyno.velocity = (static_cast(vel) * 250.0f / 7200.0f) * 2.0f * 3.141592653589793f; + dyno.position = static_cast(pos) / ABSORBER_CPR * TO_RADIANS; + dyno.velocity = (static_cast(vel) * 250.0f / ABSORBER_CPR) * TO_RADIANS; } adc.update();