This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

pwm with use of timer and ppi

hi its not working as i want . y is that?

first step i try to toggle just with one cc that is the code below

with changing of NRF_TIMER2->CC[0] = 65536;nothing happend there is no difrence in changing it

y is that?

    nrf_gpio_cfg_output(PWM_OUTPUT_PIN_NUMBER);
    // Configure GPIOTE channel 0 to toggle the PWM pin state
    // @note Only one GPIOTE task can be connected to an output pin.
    nrf_gpiote_task_config(0, PWM_OUTPUT_PIN_NUMBER, \
                           NRF_GPIOTE_POLARITY_TOGGLE, NRF_GPIOTE_INITIAL_VALUE_LOW);

   // Configure PPI channel 0 to toggle PWM_OUTPUT_PIN on every TIMER2 COMPARE[0] match.
    NRF_PPI->CH[0].EEP = (uint32_t)&NRF_TIMER2->EVENTS_COMPARE[0];
    NRF_PPI->CH[0].TEP = (uint32_t)&NRF_GPIOTE->TASKS_OUT[0];


    // Enable PPI channels 0-2.
    NRF_PPI->CHEN = (PPI_CHEN_CH0_Enabled << PPI_CHEN_CH0_Pos);


    // 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) 
    {
        //Do nothing.
    }

    NRF_TIMER2->MODE      = TIMER_MODE_MODE_Timer;
    NRF_TIMER2->BITMODE   = TIMER_BITMODE_BITMODE_16Bit << 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] = 65536;


    // Interrupt setup.
    NRF_TIMER2->INTENSET = (TIMER_INTENSET_COMPARE0_Enabled << TIMER_INTENSET_COMPARE0_Pos);


void TIMER2_IRQHandler(void)
{
    static bool cc0_turn = false; /**< Keeps track of which CC register to be used. */

    if ((NRF_TIMER2->EVENTS_COMPARE[0] != 0) && 
       ((NRF_TIMER2->INTENSET & TIMER_INTENSET_COMPARE0_Msk) != 0))
    {
			//NRF_TIMER2->TASKS_CLEAR = 1;
		}
}
Parents
  • Hi

    First question: Would you want to use app_pwm library instead of generating the PWM manually. The app_pwm internally uses TIMER+PPI+GPIOTE to generate the PWM. Valid from SDK 10.0.0. There is an example in the SDK.

  • I would encourage you to copy the PWM library from SDK 10 or SDK 11 into your project. There was an ongoing attempt from us and other develoopers to generate reliable PWM for nRF51, but we eventually got it right in SDK 10.0.0. I would discourage you to do PWM manually, but rather try to use the PWM library from SDK 10/11 with your SDK 6 project. Just realize what peripherals you are using with the SDK 10/11 pwm library and avoid use those with other SDK 6 modules.

Reply
  • I would encourage you to copy the PWM library from SDK 10 or SDK 11 into your project. There was an ongoing attempt from us and other develoopers to generate reliable PWM for nRF51, but we eventually got it right in SDK 10.0.0. I would discourage you to do PWM manually, but rather try to use the PWM library from SDK 10/11 with your SDK 6 project. Just realize what peripherals you are using with the SDK 10/11 pwm library and avoid use those with other SDK 6 modules.

Children
No Data