Hi,
I want to make a pulse for buzzer and led. I find a sample source(led.c) and the Nordic SDK. It is good enough in case posivie and negative duty is same. I need to set a differnt value for positive and negative duty. It is possible? If yes, please let me know.
The belows is my sample source.
#define BEEP_HW_OFF() \
NRF_GPIOTE->CONFIG[GPIOTE_CHANNEL_NUMBER] = (GPIOTE_CONFIG_MODE_Disabled << GPIOTE_CONFIG_MODE_Pos); \
NRF_TIMER1->TASKS_STOP = 1; \
nrf_gpio_pin_clear(BEEP_GPIO)
#define BEEP_HW_ON() \
nrf_gpio_cfg_output(BEEP_GPIO); \
beep_hw_init(); \
NRF_TIMER1->TASKS_START = 1
static void beep_hw_init(void)
{
uint32_t err_code;
// Configure PPI channel 0 to toggle ADVERTISING_LED_PIN_NO on every TIMER1 COMPARE[0] match
err_code = sd_ppi_channel_assign(PPI_CHAN0_TO_TOGGLE_BEEP,
&(NRF_TIMER1->EVENTS_COMPARE[0]),
&(NRF_GPIOTE->TASKS_OUT[GPIOTE_CHANNEL_NUMBER]));
APP_ERROR_CHECK(err_code);
// Enable PPI channel 0
err_code = sd_ppi_channel_enable_set(PPI_CHEN_CH0_Msk);
APP_ERROR_CHECK(err_code);
// Configure timer
NRF_TIMER1->MODE = TIMER_MODE_MODE_Timer;
NRF_TIMER1->BITMODE = TIMER_BITMODE_BITMODE_16Bit;
NRF_TIMER1->PRESCALER = TIMER_PRESCALER;
// Clear the timer
NRF_TIMER1->TASKS_CLEAR = 1;
// Load the value to TIMER1 CC0 register. The following value is calculated to generate
// a 2 Hz waveform that will serve as input to the LED
NRF_TIMER1->CC[0] = BEEP_INTENSITY_HIGH;
// Make the Capture Compare 0 event to clear the timer. This will restart the timer.
NRF_TIMER1->SHORTS = TIMER_SHORTS_COMPARE0_CLEAR_Enabled << TIMER_SHORTS_COMPARE0_CLEAR_Pos;
// There is no need to setup NRF_TIMER1->INTENSET register because the application do not need
// to wake up the CPU on Timer interrupts.
// Configure the GPIOTE Task to toggle the LED state.
nrf_gpiote_task_config(GPIOTE_CHANNEL_NUMBER,
BEEP_GPIO,
NRF_GPIOTE_POLARITY_TOGGLE,
NRF_GPIOTE_INITIAL_VALUE_HIGH);
}