| Posted: 02:24pm 26 Aug 2023 |
|
|
|
The most accurate way to measure low frequencies (up to 20kHz) is measuring the period. Using the picomite PIO allows for 44MHz tick (measurement resolution) at 133MHz CPUSPEED. When measuring 50Hz you would get near 1ppm (1:1000000) resolution.
This is how it is done:
'PIO frequency counter for PICOMITE MMBasic measuring period time
'this is a PIO program Dim a%(7)=(&h008400C5A029E020,&hE0408000A0CA0042,&h00C9008B004AA04A,&h8000A0C9,0,0,0,0)
'PIO configuration f=133e6 '133MHz PIO execution speed e=Pio(execctrl gp0,0,31) 'use gp0 for PIN...select the input pin
'program pio1 and start PIO program 1,a%() PIO init machine 1,0,f,0,e PIO start 1,0
'pio fifo register for reading information from PIO Dim x%(4)
'read the PIO time counted and convert to frequency Do PIO read 1,0,5,x%() 'read 5 count values, fifo + most recent period = x%(4) + 4 'counts measured + instructions PIO setup time Print f/(3*period);" Hz" 'convert counts to Hz and print Pause 1000 Loop While Inkey$=""
end
In line 8 (e=Pio(execctrl gp0,0,31)) you can assign any gpio pin of the pico. e=Pio(execctrl gp26,0,31) uses gp26 (pin 31).
Success...
Volhout
P.S. if you use a picomiteVGA, you better set f=126e6 since it runs at 126MHz. Edited 2023-08-27 00:33 by Volhout |