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

NRF51822 generate pulse with GPIO

I am trying to use NRF51822 GPIO to generate a pulse with max width of 0.3us. According to other tickets in the forum and the product spec, NRF51822 should be able to generate a 50% duty PWM with 8MHz, which means a single pulse width with 0.125us. But the shortest pulse I could get is 0.36us. Please help to check what is wrong with my setup.

I am using the standard GPIO configuration code as

nrf_gpio_cfg_output(PIN_NUM);

And for testing the pulse generation, I just use a simple while loop and toggling the GPIO as:

uint32_t* addrPinSet = (uint32_t*) 0x50000508;
uint32_t* addrPinClr = (uint32_t*) 0x5000050C;
while(true){
	*addrPinSet = PIN_MASK;
	*addrPinClr = PIN_MASK;
}
Parents
  • If you go look at the assembly code that generates I suspect you'll find that the loop is about 6 instructions long. 6/16,000,000 = 3.75us. Toggling the pin like that isn't going to work, you need PPI.

    One line of C != one assembly instruction

    oh and try optimisation, but put

    uint32_t volatile * addrPinSet .. 
    

    to stop the loop getting optimized out (or use the proper CMSIS macros)

  • This makes sense. So the assembly looks like this:

    117       	*addrPinClr = PIN_MASK;
    000213be:   ldr     r3, [r7, #8]
    000213c0:   movs    r2, #128        ; 0x80
    000213c2:   lsls    r2, r2, #9
    000213c4:   str     r2, [r3, #0]
    118       	*addrPinSet = PIN_MASK;
    000213c6:   ldr     r3, [r7, #12]
    000213c8:   movs    r2, #128        ; 0x80
    000213ca:   lsls    r2, r2, #9
    000213cc:   str     r2, [r3, #0]
    

    Haven't got any good idea that how to generate a single pulse with PPI. Any suggestions?

Reply
  • This makes sense. So the assembly looks like this:

    117       	*addrPinClr = PIN_MASK;
    000213be:   ldr     r3, [r7, #8]
    000213c0:   movs    r2, #128        ; 0x80
    000213c2:   lsls    r2, r2, #9
    000213c4:   str     r2, [r3, #0]
    118       	*addrPinSet = PIN_MASK;
    000213c6:   ldr     r3, [r7, #12]
    000213c8:   movs    r2, #128        ; 0x80
    000213ca:   lsls    r2, r2, #9
    000213cc:   str     r2, [r3, #0]
    

    Haven't got any good idea that how to generate a single pulse with PPI. Any suggestions?

Children
No Data
Related