I am developing a product using nRF52832. (S132, SDK 17, IAR8)
I am developing based on the ble_app_uart example.
I would like to add a basic PWM code to this example.
The added code is as follows.
static uint16_t seq_values;
void hv_init(void)
{
nrf_drv_pwm_config_t config0 =
{
.output_pins =
{
HV_PWM | NRF_DRV_PWM_PIN_INVERTED, // channel 0
NRF_DRV_PWM_PIN_NOT_USED, // channel 1
NRF_DRV_PWM_PIN_NOT_USED, // channel 2
NRF_DRV_PWM_PIN_NOT_USED, // channel 3
},
.irq_priority = APP_IRQ_PRIORITY_LOWEST,
.base_clock = NRF_PWM_CLK_125kHz,
.count_mode = NRF_PWM_MODE_UP,
.top_value = HV_FREQ_TOPVALUE(),
.load_mode = NRF_PWM_LOAD_COMMON,
.step_mode = NRF_PWM_STEP_AUTO
};
APP_ERROR_CHECK(nrf_drv_pwm_init(&m_pwm1, &config0, NULL));
seq_values = 0x8000 | (HV_FREQ_TOPVALUE()>>1);
}
void hv_duty_set(uint16_t duty)
{
uint32_t flag;
uint16_t playback_cnt;
uint16_t low_cnt;
if (duty>100) duty = 100;
if (duty == 0)
{
nrfx_pwm_stop(&m_pwm1, 100);
return;
}
nrf_pwm_sequence_t const seq =
{
.values.p_common = &seq_values,
.length = 1, //NRF_PWM_VALUES_LENGTH(seq_values),
.repeats = 0,
.end_delay = 0
};
if (duty == 100)
{
seq_values = 0x8000 | (HV_FREQ_TOPVALUE());
}
else
{
low_cnt = ((((uint32_t)HV_FREQ_TOPVALUE()) * duty * 10) / 1000);
seq_values = 0x8000 | (low_cnt);
}
flag = NRF_DRV_PWM_FLAG_LOOP | NRFX_PWM_FLAG_NO_EVT_FINISHED;
playback_cnt = 1;
(void)nrf_drv_pwm_simple_playback(&m_pwm1, &seq, playback_cnt, flag);
}
void main(void)
{
.....
.....
hv_init();
hv_duty_set(30);
....
....
while(1)
{
....
idle_state_handle();
}
}
The code above operates normally with the BLE.
After changing the base_clk of PWM to NRF_PWM_CLK_16MHz,
the PWM works, but the nRF52 connect app does not search my device.
I want the BLE to work, with the PWM operating at 16Mhz.
What should be fixed?
Thanks.