Hello,
ncs1.5.0
As shown in the question,
I use rtc to generate a 1kHz square wave, and use an oscilloscope to measure only 964 Hz.
Is there a problem with where I set it? Attached is my code. Thank you for your help.
Hello,
ncs1.5.0
As shown in the question,
I use rtc to generate a 1kHz square wave, and use an oscilloscope to measure only 964 Hz.
Is there a problem with where I set it? Attached is my code. Thank you for your help.
Hello,
The RTC runs off the 32768 Hz low frequency clock so you will not be able to output exactly 1000 Hz, but around 993 Hz should be possible (~33 ticks with 0 prescaler). Would that be close enough, or must it be 1000 Hz? Otherwise you will have to consider the TIMER peripheral which has a higher run current TIMER running
hi,
Thans for your quick response.
I need to test the low frequency clock, 36 Hz deviation is a bit far from what I expected.
Yes, I agree that 36 Hz seems a bit much. I suspect it may be have to do with how the compare register is being updated for every compare event. Are you familiar with the DPPI peripheral on the device? I think a better option could be to use RTC + DPPI + GPIOTE to toggle the pin without CPU involvment.
Some references you may find useful:
- https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/samples/boards/nrf/nrfx/README.html - Working with nRFX drivers in Zephyr
- DPPI - Distributed programmable peripheral interconnect
*Update*
I was forgetting that the input frequency had to be 2 times the output frequency, which effectively increases the division error. Sorry for the confusion.
Closest you can get to 2000 Hz is ~1927 Hz. Which, if you divide by 2, is 963.7 Hz. In the code you uploaded earlier, please try to set the timeout to 488 uS instead of 500 uS. Did should give you a 1024 Hz output signal.
Hi,
Thank you for your response.
But why am I changing it to 488 us? I am confused. I am measuring the external crystal oscillator not just to get a 1khz square wave.
Hi,
You should select an frequency that's a power of 2 (i.e., 1024,2048,4096..) to avoid deviation due to division errors like you first saw with 2000/1000 Hz if the goal is to test the accuracy of your crystal.
488us will result in an RTC compare event frequency of exactly 2048 Hz instead of the 1927 Hz you got when the desired frequency was 2000 Hz.