- 易迪拓培训,专注于微波、射频、天线设计工程师的培养
NRF52832的PWM使用寄存器按照手册来的,配置出来没得波形
录入:edatop.com 点击:
配置的代码如下
uint16_t pwm_seq[2] = {1500, 1500};
void pwmInit(void)
{
nrf_gpio_cfg_output(MOTO1_Pin);
nrf_gpio_cfg_output(MOTO2_Pin);
nrf_gpio_cfg_output(MOTO3_Pin);
nrf_gpio_cfg_output(MOTO4_Pin);
NRF_PWM0->PSEL.OUT[0] = (MOTO1_Pin << PWM_PSEL_OUT_PIN_Pos) | (PWM_PSEL_OUT_CONNECT_Connected
<< PWM_PSEL_OUT_CONNECT_Pos);
NRF_PWM0->PSEL.OUT[1] = (MOTO4_Pin << PWM_PSEL_OUT_PIN_Pos) | (PWM_PSEL_OUT_CONNECT_Connected
<< PWM_PSEL_OUT_CONNECT_Pos);
NRF_PWM0->ENABLE = (PWM_ENABLE_ENABLE_Enabled << PWM_ENABLE_ENABLE_Pos);
NRF_PWM0->MODE = (PWM_MODE_UPDOWN_Up << PWM_MODE_UPDOWN_Pos);
NRF_PWM0->PRESCALER = (PWM_PRESCALER_PRESCALER_div_16 <<PWM_PRESCALER_PRESCALER_Pos);
NRF_PWM0->COUNTERTOP = (2000 << PWM_COUNTERTOP_COUNTERTOP_Pos); //1 msec
NRF_PWM0->LOOP = (PWM_LOOP_CNT_Msk << PWM_LOOP_CNT_Pos);
NRF_PWM0->DECODER = (PWM_DECODER_LOAD_Individual << PWM_DECODER_LOAD_Pos) |
(PWM_DECODER_MODE_RefreshCount << PWM_DECODER_MODE_Pos);
NRF_PWM0->SEQ[0].PTR = ((uint32_t)(pwm_seq) << PWM_SEQ_PTR_PTR_Pos);
NRF_PWM0->SEQ[0].CNT = ((sizeof(pwm_seq) / sizeof(uint16_t)) <<PWM_SEQ_CNT_CNT_Pos);
NRF_PWM0->SEQ[0].REFRESH = 0;
NRF_PWM0->SEQ[0].ENDDELAY = 0;
NRF_PWM0->TASKS_SEQSTART[0] = 1;
}
各位看到的朋友们请出分力吧!
uint16_t pwm_seq[2] = {1500, 1500};
void pwmInit(void)
{
nrf_gpio_cfg_output(MOTO1_Pin);
nrf_gpio_cfg_output(MOTO2_Pin);
nrf_gpio_cfg_output(MOTO3_Pin);
nrf_gpio_cfg_output(MOTO4_Pin);
NRF_PWM0->PSEL.OUT[0] = (MOTO1_Pin << PWM_PSEL_OUT_PIN_Pos) | (PWM_PSEL_OUT_CONNECT_Connected
<< PWM_PSEL_OUT_CONNECT_Pos);
NRF_PWM0->PSEL.OUT[1] = (MOTO4_Pin << PWM_PSEL_OUT_PIN_Pos) | (PWM_PSEL_OUT_CONNECT_Connected
<< PWM_PSEL_OUT_CONNECT_Pos);
NRF_PWM0->ENABLE = (PWM_ENABLE_ENABLE_Enabled << PWM_ENABLE_ENABLE_Pos);
NRF_PWM0->MODE = (PWM_MODE_UPDOWN_Up << PWM_MODE_UPDOWN_Pos);
NRF_PWM0->PRESCALER = (PWM_PRESCALER_PRESCALER_div_16 <<PWM_PRESCALER_PRESCALER_Pos);
NRF_PWM0->COUNTERTOP = (2000 << PWM_COUNTERTOP_COUNTERTOP_Pos); //1 msec
NRF_PWM0->LOOP = (PWM_LOOP_CNT_Msk << PWM_LOOP_CNT_Pos);
NRF_PWM0->DECODER = (PWM_DECODER_LOAD_Individual << PWM_DECODER_LOAD_Pos) |
(PWM_DECODER_MODE_RefreshCount << PWM_DECODER_MODE_Pos);
NRF_PWM0->SEQ[0].PTR = ((uint32_t)(pwm_seq) << PWM_SEQ_PTR_PTR_Pos);
NRF_PWM0->SEQ[0].CNT = ((sizeof(pwm_seq) / sizeof(uint16_t)) <<PWM_SEQ_CNT_CNT_Pos);
NRF_PWM0->SEQ[0].REFRESH = 0;
NRF_PWM0->SEQ[0].ENDDELAY = 0;
NRF_PWM0->TASKS_SEQSTART[0] = 1;
}
各位看到的朋友们请出分力吧!
东莞智洛创提供代烧录:客户只需要提供物料,烧录+编带,整个过程全自动化,卷装料来卷装料回,烧录所有核心部件都是自主研发,效率和品质在国内处于领先,目前NORDIC 和TI的蓝牙IC 日生产能力为500K/天。刘经理 18922813960