| Posted: 07:39am 27 Aug 2023 |
|
|
|
Hi Carl,
At time of writing, the picomite did not have a build in assembler for PIO. It has now. And this is the same program when using the build in assembler. When assembling it immediately writes the program into memory.
'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. PIO assemble 0,".program period" PIO assemble 0,".line 0" pio assemble 0,".wrap target" PIO assemble 0,"mov X,!null" PIO assemble 0,"posloop:" PIO assemble 0,"jmp pin negloop" PIO assemble 0,"jmp x-- posloop" PIO assemble 0,"negloop:" PIO assemble 0,"jmp x-- next" PIO assemble 0,"next:" PIO assemble 0,"jmp pin negloop" PIO assemble 0,"mov isr ,!x" PIO assemble 0,"push noblock" pio assemble 0,".wrap" PIO assemble 0,".end program list"
'configure pio0 e=Pio(execctrl gp0,pio(.wrap target),pio(.wrap)) 'use gp0 for PIN f=133e6 '133MHz @ 2 instr per loop
'program pio0 and start 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$="" End
I hope this helps...
Volhout Edited 2023-08-27 18:05 by Volhout |