Skyward boardcore
Loading...
Searching...
No Matches
HBridge.h
Go to the documentation of this file.
1/* Copyright (c) 2020 Skyward Experimental Rocketry
2 * Authors: Luca Conterio, Alberto Nidasio
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 * THE SOFTWARE.
21 */
22
23#pragma once
24
25#include <drivers/timer/PWM.h>
27#include <miosix.h>
28
29namespace Boardcore
30{
31
57{
58public:
73 HBridge(miosix::GpioPin inhibitPin, TIM_TypeDef* timer,
74 TimerUtils::Channel channel, unsigned int frequency,
75 float dutyCycle = 0, unsigned int disableDelayMs = 50);
76
83 ~HBridge();
84
88 void enable();
89
94 void disable();
95
96 bool isEnabled();
97
104 void setDutyCycle(float dutyCycle);
105
112 void testDutyCycle(float dutyCycle);
113
118
119private:
120 // This class is not copyable!
121 HBridge& operator=(const HBridge&) = delete;
122 HBridge(const HBridge& hb) = delete;
123
124 miosix::GpioPin inhibitPin;
125 PWM pwm;
126 TimerUtils::Channel channel;
127
128 unsigned int frequency;
129 float dutyCycle;
130 unsigned int disableDelayMs;
131};
132
133} // namespace Boardcore
Driver to operate an H-bridge.
Definition HBridge.h:57
void testDutyCycle(float dutyCycle)
Same as setDutyCycle() but does not memorize the value.
Definition HBridge.cpp:65
HBridge(miosix::GpioPin inhibitPin, TIM_TypeDef *timer, TimerUtils::Channel channel, unsigned int frequency, float dutyCycle=0, unsigned int disableDelayMs=50)
Prepares the enable pin and the timer.
Definition HBridge.cpp:28
void disable()
Stops the pwm signal and deactivates the H-bridge after the configured amount of time.
Definition HBridge.cpp:47
void enable()
Enables the H-bridge and starts the pwm signal.
Definition HBridge.cpp:39
void resetDutyCycle()
Resets the duty cycle to the last configure value.
~HBridge()
Disables the H-bridge.
Definition HBridge.cpp:37
void setDutyCycle(float dutyCycle)
Changes the current duty cycle and saves it.
Definition HBridge.cpp:58
Driver for easy access to the PWM capabilities of the general purpose timers.
Definition PWM.h:52
This file includes all the types the logdecoder script will decode.