nRF51822 : Timer capture and PWM generation with softdevice

Hello,

I have been developing some products over the nRF51822 BLE. Got my introduction with nRF about 2 months back and despite the steep learning curve I was able to integrate the softdevice with LESC passkey and some GPIO peripheral control for a BLE Lock product. NRF team has been a GREAT HELP.

Now I want to add one more peripheral that is a 125KHz RFID card reader. I have figured out the hardware for the same. It basically fires a 125KHz to the coil and depending on the load from RFID card, a data stream of one and zero is received from a comparator. 

Refer this link https://www.serasidis.gr/circuits/RFID_reader/125kHz_RFID_reader.htm

I basically want to integrate this using the nordic mcu.

I figured out the PWM output using the app__pwm example. I am a bit stuck on capturing the waveform. I get that I have to start the timer in counter mode triggered by one GPIO but I am not able to do this along with the softdevice running in parellel.

Please let me know of any literature available or any example for the same.

What I had done so far : 

1. BLE stack along with peer manager is working perfectly

2. A couple of notify and write characteristics are available to take care of the peripherals.

3. I have used two timers so far, one for the SD and one 100ms to do all my control related tasks.

4. I was able to generate a 125KHz PWM on one GPIO.

What I need to do : 

To capture the pulses on one GPIO (pin P0.07 in my case). How I perceive this is that I can make an array to store the capture values and then process it any time. Let me know if I am looking at this in a wrong way.

Peripherals used so far : 

/*****/control task timmer
APP_TIMER_INIT(0, 4, false);
    err_code = app_timer_create(&m_control_timer_id,
                                APP_TIMER_MODE_REPEATED,
                                control_timeout_handler);
    err_code = app_timer_start(m_control_timer_id, APP_TIMER_TICKS(100, 0), NULL);

/*****/peer manager timer
    uint32_t err_code = app_timer_create(&m_sec_req_timer_id,
                            APP_TIMER_MODE_SINGLE_SHOT,
    err_code = app_timer_start(m_sec_req_timer_id, SECURITY_REQUEST_DELAY, NULL);
                            sec_req_timeout_handler);

/*****/pwm output
    app_pwm_config_t pwm1_cfg = APP_PWM_DEFAULT_CONFIG_1CH(8L, MCU1); // 125KHz on MCU1 pin
    err_code = app_pwm_init(&PWM1,&pwm1_cfg,NULL);
    APP_ERROR_CHECK(err_code);
    app_pwm_enable(&PWM1);
    app_pwm_channel_duty_set(&PWM1, 0, 50); //set initial duty as zero (instanct, channel, !duty)

/*****/general GPIOs on about 6 pins that are handled accross the code.

I also got to know about the PPI+timer+gpiote method but I was not able to get it running.

Also for me power consumption is very critical since it is a battery operated device. Any extra hardware uses a lot of power as I observed so I want to make it very minimal.(< 0.5mA total during idle operation).

Thanks & Regards

Parents Reply Children
  • So as I said, I am using one timer for control purpose i.e. a 100ms generic timer interrupt and one APP_PWM to generate the 125KHz pulse.

    void pwm_init()
    {
    uint32_t err_code;
    app_pwm_config_t pwm1_cfg = APP_PWM_DEFAULT_CONFIG_1CH(8L, MCU1); // 125KHz on MCU1 pin
    err_code = app_pwm_init(&PWM1,&pwm1_cfg,NULL);
    APP_ERROR_CHECK(err_code);
    app_pwm_enable(&PWM1);
    app_pwm_channel_duty_set(&PWM1, 0, 100); //set initial duty as zero (instanct, channel, !duty)
    }
    
    void control_timer_init()
    {
    APP_TIMER_INIT(0, 4, false);
    err_code = app_timer_create(&m_control_timer_id,
    APP_TIMER_MODE_REPEATED,
    control_timeout_handler);
    err_code = app_timer_start(m_control_timer_id, TIMER_INTERVAL, NULL);
    }

    Now I am not sure what timer do either of these use since APP_PWM and APP_TIMER are handled internally.

    To re-iterate what I want to do : 

    1. Use the softdevice and peer manager for BLE.

    2. One 125KHz pulse.

    3. One generic timer for control part (50 - 100msec).

    4. A method to measure incoming pulse width.

  • Hi,

    app_timer uses RTC. But app_pwm will use a TIMER instance.

    There are 3 TIMER instances on the nRF51.

    Softdevice uses TIMER0, so 2 timers left for the application.

    app_pwm uses 1, and timer_init() code uses 2(m_timer_count and m_timer_read).

    Maybe you can try to remove m_timer_read, and use e.g an app_timer to trigger the reading of m_timer_count instead.

  • So I tried a lot with many permutation and combinations but this does not seem to work.

    I deleted the timer2 from code and started reading on the main loop for the timer capture values but nothing seem to work.

    I guess I am overkilling the nordic capabilities. A BLE stack along with PWM generation and capture feature looks like too demanding for the controller.

    Is there any other series that may solve this or I am lagging on the approach of the problem?

  • shwetank vishnu said:
    Is there any other series that may solve this or I am lagging on the approach of the problem?

    With e.g.the nRF52832 you have a dedicated PWM peripheral, and 5 TIMERS. 

    shwetank vishnu said:
    and started reading on the main loop for the timer capture values but nothing seem to work.

    It would be better to read it from e.g. an app_timer handler that triggers/expires at a fixed interval. E.g. read it every 2 second. 

    https://devzone.nordicsemi.com/guides/short-range-guides/b/software-development-kit/posts/application-timer-tutorial

Related