Add delay after switching off H-bridge
This commit is contained in:
@@ -60,6 +60,15 @@ uint16_t ADC_ReadChannel(uint32_t channel);
|
|||||||
/* Private user code ---------------------------------------------------------*/
|
/* Private user code ---------------------------------------------------------*/
|
||||||
/* USER CODE BEGIN 0 */
|
/* USER CODE BEGIN 0 */
|
||||||
|
|
||||||
|
void H_bridge_delay()
|
||||||
|
{
|
||||||
|
// very rough calculation: body of the loop takes 8 instructions,
|
||||||
|
// freq is 12 MHz: 8 / 12e6 * 100 = 0.000066 s, so about 66 ns
|
||||||
|
// This calculation could be way off, but it doesn't matter that much
|
||||||
|
volatile uint32_t delay = 100;
|
||||||
|
while(--delay > 0) {}
|
||||||
|
}
|
||||||
|
|
||||||
void H_bridge_turn_off()
|
void H_bridge_turn_off()
|
||||||
{
|
{
|
||||||
HAL_GPIO_WritePin(LS_A_GPIO_Port, LS_A_Pin, GPIO_PIN_RESET);
|
HAL_GPIO_WritePin(LS_A_GPIO_Port, LS_A_Pin, GPIO_PIN_RESET);
|
||||||
@@ -71,6 +80,9 @@ void H_bridge_turn_off()
|
|||||||
void H_bridge_set_direction(bool positive)
|
void H_bridge_set_direction(bool positive)
|
||||||
{
|
{
|
||||||
H_bridge_turn_off();
|
H_bridge_turn_off();
|
||||||
|
// delay to make sure all FETs are turned off;
|
||||||
|
// not measured, just eyeballing the time
|
||||||
|
H_bridge_delay();
|
||||||
if (positive)
|
if (positive)
|
||||||
{
|
{
|
||||||
HAL_GPIO_WritePin(HS_A_GPIO_Port, HS_A_Pin, GPIO_PIN_SET);
|
HAL_GPIO_WritePin(HS_A_GPIO_Port, HS_A_Pin, GPIO_PIN_SET);
|
||||||
|
|||||||
Reference in New Issue
Block a user