Skip to content

Commit e29ee8c

Browse files
author
Richard Unger
committed
add 1-PWM support to teensy driver
1 parent bf0019d commit e29ee8c

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/drivers/hardware_specific/teensy_mcu.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,21 @@ void _setHighFrequency(const long freq, const int pin){
1212
}
1313

1414

15+
// function setting the high pwm frequency to the supplied pins
16+
// - Stepper motor - 2PWM setting
17+
// - hardware speciffic
18+
void* _configure1PWM(long pwm_frequency, const int pinA) {
19+
if(!pwm_frequency || !_isset(pwm_frequency) ) pwm_frequency = _PWM_FREQUENCY; // default frequency 25khz
20+
else pwm_frequency = _constrain(pwm_frequency, 0, _PWM_FREQUENCY_MAX); // constrain to 50kHz max
21+
_setHighFrequency(pwm_frequency, pinA);
22+
GenericDriverParams* params = new GenericDriverParams {
23+
.pins = { pinA },
24+
.pwm_frequency = pwm_frequency
25+
};
26+
return params;
27+
}
28+
29+
1530
// function setting the high pwm frequency to the supplied pins
1631
// - Stepper motor - 2PWM setting
1732
// - hardware speciffic
@@ -60,6 +75,17 @@ void* _configure4PWM(long pwm_frequency, const int pinA, const int pinB, const i
6075
return params;
6176
}
6277

78+
79+
80+
// function setting the pwm duty cycle to the hardware
81+
// - Stepper motor - 2PWM setting
82+
// - hardware speciffic
83+
void _writeDutyCycle1PWM(float dc_a, void* params) {
84+
// transform duty cycle from [0,1] to [0,255]
85+
analogWrite(((GenericDriverParams*)params)->pins[0], 255.0f*dc_a);
86+
}
87+
88+
6389
// function setting the pwm duty cycle to the hardware
6490
// - Stepper motor - 2PWM setting
6591
// - hardware speciffic
@@ -68,6 +94,8 @@ void _writeDutyCycle2PWM(float dc_a, float dc_b, void* params) {
6894
analogWrite(((GenericDriverParams*)params)->pins[0], 255.0f*dc_a);
6995
analogWrite(((GenericDriverParams*)params)->pins[1], 255.0f*dc_b);
7096
}
97+
98+
7199
// function setting the pwm duty cycle to the hardware
72100
// - BLDC motor - 3PWM setting
73101
// - hardware speciffic

0 commit comments

Comments
 (0)