MATSU-bed(LPC1549)でPWMを4つ以上出すプログラム
Dependents: servo_controller_1549
Diff: pwm_all_api.cpp
- Revision:
- 4:49ee58dc8e4d
- Parent:
- 3:af461f11cef6
- Child:
- 5:88243d59b4df
--- a/pwm_all_api.cpp Fri Feb 16 09:06:32 2018 +0000 +++ b/pwm_all_api.cpp Sat Feb 17 07:23:48 2018 +0000 @@ -101,7 +101,7 @@ uint32_t pwm_out_map[] = {3, 4, 3, 4, 0, 0, 3, 1, 2, 0, 1, 2, 1, 0, 5, 0, 0, 1, 5, 2, 6, 6, 0}; -void pwmout_init(pwmout_t* obj, PinName pin) { +void pwmout_all_init(pwmout_all_t* obj, PinName pin) { MBED_ASSERT(pin != (uint32_t)NC); int sct_n = get_available_sct(); @@ -426,17 +426,18 @@ pwm->CTRL &= ~(1 << 2); // default to 20ms: standard for servos, and fine for e.g. brightness control - pwmout_period_ms(obj, 20); - pwmout_write (obj, 0.5); + pwmout_all_period_ms(obj, 20); + pwmout_all_write (obj, 0.5); } -void pwmout_free(pwmout_t* obj) { + +void pwmout_all_free(pwmout_all_t* obj) { // Disable the SCT clock LPC_SYSCON->SYSAHBCLKCTRL1 &= ~(1 << (obj->pwm_ch + 2)); sct_used &= ~(1 << obj->pwm_ch); } -void pwmout_write(pwmout_t* obj, float value) { +void pwmout_all_write(pwmout_all_t* obj, float value) { LPC_SCT0_Type* pwm = obj->pwm; if (value < 0.0f) { value = 0.0; @@ -476,23 +477,23 @@ } } -float pwmout_read(pwmout_t* obj) { +float pwmout_all_read(pwmout_all_t* obj) { uint32_t t_off = obj->pwm->MATCHREL0; uint32_t t_on = obj->pwm->MATCHREL1; float v = (float)t_on/(float)t_off; return (v > 1.0f) ? (1.0f) : (v); } -void pwmout_period(pwmout_t* obj, float seconds) { - pwmout_period_us(obj, seconds * 1000000.0f); +void pwmout_all_period(pwmout_all_t* obj, float seconds) { + pwmout_all_period_us(obj, seconds * 1000000.0f); } -void pwmout_period_ms(pwmout_t* obj, int ms) { - pwmout_period_us(obj, ms * 1000); +void pwmout_all_period_ms(pwmout_all_t* obj, int ms) { + pwmout_all_period_us(obj, ms * 1000); } // Set the PWM period, keeping the duty cycle the same. -void pwmout_period_us(pwmout_t* obj, int us) { +void pwmout_all_period_us(pwmout_all_t* obj, int us) { LPC_SCT0_Type* pwm = obj->pwm; uint32_t t_off = pwm->MATCHREL0; uint32_t t_on = pwm->MATCHREL1; @@ -530,15 +531,15 @@ } } -void pwmout_pulsewidth(pwmout_t* obj, float seconds) { - pwmout_pulsewidth_us(obj, seconds * 1000000.0f); +void pwmout_all_pulsewidth(pwmout_all_t* obj, float seconds) { + pwmout_all_pulsewidth_us(obj, seconds * 1000000.0f); } -void pwmout_pulsewidth_ms(pwmout_t* obj, int ms) { - pwmout_pulsewidth_us(obj, ms * 1000); +void pwmout_all_pulsewidth_ms(pwmout_all_t* obj, int ms) { + pwmout_all_pulsewidth_us(obj, ms * 1000); } -void pwmout_pulsewidth_us(pwmout_t* obj, int us) { +void pwmout_all_pulsewidth_us(pwmout_all_t* obj, int us) { //obj->pwm->MATCHREL1 = (uint32_t)us; switch(obj->out_ch){ case 0: