| Posted: 07:08pm 26 Aug 2023 |
|
|
|
Simplified and improved, and for PIO 0 on the webmite..
Note that the result accuracy is depending on the accuracy of the crystal on the pico.
'PIO frequency counter for PICOMITE MMBasic
'PIO program 'this PIO program samples the GPx pin for edges in 2 loops 'that are 2 instructions per loop so the resulting count is in 'ticks that are 2/f seconds. Each GPx period is 2 instructions off. Dim a%(7)=(&h0044004100c3a02b,&h8020a0c900c3,0,0,0,0,0,0)
'configure pio1 e=Pio(execctrl gp0,0,6) 'use gp0 for PIN f=133e6 '133MHz @ 2 instr per loop
'program pio0 and start PIO program 0,a%() PIO init machine 0,0,f,0,e PIO start 0,0
'pio fifo register Dim h%(4)
'read counted time, average over 4, and convert to frequency Do PIO read 0,0,5,h%() period=(h%(1)+h%(2)+h%(3)+h%(4))/4 + 2 'skip h%(0) = rubbish 'correct loop delay Print f/(2*period);" Hz" 'convert to the Hz Pause 1000 Loop While Inkey$="" PIO stop 0,0 End
Edited 2023-08-27 05:28 by Volhout |