This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to output LFCLK or its multiples?

Hello,

I want to measure the frequency of 32.768k X'tal accurately.

I was able to output an external 32.768k X'tal to GPIO on a different CPU.  Is there such a way with nRF52840?

The frequency can be a multiple, not just 32.768k itself. I couldn't find any clock tree other than Figure.22 in nRF52840 ProductSpesification v1.7.

I couldn't get the relationship between timer and PWM time and LFCLK and its setting. Please tell me how to generate a GPIO signal frequency that has a clear relationship with LFCLK.


The ticket answers below will increase the capacitance of the XL2.

https://devzone.nordicsemi.com/f/nordic-q-a/1319/how-to-output-32768hz-external-crystal-lfclk-at-a-gpio-pin

To know the exact frequency, I need to measure without connecting anything to XL1,2.

Best Regards,

Yukio Oyama.

Parents
  • Hi

    It is possible to reflect the LF clock on a GPIO by using the TICK event in one of the RTC modules, and connect it to a GPIO through the PPI and GPIOTE peripherals. 

    In the most straight forward way this will only allow you to toggle a pin at half the frequency, since you need to toggle the pin twice to generate a pulse, but since you mention that multiples is OK perhaps this is acceptable?

    I have included a code snippet showing how to set this up:

        // Select 32 kHz clock source
        NRF_CLOCK->LFCLKSRC = CLOCK_LFCLKSRC_SRC_Xtal << CLOCK_LFCLKSRC_SRC_Pos;
        
        // Start the 32 kHz clock
        NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;
        NRF_CLOCK->TASKS_LFCLKSTART = 1;
        while(NRF_CLOCK->EVENTS_LFCLKSTARTED == 0);
    
        // Start the RTC, and enable the TICK event
        NRF_RTC0->EVTENSET = RTC_EVTENSET_TICK_Msk;
        NRF_RTC0->TASKS_START = 1;
        
        // Configure  the GPIOTE to control the output pin
        NRF_GPIOTE->CONFIG[0] = GPIOTE_CONFIG_MODE_Task       << GPIOTE_CONFIG_MODE_Pos     |
                                GPIOTE_CONFIG_POLARITY_Toggle << GPIOTE_CONFIG_POLARITY_Pos |
                                OUTPUT_PIN                    << GPIOTE_CONFIG_PSEL_Pos;
        
        // Connect the TICK event of the RTC to the output pin using the PPI and the GPIOTE
        NRF_PPI->CH[0].EEP = (uint32_t)&NRF_RTC0->EVENTS_TICK;
        NRF_PPI->CH[0].TEP = (uint32_t)&NRF_GPIOTE->TASKS_OUT[0];
        NRF_PPI->CHEN      = PPI_CHEN_CH0_Msk;

    Best regards
    Torbjørn

Reply
  • Hi

    It is possible to reflect the LF clock on a GPIO by using the TICK event in one of the RTC modules, and connect it to a GPIO through the PPI and GPIOTE peripherals. 

    In the most straight forward way this will only allow you to toggle a pin at half the frequency, since you need to toggle the pin twice to generate a pulse, but since you mention that multiples is OK perhaps this is acceptable?

    I have included a code snippet showing how to set this up:

        // Select 32 kHz clock source
        NRF_CLOCK->LFCLKSRC = CLOCK_LFCLKSRC_SRC_Xtal << CLOCK_LFCLKSRC_SRC_Pos;
        
        // Start the 32 kHz clock
        NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;
        NRF_CLOCK->TASKS_LFCLKSTART = 1;
        while(NRF_CLOCK->EVENTS_LFCLKSTARTED == 0);
    
        // Start the RTC, and enable the TICK event
        NRF_RTC0->EVTENSET = RTC_EVTENSET_TICK_Msk;
        NRF_RTC0->TASKS_START = 1;
        
        // Configure  the GPIOTE to control the output pin
        NRF_GPIOTE->CONFIG[0] = GPIOTE_CONFIG_MODE_Task       << GPIOTE_CONFIG_MODE_Pos     |
                                GPIOTE_CONFIG_POLARITY_Toggle << GPIOTE_CONFIG_POLARITY_Pos |
                                OUTPUT_PIN                    << GPIOTE_CONFIG_PSEL_Pos;
        
        // Connect the TICK event of the RTC to the output pin using the PPI and the GPIOTE
        NRF_PPI->CH[0].EEP = (uint32_t)&NRF_RTC0->EVENTS_TICK;
        NRF_PPI->CH[0].TEP = (uint32_t)&NRF_GPIOTE->TASKS_OUT[0];
        NRF_PPI->CHEN      = PPI_CHEN_CH0_Msk;

    Best regards
    Torbjørn

Children
No Data
Related