drivers: pwm: pwm_nrf5_sw: Add prescaler support
Add support for specifying the clock prescaler value for the HF timer used for generating the PWM signals. This allows for lower timer frequency and thus slower PWM signals (e.g. for use as servo controller). Signed-off-by: Henrik Brix Andersen <henrik@brixandersen.dk>
This commit is contained in:
parent
f5310d5b54
commit
fc1898ccb5
2 changed files with 29 additions and 4 deletions
|
@ -15,10 +15,33 @@ menuconfig PWM_NRF5_SW
|
|||
This implementation provides up to 3 pins using one HF timer, two PPI
|
||||
channels per pin and one GPIOTE config per pin.
|
||||
|
||||
if PWM_NRF5_SW
|
||||
|
||||
config PWM_NRF5_SW_0_DEV_NAME
|
||||
string "Nordic Semiconductor nRF5x series S/W PWM Device Name"
|
||||
depends on PWM_NRF5_SW
|
||||
default "PWM_0"
|
||||
help
|
||||
Specify the device name for the Nordic Semiconductor nRF5x series S/W
|
||||
PWM driver.
|
||||
|
||||
config PWM_NRF5_SW_0_CLOCK_PRESCALER
|
||||
int
|
||||
prompt "Nordic Semiconductor nRF5x series S/W PWM Clock Prescaler"
|
||||
default 0
|
||||
range 0 9
|
||||
help
|
||||
Set the clock prescaler for the timer used for generating
|
||||
the PWM output signals. Prescaler values correspond to the
|
||||
following timer frequencies:
|
||||
0: 16 MHz
|
||||
1: 8 MHz
|
||||
2: 4 MHz
|
||||
3: 2 MHz
|
||||
4: 1 MHz
|
||||
5: 500 kHz
|
||||
6: 250 kHz
|
||||
7: 125 kHz
|
||||
8: 62500 Hz
|
||||
9: 31250 Hz
|
||||
|
||||
endif
|
||||
|
|
|
@ -17,6 +17,7 @@ struct pwm_config {
|
|||
u8_t gpiote_base;
|
||||
u8_t ppi_base;
|
||||
u8_t map_size;
|
||||
u8_t prescaler;
|
||||
};
|
||||
|
||||
struct chan_map {
|
||||
|
@ -143,7 +144,7 @@ static int pwm_nrf5_sw_pin_set(struct device *dev, u32_t pwm,
|
|||
|
||||
/* setup HF timer in 16MHz frequency */
|
||||
timer->MODE = TIMER_MODE_MODE_Timer;
|
||||
timer->PRESCALER = 0;
|
||||
timer->PRESCALER = config->prescaler;
|
||||
timer->BITMODE = TIMER_BITMODE_BITMODE_16Bit;
|
||||
timer->EVENTS_COMPARE[channel] = 0;
|
||||
timer->EVENTS_COMPARE[config->map_size] = 0;
|
||||
|
@ -207,8 +208,8 @@ static int pwm_nrf5_sw_get_cycles_per_sec(struct device *dev, u32_t pwm,
|
|||
|
||||
config = (struct pwm_config *)dev->config->config_info;
|
||||
|
||||
/* HF timer frequency is derived from 16MHz source and prescaler is 0 */
|
||||
*cycles = 16000000UL;
|
||||
/* HF timer frequency is derived from 16MHz source with a prescaler */
|
||||
*cycles = 16000000UL / BIT(config->prescaler);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -242,6 +243,7 @@ static const struct pwm_config pwm_nrf5_sw_0_config = {
|
|||
#endif
|
||||
.gpiote_base = 0,
|
||||
.map_size = PWM_0_MAP_SIZE,
|
||||
.prescaler = CONFIG_PWM_NRF5_SW_0_CLOCK_PRESCALER,
|
||||
};
|
||||
|
||||
#define PWM_0_DATA_SIZE (offsetof(struct pwm_data, map) + \
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue