MATSU-bed(LPC1549)でPWMを4つ以上出すプログラム
Dependents: servo_controller_1549
pwm_all_api.h@5:88243d59b4df, 2018-03-12 (annotated)
- Committer:
- hardtail
- Date:
- Mon Mar 12 08:50:47 2018 +0000
- Revision:
- 5:88243d59b4df
- Parent:
- 4:49ee58dc8e4d
?????????????
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hardtail | 0:64b18a3829f1 | 1 | /* mbed Microcontroller Library |
hardtail | 0:64b18a3829f1 | 2 | * Copyright (c) 2006-2013 ARM Limited |
hardtail | 0:64b18a3829f1 | 3 | * |
hardtail | 0:64b18a3829f1 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
hardtail | 0:64b18a3829f1 | 5 | * you may not use this file except in compliance with the License. |
hardtail | 0:64b18a3829f1 | 6 | * You may obtain a copy of the License at |
hardtail | 0:64b18a3829f1 | 7 | * |
hardtail | 0:64b18a3829f1 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
hardtail | 0:64b18a3829f1 | 9 | * |
hardtail | 0:64b18a3829f1 | 10 | * Unless required by applicable law or agreed to in writing, software |
hardtail | 0:64b18a3829f1 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
hardtail | 0:64b18a3829f1 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
hardtail | 0:64b18a3829f1 | 13 | * See the License for the specific language governing permissions and |
hardtail | 0:64b18a3829f1 | 14 | * limitations under the License. |
hardtail | 0:64b18a3829f1 | 15 | */ |
hardtail | 0:64b18a3829f1 | 16 | #ifndef MBED_PWM_ALL_API_H |
hardtail | 0:64b18a3829f1 | 17 | #define MBED_PWM_ALL_API_H |
hardtail | 0:64b18a3829f1 | 18 | |
hardtail | 0:64b18a3829f1 | 19 | #include "device.h" |
hardtail | 0:64b18a3829f1 | 20 | |
hardtail | 0:64b18a3829f1 | 21 | |
hardtail | 4:49ee58dc8e4d | 22 | |
hardtail | 0:64b18a3829f1 | 23 | #ifdef __cplusplus |
hardtail | 0:64b18a3829f1 | 24 | extern "C" { |
hardtail | 0:64b18a3829f1 | 25 | #endif |
hardtail | 0:64b18a3829f1 | 26 | |
hardtail | 5:88243d59b4df | 27 | /* |
hardtail | 5:88243d59b4df | 28 | SCT OUT setting |
hardtail | 5:88243d59b4df | 29 | PIN | SCT |
hardtail | 5:88243d59b4df | 30 | -------------------- |
hardtail | 5:88243d59b4df | 31 | P0_0 | SCT0_OUT3 |
hardtail | 5:88243d59b4df | 32 | P0_1 | SCT0_OUT4 |
hardtail | 5:88243d59b4df | 33 | P0_2 | SCT1_OUT3 |
hardtail | 5:88243d59b4df | 34 | P0_3 | SCT1_OUT3 |
hardtail | 5:88243d59b4df | 35 | P0_4 | None (SPI_0) |
hardtail | 5:88243d59b4df | 36 | P0_5 | SCT0_OUT0 |
hardtail | 5:88243d59b4df | 37 | P0_6 | SCT2_OUT3 |
hardtail | 5:88243d59b4df | 38 | P0_7 | SCT0_OUT1 |
hardtail | 5:88243d59b4df | 39 | P0_8 | SCT0_OUT2 |
hardtail | 5:88243d59b4df | 40 | P0_9 | SCT1_OUT0 |
hardtail | 5:88243d59b4df | 41 | P0_10 | SCT1_OUT1 |
hardtail | 5:88243d59b4df | 42 | P0_11 | SCT1_OUT2 |
hardtail | 5:88243d59b4df | 43 | P0_12 | SCT2_OUT1 |
hardtail | 5:88243d59b4df | 44 | P0_13 | SCT2_OUT2 |
hardtail | 5:88243d59b4df | 45 | P0_14 | SCT1_OUT5 |
hardtail | 5:88243d59b4df | 46 | P0_15 | SCT3_OUT3 |
hardtail | 5:88243d59b4df | 47 | P0_16 | None (SPI_1) |
hardtail | 5:88243d59b4df | 48 | P0_17 | SCT3_OUT1 |
hardtail | 5:88243d59b4df | 49 | P0_18 | SCT0_OUT5 |
hardtail | 5:88243d59b4df | 50 | P0_19 | SCT3_OUT2 |
hardtail | 5:88243d59b4df | 51 | P0_20 | SCT1_OUT6 |
hardtail | 5:88243d59b4df | 52 | P0_21 | None (RESET) |
hardtail | 5:88243d59b4df | 53 | P0_22 | None (open drain i2c pin) |
hardtail | 5:88243d59b4df | 54 | P0_23 | None (open drain i2c pin) |
hardtail | 5:88243d59b4df | 55 | P0_24 | SCT0_OUT6 |
hardtail | 5:88243d59b4df | 56 | P0_25 | SCT2_OUT0 |
hardtail | 5:88243d59b4df | 57 | */ |
hardtail | 5:88243d59b4df | 58 | |
hardtail | 4:49ee58dc8e4d | 59 | struct pwmout_sct { |
hardtail | 4:49ee58dc8e4d | 60 | LPC_SCT0_Type* pwm; |
hardtail | 4:49ee58dc8e4d | 61 | uint32_t pwm_ch; |
hardtail | 4:49ee58dc8e4d | 62 | uint32_t out_ch; |
hardtail | 4:49ee58dc8e4d | 63 | uint32_t pin; |
hardtail | 4:49ee58dc8e4d | 64 | uint32_t match; |
hardtail | 4:49ee58dc8e4d | 65 | }; |
hardtail | 4:49ee58dc8e4d | 66 | |
hardtail | 4:49ee58dc8e4d | 67 | /** Pwmout hal structure. pwmout_s is declared in the target's hal |
hardtail | 4:49ee58dc8e4d | 68 | */ |
hardtail | 4:49ee58dc8e4d | 69 | typedef struct pwmout_sct pwmout_all_t; |
hardtail | 4:49ee58dc8e4d | 70 | |
hardtail | 4:49ee58dc8e4d | 71 | /** |
hardtail | 4:49ee58dc8e4d | 72 | * \defgroup hal_pwmout Pwmout hal functions |
hardtail | 4:49ee58dc8e4d | 73 | * @{ |
hardtail | 4:49ee58dc8e4d | 74 | */ |
hardtail | 0:64b18a3829f1 | 75 | |
hardtail | 4:49ee58dc8e4d | 76 | /** Initialize the pwm out peripheral and configure the pin |
hardtail | 4:49ee58dc8e4d | 77 | * |
hardtail | 4:49ee58dc8e4d | 78 | * @param obj The pwmout object to initialize |
hardtail | 4:49ee58dc8e4d | 79 | * @param pin The pwmout pin to initialize |
hardtail | 4:49ee58dc8e4d | 80 | */ |
hardtail | 4:49ee58dc8e4d | 81 | void pwmout_all_init(pwmout_all_t *obj, PinName pin); |
hardtail | 4:49ee58dc8e4d | 82 | |
hardtail | 4:49ee58dc8e4d | 83 | /** Deinitialize the pwmout object |
hardtail | 4:49ee58dc8e4d | 84 | * |
hardtail | 4:49ee58dc8e4d | 85 | * @param obj The pwmout object |
hardtail | 4:49ee58dc8e4d | 86 | */ |
hardtail | 4:49ee58dc8e4d | 87 | void pwmout_all_free(pwmout_all_t *obj); |
hardtail | 0:64b18a3829f1 | 88 | |
hardtail | 4:49ee58dc8e4d | 89 | /** Set the output duty-cycle in range <0.0f, 1.0f> |
hardtail | 4:49ee58dc8e4d | 90 | * |
hardtail | 4:49ee58dc8e4d | 91 | * Value 0.0f represents 0 percentage, 1.0f represents 100 percent. |
hardtail | 4:49ee58dc8e4d | 92 | * @param obj The pwmout object |
hardtail | 4:49ee58dc8e4d | 93 | * @param percent The floating-point percentage number |
hardtail | 4:49ee58dc8e4d | 94 | */ |
hardtail | 4:49ee58dc8e4d | 95 | void pwmout_all_write(pwmout_all_t *obj, float percent); |
hardtail | 4:49ee58dc8e4d | 96 | |
hardtail | 4:49ee58dc8e4d | 97 | /** Read the current float-point output duty-cycle |
hardtail | 4:49ee58dc8e4d | 98 | * |
hardtail | 4:49ee58dc8e4d | 99 | * @param obj The pwmout object |
hardtail | 4:49ee58dc8e4d | 100 | * @return A floating-point output duty-cycle |
hardtail | 4:49ee58dc8e4d | 101 | */ |
hardtail | 4:49ee58dc8e4d | 102 | float pwmout_all_read(pwmout_all_t *obj); |
hardtail | 0:64b18a3829f1 | 103 | |
hardtail | 4:49ee58dc8e4d | 104 | /** Set the PWM period specified in seconds, keeping the duty cycle the same |
hardtail | 4:49ee58dc8e4d | 105 | * |
hardtail | 4:49ee58dc8e4d | 106 | * Periods smaller than microseconds (the lowest resolution) are set to zero. |
hardtail | 4:49ee58dc8e4d | 107 | * @param obj The pwmout object |
hardtail | 4:49ee58dc8e4d | 108 | * @param seconds The floating-point seconds period |
hardtail | 4:49ee58dc8e4d | 109 | */ |
hardtail | 4:49ee58dc8e4d | 110 | void pwmout_all_period(pwmout_all_t *obj, float seconds); |
hardtail | 4:49ee58dc8e4d | 111 | |
hardtail | 4:49ee58dc8e4d | 112 | /** Set the PWM period specified in miliseconds, keeping the duty cycle the same |
hardtail | 4:49ee58dc8e4d | 113 | * |
hardtail | 4:49ee58dc8e4d | 114 | * @param obj The pwmout object |
hardtail | 4:49ee58dc8e4d | 115 | * @param ms The milisecond period |
hardtail | 4:49ee58dc8e4d | 116 | */ |
hardtail | 4:49ee58dc8e4d | 117 | void pwmout_all_period_ms(pwmout_all_t *obj, int ms); |
hardtail | 4:49ee58dc8e4d | 118 | |
hardtail | 4:49ee58dc8e4d | 119 | /** Set the PWM period specified in microseconds, keeping the duty cycle the same |
hardtail | 4:49ee58dc8e4d | 120 | * |
hardtail | 4:49ee58dc8e4d | 121 | * @param obj The pwmout object |
hardtail | 4:49ee58dc8e4d | 122 | * @param us The microsecond period |
hardtail | 4:49ee58dc8e4d | 123 | */ |
hardtail | 4:49ee58dc8e4d | 124 | void pwmout_all_period_us(pwmout_all_t *obj, int us); |
hardtail | 0:64b18a3829f1 | 125 | |
hardtail | 4:49ee58dc8e4d | 126 | /** Set the PWM pulsewidth specified in seconds, keeping the period the same. |
hardtail | 4:49ee58dc8e4d | 127 | * |
hardtail | 4:49ee58dc8e4d | 128 | * @param obj The pwmout object |
hardtail | 4:49ee58dc8e4d | 129 | * @param seconds The floating-point pulsewidth in seconds |
hardtail | 4:49ee58dc8e4d | 130 | */ |
hardtail | 4:49ee58dc8e4d | 131 | void pwmout_all_pulsewidth(pwmout_all_t *obj, float seconds); |
hardtail | 4:49ee58dc8e4d | 132 | |
hardtail | 4:49ee58dc8e4d | 133 | /** Set the PWM pulsewidth specified in miliseconds, keeping the period the same. |
hardtail | 4:49ee58dc8e4d | 134 | * |
hardtail | 4:49ee58dc8e4d | 135 | * @param obj The pwmout object |
hardtail | 4:49ee58dc8e4d | 136 | * @param ms The floating-point pulsewidth in miliseconds |
hardtail | 4:49ee58dc8e4d | 137 | */ |
hardtail | 4:49ee58dc8e4d | 138 | void pwmout_all_pulsewidth_ms(pwmout_all_t *obj, int ms); |
hardtail | 4:49ee58dc8e4d | 139 | |
hardtail | 4:49ee58dc8e4d | 140 | /** Set the PWM pulsewidth specified in microseconds, keeping the period the same. |
hardtail | 4:49ee58dc8e4d | 141 | * |
hardtail | 4:49ee58dc8e4d | 142 | * @param obj The pwmout object |
hardtail | 4:49ee58dc8e4d | 143 | * @param us The floating-point pulsewidth in microseconds |
hardtail | 4:49ee58dc8e4d | 144 | */ |
hardtail | 4:49ee58dc8e4d | 145 | void pwmout_all_pulsewidth_us(pwmout_all_t *obj, int us); |
hardtail | 4:49ee58dc8e4d | 146 | |
hardtail | 4:49ee58dc8e4d | 147 | /**@}*/ |
hardtail | 0:64b18a3829f1 | 148 | |
hardtail | 0:64b18a3829f1 | 149 | #ifdef __cplusplus |
hardtail | 0:64b18a3829f1 | 150 | } |
hardtail | 0:64b18a3829f1 | 151 | #endif |
hardtail | 0:64b18a3829f1 | 152 | |
hardtail | 0:64b18a3829f1 | 153 | |
hardtail | 0:64b18a3829f1 | 154 | #endif |