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

Using Optimisation in nrf51 Keil

Hi, I have the following piece of code.

nrf_gpio_cfg_output(PIN_EN_BSTR);

for(int i=0;i<300;i++)

{

	nrf_gpio_pin_clear(PIN_EN_BSTR);

	__NOP();

	__NOP();

	__NOP();

	__NOP();

	__NOP();

	__NOP();

	__NOP();

	__NOP();

	__NOP();

	__NOP();	

	nrf_gpio_pin_set(PIN_EN_BSTR);

	nrf_delay_us(100);

}

nrf_gpio_pin_clear(PIN_EN_BSTR);

With Optimisation level O0, the off time is 2usec and with O3, the off time is 1.4usec. Will __NOPs have different cycle time for different optimisation levels? I thought they should be the same? Thanks.

Parents
  • __NOP() can be optimized by compiler, instead use inline assembly instructions that you can find in nrf_delay.h

      __ASM volatile (
           " NOP\n\t"
           " NOP\n\t"
           " NOP\n\t"
           " NOP\n\t"
           " NOP\n\t"
           " NOP\n\t"
           " NOP\n\t"
           " NOP\n\t"
           " NOP\n\t"
           " NOP\n\t");
    

    Inline assembly is not optimized.

  • Thanks Aryan. Bascally I am looking for a code where I can do PWM of a gpio pin with on period (1usec) and off period as 100usec : The main point would be the on and off time of PWM should be the same for all optimisation levels, O0 to O3. Thanks

Reply
  • Thanks Aryan. Bascally I am looking for a code where I can do PWM of a gpio pin with on period (1usec) and off period as 100usec : The main point would be the on and off time of PWM should be the same for all optimisation levels, O0 to O3. Thanks

Children
No Data