Skip to content
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

Use TIM2 Output Compare to autotrigger GPIO pin #17

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jfedor2
Copy link
Contributor

@jfedor2 jfedor2 commented Oct 8, 2024

Makes it so that triggering the GPIO pin is uniformly spread over a span of 1ms by using the timer output compare function.

Because the pin toggling is done in hardware, the timing is not affected by interrupt handlers and higher prority threads.

Changes the GPIO pin used from PB15 (Arduino D11) to PA15 (Arduino D9).

Doesn't take the "Auto-trigger Level" setting into consideration.

Makes it so that triggering the GPIO pin is uniformly spread over a span
of 1ms by using the timer output compare function.

Because the pin toggling is done in hardware, the timing is not affected
by interrupt handlers and higher prority threads.

Changes the GPIO pin used from PB15 (Arduino D11) to PA15 (Arduino D9).

Doesn't take the "Auto-trigger Level" setting into consideration.
@jfedor2
Copy link
Contributor Author

jfedor2 commented Oct 8, 2024

This is a proof-of-concept proposed solution for #16.

HAL_GPIO_WritePin(ARDUINO_D11_GPIO_Port, ARDUINO_D11_Pin, auto_trigger_level_high ? GPIO_PIN_SET : GPIO_PIN_RESET);
uint32_t delay = rand() % 1000 + 100;
last_btn_gpio_timestamp = xlat_counter_1mhz_get() + delay;
htim2.Instance->CCR1 = last_btn_gpio_timestamp;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there's a potential issue if we get interrupted for longer than the chosen delay time before this line as the output compare function checks for exact match, so we might miss it. Could possibly solve it with PWM mode or just making the delay long enough.

}

void xlat_auto_trigger_turn_off_action(void)
{
HAL_GPIO_WritePin(ARDUINO_D11_GPIO_Port, ARDUINO_D11_Pin, auto_trigger_level_high ? GPIO_PIN_RESET : GPIO_PIN_SET);
htim2.Instance->CCR1 = xlat_counter_1mhz_get() + 100;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar issue here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant