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

pulse generation

Hello, I work with some ADC 24-bit (HX711) and for getting data from that I need after low level on first gpio pin to fed 26 pulses to that with time period about 1us on second gpio pin and simultaneously getting data on first gpio pin.

For detect low level on first pin I use gpiote interrupt (there I start the timer)

I thought about easiest way to generate signal with freq about 1Mhz.

I try to use function from timer example for generating such a signal:

nrf_drv_timer_extended_compare( &TIMER_LED, NRF_TIMER_CC_CHANNEL0, 1, NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, true);

and in timer_handler I toggling pin - but it's only 131kHz maximum

  • Hi,

    For generating a fixed number of pulses, I suggested using the PWM driver(nRF52 only).

    Here is a function called generate_pulse_1mhz(uint16_t pulses,uint8_t pin_number), it takes the number of 1 Mhz pulses you want to generate and the output pin number. When called it will output the desired number of pulses on the pin specified.

    static nrf_drv_pwm_t m_pwm0 = NRF_DRV_PWM_INSTANCE(0);
    
    static void generate_pulse_1mhz(uint16_t pulses,uint8_t pin_number)
    {
        uint32_t err_code;
        nrf_drv_pwm_config_t const config0 =
        {
            .output_pins =
            {
                pin_number,                           // channel 0
                NRF_DRV_PWM_PIN_NOT_USED,             // channel 1
                NRF_DRV_PWM_PIN_NOT_USED,             // channel 2
                NRF_DRV_PWM_PIN_NOT_USED,             // channel 3
            },
            .irq_priority = APP_IRQ_PRIORITY_HIGH,
            .base_clock   = NRF_PWM_CLK_2MHz,
            .count_mode   = NRF_PWM_MODE_UP,
            .top_value    = 2,
            .load_mode    = NRF_PWM_LOAD_COMMON,
            .step_mode    = NRF_PWM_STEP_AUTO
        };
        err_code = nrf_drv_pwm_init(&m_pwm0, &config0, NULL);
        APP_ERROR_CHECK(err_code);
        
        static uint16_t /*const*/ seq_values[] ={1};
        
        nrf_pwm_sequence_t const seq =
        {
            .values.p_common = seq_values,
            .length          = NRF_PWM_VALUES_LENGTH(seq_values),
            .repeats         = 0,
            .end_delay       = 0
        };
        
        nrf_drv_pwm_simple_playback(&m_pwm0, &seq, pulses,  NRF_DRV_PWM_FLAG_STOP);
    }
    
  • Thank you. This function is works for me. The following task would be to start this pulse sequince after trigger low level on other pin. But I think it's not correct to call this whole function from gpiote event handle?! I know the best way would be to use PPI, but I never used it before

  • Yes, you dont need to call the whole function. How often do you need the function? You could split a large part of the code into a init-part, and then call the nrf_drv_pwm_simple_playback in the event handler. If you use the function very often it could be worth looking into using PPI. Here is a post on that.

  • Thanks. I have some problem with triggering pwm sequence task by ppi here is my question devzone.nordicsemi.com/.../

Related