Skip to content

Commit

Permalink
encoder works
Browse files Browse the repository at this point in the history
  • Loading branch information
Known4225 committed Dec 23, 2024
1 parent e14f096 commit cfd2b70
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 14 deletions.
5 changes: 5 additions & 0 deletions sdk/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"files.associations": {
"iostream": "cpp"
}
}
2 changes: 1 addition & 1 deletion sdk/FreeRTOS-Plus-TCP
16 changes: 8 additions & 8 deletions sdk/freertos_app_cpu0/.cproject
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<tool id="xilinx.gnu.armv7.c.toolchain.compiler.debug.1911982104" name="ARM v7 gcc compiler" superClass="xilinx.gnu.armv7.c.toolchain.compiler.debug">
<option defaultValue="gnu.c.optimization.level.none" id="xilinx.gnu.compiler.option.optimization.level.1046191149" name="Optimization Level" superClass="xilinx.gnu.compiler.option.optimization.level" valueType="enumerated"/>
<option id="xilinx.gnu.compiler.option.debugging.level.1838336793" name="Debug Level" superClass="xilinx.gnu.compiler.option.debugging.level" value="gnu.c.debugging.level.max" valueType="enumerated"/>
<option id="xilinx.gnu.compiler.inferred.swplatform.includes.427674154" name="Software Platform Include Path" superClass="xilinx.gnu.compiler.inferred.swplatform.includes" valueType="includePath"/>
<option id="xilinx.gnu.compiler.inferred.swplatform.includes.427674154" name="Software Platform Include Path" superClass="xilinx.gnu.compiler.inferred.swplatform.includes"/>
<option id="xilinx.gnu.compiler.misc.other.1212870980" name="Other flags" superClass="xilinx.gnu.compiler.misc.other" value="-c -fmessage-length=0 -MT&quot;$@&quot; -mcpu=cortex-a9 -mfpu=vfpv3 -mfloat-abi=hard" valueType="string"/>
<option id="xilinx.gnu.compiler.inferred.swplatform.flags.2118790169" name="Software Platform Inferred Flags" superClass="xilinx.gnu.compiler.inferred.swplatform.flags" value=" " valueType="string"/>
<option id="xilinx.gnu.compiler.dircategory.includes.488002873" name="Include Paths" superClass="xilinx.gnu.compiler.dircategory.includes" valueType="includePath">
Expand Down Expand Up @@ -57,7 +57,7 @@
</tool>
<tool id="xilinx.gnu.armv7.toolchain.archiver.1965964781" name="ARM v7 archiver" superClass="xilinx.gnu.armv7.toolchain.archiver"/>
<tool id="xilinx.gnu.armv7.c.toolchain.linker.debug.1928616091" name="ARM v7 gcc linker" superClass="xilinx.gnu.armv7.c.toolchain.linker.debug">
<option id="xilinx.gnu.linker.inferred.swplatform.lpath.1535496169" name="Software Platform Library Path" superClass="xilinx.gnu.linker.inferred.swplatform.lpath" valueType="libPaths"/>
<option id="xilinx.gnu.linker.inferred.swplatform.lpath.1535496169" name="Software Platform Library Path" superClass="xilinx.gnu.linker.inferred.swplatform.lpath"/>
<option id="xilinx.gnu.linker.inferred.swplatform.flags.1240781130" name="Software Platform Inferred Flags" superClass="xilinx.gnu.linker.inferred.swplatform.flags" valueType="libs">
<listOptionValue builtIn="false" value="-Wl,--start-group,-lxil,-lgcc,-lc,--end-group"/>
</option>
Expand All @@ -76,7 +76,7 @@
<inputType id="xilinx.gnu.linker.input.lscript.2012147853" name="Linker Script" superClass="xilinx.gnu.linker.input.lscript"/>
</tool>
<tool id="xilinx.gnu.armv7.cxx.toolchain.linker.debug.1164314051" name="ARM v7 g++ linker" superClass="xilinx.gnu.armv7.cxx.toolchain.linker.debug">
<option id="xilinx.gnu.linker.inferred.swplatform.lpath.395189134" name="Software Platform Library Path" superClass="xilinx.gnu.linker.inferred.swplatform.lpath" valueType="libPaths"/>
<option id="xilinx.gnu.linker.inferred.swplatform.lpath.395189134" name="Software Platform Library Path" superClass="xilinx.gnu.linker.inferred.swplatform.lpath"/>
<option id="xilinx.gnu.linker.inferred.swplatform.flags.94761094" name="Software Platform Inferred Flags" superClass="xilinx.gnu.linker.inferred.swplatform.flags" valueType="libs">
<listOptionValue builtIn="false" value="-Wl,--start-group,-lxil,-lgcc,-lc,--end-group"/>
</option>
Expand All @@ -94,7 +94,7 @@
<sourceEntries>
<entry excluding="shared|Zynq|GCC|FreeRTOS-Plus-TCP|MemMang|ARM_CA9|FreeRTOS-Kernel" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="ARM_CA9"/>
<entry excluding="portable" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="FreeRTOS-Kernel"/>
<entry excluding="examples|portable" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="FreeRTOS-Kernel"/>
<entry excluding="tools|source/portable/NetworkInterface|source/portable/BufferManagement/BufferAllocation_1.c|source/portable/Compiler|test" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="FreeRTOS-Plus-TCP"/>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="GCC"/>
<entry excluding="heap_5.c|heap_3.c|heap_2.c|heap_1.c" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="MemMang"/>
Expand Down Expand Up @@ -132,7 +132,7 @@
<tool id="xilinx.gnu.armv7.c.toolchain.compiler.release.113308459" name="ARM v7 gcc compiler" superClass="xilinx.gnu.armv7.c.toolchain.compiler.release">
<option defaultValue="gnu.c.optimization.level.more" id="xilinx.gnu.compiler.option.optimization.level.193863771" name="Optimization Level" superClass="xilinx.gnu.compiler.option.optimization.level" valueType="enumerated"/>
<option id="xilinx.gnu.compiler.option.debugging.level.957144722" name="Debug Level" superClass="xilinx.gnu.compiler.option.debugging.level" value="gnu.c.debugging.level.none" valueType="enumerated"/>
<option id="xilinx.gnu.compiler.inferred.swplatform.includes.883297099" name="Software Platform Include Path" superClass="xilinx.gnu.compiler.inferred.swplatform.includes" valueType="includePath"/>
<option id="xilinx.gnu.compiler.inferred.swplatform.includes.883297099" name="Software Platform Include Path" superClass="xilinx.gnu.compiler.inferred.swplatform.includes"/>
<option id="xilinx.gnu.compiler.misc.other.974634919" name="Other flags" superClass="xilinx.gnu.compiler.misc.other" value="-c -fmessage-length=0 -MT&quot;$@&quot; -mcpu=cortex-a9 -mfpu=vfpv3 -mfloat-abi=hard" valueType="string"/>
<option id="xilinx.gnu.compiler.inferred.swplatform.flags.1644435644" name="Software Platform Inferred Flags" superClass="xilinx.gnu.compiler.inferred.swplatform.flags" value=" " valueType="string"/>
<option id="xilinx.gnu.compiler.dircategory.includes.641441859" name="Include Paths" superClass="xilinx.gnu.compiler.dircategory.includes" valueType="includePath">
Expand Down Expand Up @@ -161,7 +161,7 @@
</tool>
<tool id="xilinx.gnu.armv7.toolchain.archiver.1407914290" name="ARM v7 archiver" superClass="xilinx.gnu.armv7.toolchain.archiver"/>
<tool id="xilinx.gnu.armv7.c.toolchain.linker.release.1966414557" name="ARM v7 gcc linker" superClass="xilinx.gnu.armv7.c.toolchain.linker.release">
<option id="xilinx.gnu.linker.inferred.swplatform.lpath.1553088080" name="Software Platform Library Path" superClass="xilinx.gnu.linker.inferred.swplatform.lpath" valueType="libPaths"/>
<option id="xilinx.gnu.linker.inferred.swplatform.lpath.1553088080" name="Software Platform Library Path" superClass="xilinx.gnu.linker.inferred.swplatform.lpath"/>
<option id="xilinx.gnu.linker.inferred.swplatform.flags.471947342" name="Software Platform Inferred Flags" superClass="xilinx.gnu.linker.inferred.swplatform.flags" valueType="libs">
<listOptionValue builtIn="false" value="-Wl,--start-group,-lxil,-lgcc,-lc,--end-group"/>
</option>
Expand All @@ -180,7 +180,7 @@
<inputType id="xilinx.gnu.linker.input.lscript.927671816" name="Linker Script" superClass="xilinx.gnu.linker.input.lscript"/>
</tool>
<tool id="xilinx.gnu.armv7.cxx.toolchain.linker.release.1398604415" name="ARM v7 g++ linker" superClass="xilinx.gnu.armv7.cxx.toolchain.linker.release">
<option id="xilinx.gnu.linker.inferred.swplatform.lpath.1884164785" name="Software Platform Library Path" superClass="xilinx.gnu.linker.inferred.swplatform.lpath" valueType="libPaths"/>
<option id="xilinx.gnu.linker.inferred.swplatform.lpath.1884164785" name="Software Platform Library Path" superClass="xilinx.gnu.linker.inferred.swplatform.lpath"/>
<option id="xilinx.gnu.linker.inferred.swplatform.flags.542482653" name="Software Platform Inferred Flags" superClass="xilinx.gnu.linker.inferred.swplatform.flags" valueType="libs">
<listOptionValue builtIn="false" value="-Wl,--start-group,-lxil,-lgcc,-lc,--end-group"/>
</option>
Expand All @@ -196,7 +196,7 @@
</toolChain>
</folderInfo>
<sourceEntries>
<entry excluding="MemMang/heap_5.c|MemMang/heap_3.c|MemMang/heap_2.c|MemMang/heap_1.c|FreeRTOS-Plus-TCP/tools|FreeRTOS-Plus-TCP/source/portable/NetworkInterface|FreeRTOS-Plus-TCP/source/portable/BufferManagement/BufferAllocation_1.c|FreeRTOS-Plus-TCP/source/portable/Compiler|FreeRTOS-Plus-TCP/test|FreeRTOS-Kernel/portable" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/>
<entry excluding="FreeRTOS-Kernel/examples|MemMang/heap_5.c|MemMang/heap_3.c|MemMang/heap_2.c|MemMang/heap_1.c|FreeRTOS-Plus-TCP/tools|FreeRTOS-Plus-TCP/source/portable/NetworkInterface|FreeRTOS-Plus-TCP/source/portable/BufferManagement/BufferAllocation_1.c|FreeRTOS-Plus-TCP/source/portable/Compiler|FreeRTOS-Plus-TCP/test|FreeRTOS-Kernel/portable" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/>
</sourceEntries>
</configuration>
</storageModule>
Expand Down
2 changes: 1 addition & 1 deletion sdk/freertos_app_cpu0/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ void vApplicationGetTimerTaskMemory(StaticTask_t **ppxTimerTaskTCBBuffer, StackT
}

