I made Pwm program with 3 channels without using softdevice and without using interrupts at that time it is working perfectly. But when i am trying to use softdevice with ppi as sd_ppi_xxxx my program is not working. I refered softdevice specification it says that to start using softdevice,the application initializes it with aclock source and pointer to an error handler. but i dont know what does it mean.can any one please explain with some examples.
my program is :
/*
- PWM channel program with softdevice ON */
#include <stdbool.h> #include <stdint.h> #include "nrf.h" #include "nrf_gpiote.h" #include "nrf_gpio.h" #include "s110/nrf_sdm.h"
#define PWM_1 (21) #define PWM_2 (22) #define PWM_3 (23)
#define TIMER_PRESCALERS 6U /**< Prescaler setting for timer. */
/*Function for handling timer 2 peripheral interrupts. / / Function for initializing the Timer 2 peripheral. */ static void timer2_init(void) { // Start 16 MHz crystal oscillator . NRF_CLOCK->EVENTS_HFCLKSTARTED = 0; NRF_CLOCK->TASKS_HFCLKSTART = 1;
// Wait for the external oscillator to start up.
while (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0);
NRF_TIMER2->MODE = TIMER_MODE_MODE_Timer;
NRF_TIMER2->BITMODE = TIMER_BITMODE_BITMODE_08Bit << TIMER_BITMODE_BITMODE_Pos;
NRF_TIMER2->PRESCALER = TIMER_PRESCALERS;
// Clears the timer, sets it to 0.
NRF_TIMER2->TASKS_CLEAR = 1;
// Load the initial values to TIMER2 CC registers.
NRF_TIMER2->CC[0] = 0;
NRF_TIMER2->CC[1] = 255;
NRF_TIMER2->CC[2] = 1;
NRF_TIMER2->CC[3] = 1;
}
/* Function for initializing the GPIO Tasks/Events peripheral. */ static void gpiote_init(void) { // Connect GPIO input buffers and configure PWM_OUTPUT_PIN_NUMBER as an output. //nrf_gpio_range_cfg_input(BUTTON_START, BUTTON_STOP, BUTTON_PULL); nrf_gpio_port_clear(NRF_GPIO_PORT_SELECT_PORT2, 0xFF);
nrf_gpio_cfg_output(PWM_1);
nrf_gpiote_task_config(0, PWM_1, \
NRF_GPIOTE_POLARITY_TOGGLE, NRF_GPIOTE_INITIAL_VALUE_LOW);
nrf_gpio_cfg_output(PWM_2);
nrf_gpiote_task_config(1, PWM_2, \
NRF_GPIOTE_POLARITY_TOGGLE, NRF_GPIOTE_INITIAL_VALUE_LOW);
nrf_gpio_cfg_output(PWM_3);
nrf_gpiote_task_config(2, PWM_3, \
NRF_GPIOTE_POLARITY_TOGGLE, NRF_GPIOTE_INITIAL_VALUE_LOW);
}
/* Function for initializing the Programmable Peripheral Interconnect peripheral. */ static void ppi_init(void) { sd_ppi_channel_assign(8,&NRF_TIMER2->EVENTS_COMPARE[0],&NRF_GPIOTE->TASKS_OUT[0]); sd_ppi_channel_enable_set(1 << 8); sd_ppi_channel_assign(9,&NRF_TIMER2->EVENTS_COMPARE[1],&NRF_GPIOTE->TASKS_OUT[0]); sd_ppi_channel_enable_set(1 << 9); sd_ppi_channel_assign(10,&NRF_TIMER2->EVENTS_COMPARE[0],&NRF_GPIOTE->TASKS_OUT[1]); sd_ppi_channel_enable_set(1 << 10); sd_ppi_channel_assign(11,&NRF_TIMER2->EVENTS_COMPARE[2],&NRF_GPIOTE->TASKS_OUT[1]); sd_ppi_channel_enable_set(1 << 11); sd_ppi_channel_assign(12,&NRF_TIMER2->EVENTS_COMPARE[0],&NRF_GPIOTE->TASKS_OUT[2]); sd_ppi_channel_enable_set(1 << 12); sd_ppi_channel_assign(13,&NRF_TIMER2->EVENTS_COMPARE[3],&NRF_GPIOTE->TASKS_OUT[2]); sd_ppi_channel_enable_set(1 << 13); } /*static void pwm_enable(uint32_t pwm_ch,uint32_t pwm_value) {
NRF_TIMER2->CC[pwm_ch] = pwm_value;
}*/
/*Function for application main entry. */
int main(void) { gpiote_init(); timer2_init();
ppi_init();
NRF_TIMER2->TASKS_START = 1; // Start the timer.
while (true);
}