Hi.I use SDK12.2.I want to blink the RGB LED.so I use pwm.this is my code but it only bule color light on.does anyone know why?
#include <stdio.h>
#include <string.h>
#include "nrf_drv_pwm.h"
#include "app_util_platform.h"
#include "app_error.h"
#include "boards.h"
#include "bsp.h"
#include "app_timer.h"
#include "nrf_drv_clock.h"
#define NRF_LOG_MODULE_NAME "APP"
#include "nrf_log.h"
#include "nrf_log_ctrl.h"
#include <string.h>
#include "nrf_drv_pwm.h"
#include "app_util_platform.h"
#include "app_error.h"
#include "boards.h"
#include "bsp.h"
#include "app_timer.h"
#include "nrf_drv_clock.h"
#define NRF_LOG_MODULE_NAME "APP"
#include "nrf_log.h"
#include "nrf_log_ctrl.h"
#include "nrf_delay.h"
#define APP_TIMER_PRESCALER 0
#define APP_TIMER_OP_QUEUE_SIZE 2
#define APP_TIMER_OP_QUEUE_SIZE 2
int gLEDR = 10;
int gLEDG = 9;
int gLEDB = 8;
int gLEDG = 9;
int gLEDB = 8;
static nrf_drv_pwm_t m_pwm0 = NRF_DRV_PWM_INSTANCE(0);
static uint16_t const m_top = 10000;
static nrf_pwm_values_individual_t seq_values;
static nrf_pwm_sequence_t const seq =
{
.values.p_individual = &seq_values,
.length = NRF_PWM_VALUES_LENGTH(seq_values),
.repeats = 0,
.end_delay = 0
};
static nrf_pwm_sequence_t const seq =
{
.values.p_individual = &seq_values,
.length = NRF_PWM_VALUES_LENGTH(seq_values),
.repeats = 0,
.end_delay = 0
};
static void pwm_init(void)
{
uint32_t err_code;
nrf_drv_pwm_config_t const config0 =
{
.output_pins =
{
gLEDR | NRF_DRV_PWM_PIN_INVERTED,// channel 0
gLEDG | NRF_DRV_PWM_PIN_INVERTED,// channel 1
gLEDB | NRF_DRV_PWM_PIN_INVERTED, // channel 2
NRF_DRV_PWM_PIN_NOT_USED // channel 3
},
.irq_priority = APP_IRQ_PRIORITY_LOWEST,
.base_clock = NRF_PWM_CLK_4MHz,
.count_mode = NRF_PWM_MODE_UP,
.top_value = m_top,
.load_mode = NRF_PWM_LOAD_INDIVIDUAL,
.step_mode = NRF_PWM_STEP_AUTO
};
err_code = nrf_drv_pwm_init(&m_pwm0, &config0, NULL);
APP_ERROR_CHECK(err_code);
// m_used |= USED_PWM(0);
}
void update_pwm(int16_t dutyR, int16_t dutyG, int16_t dutyB)
{
seq_values.channel_0 = m_top-dutyR;
seq_values.channel_1 = m_top-dutyG;
seq_values.channel_2 = m_top-dutyB;
nrf_drv_pwm_simple_playback(&m_pwm0, &seq, 1, NRF_DRV_PWM_FLAG_LOOP);
}
{
seq_values.channel_0 = m_top-dutyR;
seq_values.channel_1 = m_top-dutyG;
seq_values.channel_2 = m_top-dutyB;
nrf_drv_pwm_simple_playback(&m_pwm0, &seq, 1, NRF_DRV_PWM_FLAG_LOOP);
}
int main(void)
{
pwm_init();
while(1){
{
pwm_init();
while(1){
for (int i=0; i<100; i++){
update_pwm(i*100,0,0);
nrf_delay_ms(1);
}
update_pwm(i*100,0,0);
nrf_delay_ms(1);
}
for (int i=0; i<100; i++){
update_pwm(10000,i*100,0);
nrf_delay_ms(1);
}
update_pwm(10000,i*100,0);
nrf_delay_ms(1);
}
for (int i=0; i<100; i++){
update_pwm(10000,10000,i*100);
nrf_delay_ms(1);
}
update_pwm(10000,10000,i*100);
nrf_delay_ms(1);
}
for (int i=100; i>0; i--){
update_pwm(i*100,10000,10000);
nrf_delay_ms(1);
}
update_pwm(i*100,10000,10000);
nrf_delay_ms(1);
}
for (int i=100; i>0; i--){
update_pwm(0,i*100,10000);
nrf_delay_ms(1);
}
update_pwm(0,i*100,10000);
nrf_delay_ms(1);
}
for (int i=100; i>0; i--){
update_pwm(0,0,i*100);
nrf_delay_ms(1);
}
update_pwm(0,0,i*100);
nrf_delay_ms(1);
}
update_pwm(0,0,0);
nrf_delay_ms(200);
}
}
/**/
nrf_delay_ms(200);
}
}
/**/