Skip to content

Commit

Permalink
Store PID parameters in flash.
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhuYanzhen1 committed Sep 21, 2021
1 parent 184cad8 commit fb3b895
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions program/hardware/flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,18 @@
\retval none
*/
void flash_write_parameters(void) {
unsigned int buffer[2] = {machine_angle_offset, phase_sequence};
unsigned int buffer[10] = {machine_angle_offset, phase_sequence, 0x00000000UL, 0x00000000UL,
0x00000000UL, 0x00000000UL, 0x00000000UL, 0x00000000UL, 0x00000000UL, 0x00000000UL};
buffer[2] = float_to_int32(speed_pid_handler.kp);
buffer[3] = float_to_int32(speed_pid_handler.ki);
buffer[4] = float_to_int32(speed_pid_handler.kd);
buffer[5] = float_to_int32(speed_pid_handler.sum_maximum);
buffer[6] = float_to_int32(angle_pid_handler.kp);
buffer[7] = float_to_int32(angle_pid_handler.ki);
buffer[8] = float_to_int32(angle_pid_handler.kd);
buffer[9] = float_to_int32(angle_pid_handler.sum_maximum);
flash_erase_page();
flash_program_word(0x00000000UL, buffer, 2);
flash_program_word(0x00000000UL, buffer, 10);
}

/*!
Expand All @@ -25,6 +34,14 @@ void flash_write_parameters(void) {
void flash_read_parameters(void) {
machine_angle_offset = flash_read_word(0x00000000UL);
phase_sequence = flash_read_word(0x00000004UL);
speed_pid_handler.kp = int32_to_float(flash_read_word(0x00000008UL));
speed_pid_handler.ki = int32_to_float(flash_read_word(0x00000012UL));
speed_pid_handler.kd = int32_to_float(flash_read_word(0x00000016UL));
speed_pid_handler.sum_maximum = int32_to_float(flash_read_word(0x00000020UL));
angle_pid_handler.kp = int32_to_float(flash_read_word(0x00000024UL));
angle_pid_handler.ki = int32_to_float(flash_read_word(0x00000028UL));
angle_pid_handler.kd = int32_to_float(flash_read_word(0x00000032UL));
angle_pid_handler.sum_maximum = int32_to_float(flash_read_word(0x00000036UL));
if (machine_angle_offset > 4096 || phase_sequence > 1) {
led_on();
while (1);
Expand Down

0 comments on commit fb3b895

Please sign in to comment.