Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.
|
Forum Index : Microcontroller and PC projects : SetPin(GPnn), FIN query
Page 2 of 2 | |||||
Author | Message | ||||
phil99 Guru Joined: 11/02/2018 Location: AustraliaPosts: 2136 |
While waiting for Volhout's answer, you don't need the "other" pins. As noted in Volhout's post your program can read the same pins as the PIO - provided you aren't also using them for the PWM test signal, which you could move to other pins while developing your program. |
||||
carlschneider Senior Member Joined: 04/08/2023 Location: South AfricaPosts: 158 |
How about taking the reading and then PIO Stop 0,0 PIO Start 0,0 I notice that, even although Volhout has dropped the first result as noise and only used 3+latest, I'm also getting first result from PIO being noisy. To overcome this I do a dummy run of the PIO read and discard it. Hope this helps [Blind leading the blind here for sure :)] Cheers Carl Retirement is tough on Hobbies without a day job |
||||
carlschneider Senior Member Joined: 04/08/2023 Location: South AfricaPosts: 158 |
Or maybe use the PIO init to clear everything and then PIO start... Cheers Carl Retirement is tough on Hobbies without a day job |
||||
Chopperp Guru Joined: 03/01/2018 Location: AustraliaPosts: 1057 |
OK, thanks Phil Re-read the posts to see if I could make more sense of it. I had missed the bit where Volhout said that the PIO stuff could be assigned to any pin. I thought they were limited to GP0 & GP1 (On the standard 2040). I assigned the PIO to GP6 & GP8 & initially assigned these two pins to PIN (don't ask) as well. I was able to measure both the frequencies via the PIO & periods via PIN. Unfortunately, using PIN didn't work too good when the signal was disconnected so I tried FIN on both & that worked OK. The frequencies dropped to 0 when disconnected. I now do have a loss of input detector. Thanks again Brian EDIT. Bit slow for your relies Carl. Thanks. Had thought of those things. Might wait until Volhout replies Edited 2023-08-28 12:16 by Chopperp ChopperP |
||||
Volhout Guru Joined: 05/03/2018 Location: NetherlandsPosts: 4247 |
The PIO program fills the FIFO with results from edges of the input signal. When there are no edges, nothing will be put in FIFO. But unless FIFO is actively cleared, the old data remains. So there are 3 ways to solve this. 1 - let MMBasic monitor the pin as well, and see that there is no signal. '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) 'use MMBasic to detect input signal SetPin gp0,intl,INT_0 cnt%=0 'read counted time, average over 4, and convert to frequency Do If cnt%>0 Then PIO read 0,0,5,h%() period=(h%(1)+h%(2)+h%(3)+h%(4))/4 + 2 'skip h%(0) = rubbish frequency=f/(2*period) 'convert to the Hz Else frequency=0 EndIf Print frequency;" Hz" cnt%=0 Pause 1000 Loop While Inkey$="" End Sub INT_0 Inc cnt%,1 End Sub Note that is used an interrupt. Not the FIN function. Pico can only use the FIN at a limitted set of pins. The interrupt can be used at any pin. So whatever pin you choose. When frequencies are high the interrupt may mis some edged, but that is not important here. We only need to distinguish between 0 and non-zero. 2 - let the PIO indicate it has seen edges, by using a second pin as a status pin. MMBasic can use the pin to decide there is new data in FIFO. You can also attach a LED to that pin to signal there is input signal. 3 - make the PIO flush the FIFO. This is dangerous, since there is no indication whatever is in fifo is correct. And you have to STOP-INIT-START the PIO for it to work. But it can be done. Regards, Volhout Edited 2023-08-28 17:35 by Volhout PicomiteVGA PETSCII ROBOTS |
||||
carlschneider Senior Member Joined: 04/08/2023 Location: South AfricaPosts: 158 |
Hi Volhout Can you please confirm that you are using OPTION BASE 0. Cheers Carl Retirement is tough on Hobbies without a day job |
||||
Volhout Guru Joined: 05/03/2018 Location: NetherlandsPosts: 4247 |
Hi Carl, Yes, OPTION BASE 0 Otherwise you would have to skip h%(1) since it contains rubbish... The array h%(4) contains 5 values. h%(0),h%(1),h%(2),h%(3),h%(4) Each time you start the PIO, you could be in the middle of a 50Hz cycle, so the count of the first FIFO value h%(0) could be anything. h%(1), h%(2), h%(3) are valid values stored in the fifo (fifo size is 4 values) h%(4) is either - a new value that has been send to FIFO by the PIO during execution of the PIO READ command - when PIO does not send a new value, h%(4) contains a repeat of h%(3) (the last value read from fifo). Good question though... Volhout PicomiteVGA PETSCII ROBOTS |
||||
Volhout Guru Joined: 05/03/2018 Location: NetherlandsPosts: 4247 |
Carl, Just in case you are interested in building a universal counter (2 channel frequency, ratio, pulse, period, pause, etc..) here is a PIO core that does it. This is written for VGA picomite (uses PIO-1) so if you need it to run on PIO 0 you will have some work to do. It is WIP (work in progress) so the core functions work, but it does not have a GUI (user interface) yet. freq_counter13.zip It does not use the build in PIO assembler, since the build in PIO assembler cannot use .WRAP from one state machine in another state machines configuration. But it is commented quite extensively, so you should be able to understand what it does. If you are not interested, ignore this message. If you plan to make a GUI, let me know. Volhout PicomiteVGA PETSCII ROBOTS |
||||
Chopperp Guru Joined: 03/01/2018 Location: AustraliaPosts: 1057 |
Hi Volhout Thanks for the first method using the interrupt. Food for thought. My test set-up was already wired for GP6, GP7, GP8 & GP9 so I don't have any problems using any of them for FIN (at this stage). Keep up the great work Brian ChopperP |
||||
carlschneider Senior Member Joined: 04/08/2023 Location: South AfricaPosts: 158 |
I’m curious as to what else PIO1 is being used for and is the Dallas 1-wire driver in there too? Cheers Carl Retirement is tough on Hobbies without a day job |
||||
carlschneider Senior Member Joined: 04/08/2023 Location: South AfricaPosts: 158 |
Hi Volhout I am most definitely interested so I won’t ignore the message, however I’m currently sitting in Saskatoon with basically a laptop, a USB cable and a Pico W. When you say GUI does this include the possibility of a html page served by the Pico W? I am currently redoing a running ESP32 project back home using the Pico W, namely excess PV diversion to hot water storage, solar water heater controller and air tempering, from functional block memory. Part of the functionality is to review/set parameters through an html page which is what I’m currently eyeing. Ultimately I’m looking to do some remote control by writing modbus tcp registers in an SMA battery inverter triggered from the html page served by the Pico. Could this dev be leveraged into the GUI you seek? I have read your thread dealing with the PIO and it makes things a little clearer but will definitely require a few rereads before it sinks in. Certainly reminds me of programming in mnemonics then converting to binary and inputting on an 8080 using toggle switches. The whole board and switches mounted in a clear Perspex box, fondly referred to as Snow White and the seven dwarves, for I know not what reason. Sleeping beauty would have been more appropriate given the transparent box :) Thanks again for all your input and efforts, they are truly appreciated. Cheers Carl Retirement is tough on Hobbies without a day job |
||||
Volhout Guru Joined: 05/03/2018 Location: NetherlandsPosts: 4247 |
Hi Carl, The Webmite has the possibility to generate graphics on a shadow screen, and send that over html to a pc. So yes, it is possible.. But for a frequency counter you do not need graphics, numbers are all. Volhout PicomiteVGA PETSCII ROBOTS |
||||
Page 2 of 2 |
Print this page |