void vApplicationStackOverflowHook(TaskHandle_t xTask, char * pcTaskName) {
xil_printf("STACK OVERRFLOW ON TASK %s\n", pcTaskName);
xil_printf("STACK OVERFLOW ON TASK %s\n", pcTaskName);
}

/*******************************************************************************/
Expand Down
2 changes: 2 additions & 0 deletions sdk/freertos_app_cpu0/src/usr/vsiApp/app_vsiApp.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ void app_vsiApp_init(void)
timing_manager_enable_sensor(AMDS_2);
// Enable ADC (timing manager)
timing_manager_enable_sensor(ADC);
// Enable Encoder (timing manager)
timing_manager_enable_sensor(ENCODER);
// Register "vsi" command with system
cmd_vsiApp_register();
}
Expand Down
16 changes: 13 additions & 3 deletions sdk/freertos_app_cpu0/src/usr/vsiApp/task_vsiApp.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "drv/pwm.h"
#include "drv/analog.h"
#include "drv/amds.h"
#include "drv/encoder.h"
#include "sys/defines.h"
#include "sys/log.h"
#include "sys/injection.h"
Expand Down Expand Up @@ -43,6 +44,9 @@ int task_vsiApp_init(void)
if (pwm_enable() != SUCCESS) {
return FAILURE;
}

