Skyward boardcore
Loading...
Searching...
No Matches
HBridge.cpp
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#include "HBridge.h"
24
25namespace Boardcore
26{
27
28HBridge::HBridge(miosix::GpioPin inhibitPin, TIM_TypeDef* timer,
29 TimerUtils::Channel channel, unsigned int frequency,
30 float dutyCycle, unsigned int disableDelayMs)
31 : inhibitPin(inhibitPin), pwm(timer, frequency), channel(channel),
32 frequency(frequency), dutyCycle(dutyCycle), disableDelayMs(disableDelayMs)
33{
34 inhibitPin.low();
35}
36
38
40{
41 pwm.setDutyCycle(channel, dutyCycle);
42 pwm.enableChannel(channel);
43
44 inhibitPin.high();
45}
46
48{
49 pwm.disableChannel(channel);
50
51 miosix::Thread::sleep(disableDelayMs);
52
53 inhibitPin.low();
54}
55
56bool HBridge::isEnabled() { return pwm.isChannelEnabled(channel); }
57
58void HBridge::setDutyCycle(float dutyCycle)
59{
60 this->dutyCycle = dutyCycle;
61
62 pwm.setDutyCycle(channel, dutyCycle);
63}
64
65void HBridge::testDutyCycle(float testDutyCycle)
66{
67 pwm.setDutyCycle(channel, testDutyCycle);
68}
69
70} // namespace Boardcore
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
~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
void disableChannel(TimerUtils::Channel channel)
Definition PWM.cpp:68
void setDutyCycle(TimerUtils::Channel channel, float dutyCycle)
Sets the duty cycle for the specified channel.
Definition PWM.cpp:78
bool isChannelEnabled(TimerUtils::Channel channel)
Definition PWM.cpp:73
void enableChannel(TimerUtils::Channel channel, Polarity polarity=Polarity::NORMAL)
Definition PWM.cpp:56
This file includes all the types the logdecoder script will decode.