HRI board firmware v2.1 Microcontroller firmware of the board used during the HRI labs.

h_bridge.h
Go to the documentation of this file.
1 /*
2 * Copyright (C) 2017 EPFL-LSRO (Laboratoire de Systemes Robotiques).
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #ifndef __H_BRIDGE_H
18 #define __H_BRIDGE_H
19
20 #include "../main.h"
21
22 #define PWM1_Pin 6
23 #define PWM1_Port GPIOC
24 #define PWM2_Pin 7
25 #define PWM2_Port GPIOC
26 #define ENB1_Pin 8
27 #define ENB1_Port GPIOC
28 #define ENB2_Pin 9
29 #define ENB2_Port GPIOC
30 #define nFAULT_Pin GPIO_Pin_15
31 #define nFAULT_Port GPIOD
32 #define nSLEEP_Pin GPIO_Pin_14
33 #define nSLEEP_Port GPIOD
34
35 #define PWM_FREQUENCY 30000 // Motor PWM freq. [Hz]
36
37 #define PWM_RESOL_SHIFT_DWN 6 // PWM_SCALE = 0xFFFF/2^PWM_RESOL_SHIFT_DWN
38 #define CURRENT_SCALE_RESOL ((uint32_t)(16-PWM_RESOL_SHIFT_DWN))
39 #define PWM_TIM_PERIODE ((int16_t)(0xFFFF>>PWM_RESOL_SHIFT_DWN))
40 #define PWM_TIM_PRESCALER ((int16_t)(SystemCoreClock/APB2_PRESCALER*TIM_MULTIPLIER/PWM_FREQUENCY/PWM_TIM_PERIODE-1))
41
56 void hb_Init(void);
57 void hb_Enable(void);
58 void hb_Disable(void);
59 void hb_SetPWM(float32_t ratio);
60 bool hb_HasFault(void);
61
66 #endif
hb_Init
void hb_Init(void)
Initialize the pins and the PWM timer to control the H-bridge.
Definition: h_bridge.c:24
hb_Enable
void hb_Enable(void)
Enable the motor driver.
Definition: h_bridge.c:109
hb_Disable
void hb_Disable(void)
Disable the motor driver.
Definition: h_bridge.c:118
hb_SetPWM
void hb_SetPWM(float32_t ratio)
Set the PWM duty.
Definition: h_bridge.c:129
hb_HasFault
bool hb_HasFault(void)
Gets the fault state. Gets the fault state of the H-Bridge from its nFAULT line. A fault may be becau...
Definition: h_bridge.c:145