/* Encoder bits */
encoder_set_pulses_per_rev_bits(13);
/* Initialize signal injection points */
injection_ctx_init(&inj_ctx_ctrl[0], "amp*");
injection_ctx_init(&inj_ctx_ctrl[1], "theta*");
Expand All @@ -57,6 +61,7 @@ int task_vsiApp_init(void)
taskExists = 1;
xTaskCreate(task_vsiApp, (const char *) "vsiApp", configMINIMAL_STACK_SIZE,
NULL, tskIDLE_PRIORITY, &tcb);

return SUCCESS;
}

Expand Down Expand Up @@ -138,20 +143,25 @@ void task_vsiApp(void *arg)
if (valid == 0xFF) {
// Yay! 0xFF means the bits for all channels are valid!
// Read in values sampled on the AMDS (plugged into your GPIO port) from all channels:
int err;
err = amds_get_data(amds_port, AMDS_CH_1, &out_ch_1);
amds_get_data(amds_port, AMDS_CH_1, &out_ch_1);
amds_current_a = 0.00125 * out_ch_1;
// Now, "out" variables contain the sign-extended 16-bit
// sample value for each channel
}

log_callback(&Do, LOG_DOUBLE, "current_a");
log_callback(&current_a, LOG_FLOAT, "current_a");
log_callback(&current_b, LOG_FLOAT, "current_b");
log_callback(&current_c, LOG_FLOAT, "current_c");
log_callback(&voltage_a, LOG_FLOAT, "voltage_a");
log_callback(&voltage_b, LOG_FLOAT, "voltage_b");
log_callback(&voltage_c, LOG_FLOAT, "voltage_c");
log_callback(&amds_current_a, LOG_FLOAT, "amds_current_a");
log_callback(&Do, LOG_DOUBLE, "amplitude_internal");

uint32_t encPosition = 0;
encoder_get_position(&encPosition);
log_callback(&encPosition, LOG_INT, "encoder_position");
// xil_printf("encoder value: %d\n", encPosition);

/* delay(50us) */
// uint32_t startDelay = cpu_timer_now();
Expand Down
2 changes: 1 addition & 1 deletion sdk/shared/sys/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,7 @@ int log_print_info(void)

// Initialize the state machine callback tcb
task_info_exists = 1;
xTaskCreate(state_machine_info_callback, (const char *) "loginfo", configMINIMAL_STACK_SIZE,
xTaskCreate(state_machine_info_callback, (const char *) "loginfo", 512,
&ctx_info, tskIDLE_PRIORITY, &ctx_info.tcb);
return SUCCESS;
}
Expand Down

0 comments on commit cfd2b70

Please sign in to comment.