-
Notifications
You must be signed in to change notification settings - Fork 2
Add support to read data from 3 encoders #29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,7 +36,7 @@ void hwbp_app_initialize(void) | |
uint8_t hwH = 2; | ||
uint8_t hwL = 0; | ||
uint8_t fwH = 3; | ||
uint8_t fwL = 2; | ||
uint8_t fwL = 3; | ||
uint8_t ass = 0; | ||
|
||
/* Start core */ | ||
|
@@ -62,7 +62,7 @@ void core_callback_catastrophic_error_detected(void) | |
{ | ||
uint8_t led[3] = {0, 0, 0}; | ||
|
||
timer_type0_stop(&TCF0); clr_DO0; | ||
timer_type0_stop(&TCF0); clr_DO0; | ||
timer_type0_stop(&TCE0); clr_DO1; | ||
timer_type0_stop(&TCD0); clr_DO2; | ||
timer_type0_stop(&TCC0); clr_DO3; | ||
|
@@ -180,7 +180,9 @@ void core_callback_reset_registers(void) | |
//app_regs.REG_PORT_DIOS_IN = 0; | ||
|
||
//app_regs.REG_DATA[0] = 0; | ||
app_regs.REG_DATA[1] = 0; | ||
app_regs.REG_DATA_ENCODERS[REG_DATA_ENCODERS_INDEX_ENCODER0] = 0; | ||
app_regs.REG_DATA_ENCODERS[REG_DATA_ENCODERS_INDEX_ENCODER1] = 0; | ||
app_regs.REG_DATA_ENCODERS[REG_DATA_ENCODERS_INDEX_ENCODER2] = 0; | ||
|
||
app_regs.REG_OUTPUT_PULSE_EN = B_PORT0_12V | B_PORT1_12V | B_PORT2_12V; | ||
|
||
|
@@ -363,45 +365,98 @@ uint8_t t1ms = 0; | |
|
||
bool first_adc_channel; | ||
|
||
int16_t previous_encoder_poke0; | ||
int16_t previous_encoder_poke1; | ||
int16_t previous_encoder_poke2; | ||
|
||
int16_t encoder0_value; | ||
int16_t encoder1_value; | ||
int16_t encoder2_value; | ||
|
||
void core_callback_t_before_exec(void) | ||
{ | ||
if (t1ms++ & 1) | ||
{ | ||
/* Read ADC */ | ||
core_func_mark_user_timestamp(); | ||
if (t1ms++ & 1) | ||
{ | ||
/* Read ADC */ | ||
core_func_mark_user_timestamp(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A fair amount changes seem to be due to different editor configuration. Ideally these would not be tracked in the PR There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @bruno-f-cruz good point, probably the best would be to provide a .editorconfig file defining the common rules and then go from there. @nightswimmer we can look at this together and reproduce the settings for the existing project to minimize the diff, then rebase. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @bruno-f-cruz me and @nightswimmer were looking at this together and it looks like the spacing across firmware source code is very much random, even within the same file sometimes tabs are used, sometimes spaces, and it is not very clear which one is the dominant style. If we are going to correct this, it might be better to just unify the entire source code into a single format (I suggest spaces) and possibly add ignore this formatting commit for git blame. I will prepare a PR for review just with very basic editor config settings and we can decide. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @bruno-f-cruz Actually, let's backtrack on this, it is too messy and ambiguous to understand at this point, probably best to raise an issue and decide a consistent strategy for editor config across all files before we start enforcing this consistently. To summarize the situation: there is in fact already a The current state of mixed spacing rules throughout the firmware source code is likely a reflection of different people editing the code with different settings over time. |
||
|
||
/* Start conversation on ADCA Channel 0*/ | ||
first_adc_channel = true; | ||
ADCA_CH0_MUXCTRL = 0 << 3; | ||
ADCA_CH0_CTRL |= ADC_CH_START_bm; | ||
/* Start conversation on ADCA Channel 0*/ | ||
first_adc_channel = true; | ||
ADCA_CH0_MUXCTRL = 0 << 3; | ||
ADCA_CH0_CTRL |= ADC_CH_START_bm; | ||
|
||
/* Read encoder on Port 2 */ | ||
if (app_regs.REG_EN_ENCODERS & B_EN_ENCODER_PORT2) | ||
{ | ||
int16_t timer_cnt = TCD1_CNT; | ||
/* Read encoder on Port 0 */ | ||
if (app_regs.REG_EN_ENCODERS & B_EN_ENCODER_PORT0) | ||
{ | ||
int16_t timer_cnt = TCD1_CNT; | ||
|
||
if (app_regs.REG_CONF_ENCODERS == GM_POSITION) | ||
{ | ||
if (timer_cnt > 32768) | ||
{ | ||
app_regs.REG_DATA_ENCODERS[REG_DATA_ENCODERS_INDEX_ENCODER0] = 0xFFFF - timer_cnt; | ||
encoder0_value = 0xFFFF - timer_cnt; | ||
} | ||
else | ||
{ | ||
app_regs.REG_DATA_ENCODERS[REG_DATA_ENCODERS_INDEX_ENCODER0] = (32768 - timer_cnt) * -1; | ||
} | ||
} | ||
else | ||
{ | ||
app_regs.REG_DATA_ENCODERS[REG_DATA_ENCODERS_INDEX_ENCODER0] = previous_encoder_poke0 - timer_cnt; | ||
previous_encoder_poke0 = timer_cnt; | ||
} | ||
} | ||
|
||
/* Read encoder on Port 1 */ | ||
if (app_regs.REG_EN_ENCODERS & B_EN_ENCODER_PORT1) | ||
{ | ||
int16_t timer_cnt = TCE1_CNT; | ||
|
||
if (app_regs.REG_CONF_ENCODERS == GM_POSITION) | ||
{ | ||
if (timer_cnt > 32768) | ||
{ | ||
app_regs.REG_DATA_ENCODERS[REG_DATA_ENCODERS_INDEX_ENCODER1] = 0xFFFF - timer_cnt; | ||
encoder1_value = 0xFFFF - timer_cnt; | ||
} | ||
else | ||
{ | ||
app_regs.REG_DATA_ENCODERS[REG_DATA_ENCODERS_INDEX_ENCODER1] = (32768 - timer_cnt) * -1; | ||
} | ||
} | ||
else | ||
{ | ||
app_regs.REG_DATA_ENCODERS[REG_DATA_ENCODERS_INDEX_ENCODER1] = previous_encoder_poke1 - timer_cnt; | ||
previous_encoder_poke1 = timer_cnt; | ||
} | ||
} | ||
|
||
/* Read encoder on Port 2 */ | ||
if (app_regs.REG_EN_ENCODERS & B_EN_ENCODER_PORT2) | ||
{ | ||
int16_t timer_cnt = TCF1_CNT; | ||
|
||
if (app_regs.REG_CONF_ENCODERS == GM_POSITION) | ||
{ | ||
if (timer_cnt > 32768) | ||
{ | ||
app_regs.REG_DATA[1] = 0xFFFF - timer_cnt; | ||
} | ||
else | ||
{ | ||
app_regs.REG_DATA[1] = (32768 - timer_cnt) * -1; | ||
} | ||
} | ||
else | ||
{ | ||
app_regs.REG_DATA[1] = previous_encoder_poke2 - timer_cnt; | ||
|
||
previous_encoder_poke2 = timer_cnt; | ||
} | ||
|
||
} | ||
} | ||
if (app_regs.REG_CONF_ENCODERS == GM_POSITION) | ||
{ | ||
if (timer_cnt > 32768) | ||
{ | ||
app_regs.REG_DATA_ENCODERS[REG_DATA_ENCODERS_INDEX_ENCODER2] = 0xFFFF - timer_cnt; | ||
encoder2_value = 0xFFFF - timer_cnt; | ||
} | ||
else | ||
{ | ||
app_regs.REG_DATA_ENCODERS[REG_DATA_ENCODERS_INDEX_ENCODER2] = (32768 - timer_cnt) * -1; | ||
} | ||
} | ||
else | ||
{ | ||
app_regs.REG_DATA_ENCODERS[REG_DATA_ENCODERS_INDEX_ENCODER2] = previous_encoder_poke2 - timer_cnt; | ||
previous_encoder_poke2 = timer_cnt; | ||
} | ||
} | ||
} | ||
} | ||
|
||
void core_callback_t_after_exec(void){} | ||
|
@@ -517,10 +572,16 @@ void core_callback_t_1ms(void) | |
if (int2_enable_counter) | ||
if ((--int2_enable_counter) == 0) | ||
PORTF_INTCTRL |= INT_LEVEL_LOW; | ||
|
||
// If any of the encoders is enabled, send the data | ||
if (app_regs.REG_EN_ENCODERS) | ||
{ | ||
core_func_send_event(ADD_REG_DATA_ENCODERS, false); | ||
} | ||
} | ||
|
||
/************************************************************************/ | ||
/* Callbacks: cloc control */ | ||
/* Callbacks: clock control */ | ||
/************************************************************************/ | ||
void core_callback_clock_to_repeater(void) {} | ||
void core_callback_clock_to_generator(void) {} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably unintended change