Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 19:03 19 Apr 2024 Privacy Policy
Jump to

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 : revisit picomite PIO - measure period

Author Message
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 3496
Posted: 07:17am 12 May 2022
Copy link to clipboard 
Print this post

In the early days of picomite development, I played with the PIO inside the picomite.
After some initial investigations, I dropped the topic, in favour of other picomite functions.

Now, after a year, I wanted to pick it up again, and found my knowledge was very rusty.
I did not even know how to assemble (compile) the code, tried using PASM12a (Mixtel90).

After a lot of "aha"'s I finally have something working, and I wanted to share it with you.
Maybe it may serve others to shorten their introduction to PIO.

This program uses the PIO to measure period (1/frequency) of an incoming signal. To achieve this it uses the "JMP PIN" PIO instruction. You can assign any of the 32 GPIO pins to this instruction. The PIN does not have to be in the SET PIN map, it is completely independent of the PINCTRL settings. It can also be a pin the is connected to an internal PWM (as shown in the example).

To test the measurement function, the PIO is measuring the frequency of GP0 that is driven from a PWM running at 1kHz.

The register adresses used (&h503000xx) refer to PIO 1. Similar use &h502000xx when using PIO 0).

I hope this is of some benefit to others.

'PIO measure period - this works !!!
'The program uses a PMW output to generate a test frequency, just to test the function
'the PIO (PIO1 sequencer 0 in this example) measures the period (1/frequency) of the incomming signal at GPx
'the signal must be logic level. For this example the sequencer runs at 1MHz, gives a 500kHz (2us) resolution
'of the measured clock.

'generate 1khz test tone on GP0
SetPin gp0,pwm0a
PWM 0,1000,50

' PIO1 program, measure period on GPx (depends on PIN setting EXECCTRL register)
' the period is 2*TC*(count+3), where TC= PIO clock frequency
'
'0 set x 0        E020 clear X
'1 mov x -x       A029 change X to -1 (ffffffff)
'2 jmp pin 4      00C4 when pin=1 goto count loop 2
'3 jmp x-- 2      0042 count loop 1 (while PIN=low)
'4 jmp x-- 5      0045 count loop 2 (while PIN=high)
'5 jmp pin 4      00C4
'6 mov -x isr     A0C9 finished counting, move X to shift register
'7 push noblock   8000 and push shif register to FIFO
'8 jmp always 0   0000 in future may be replaced by .wrap
'
Dim a%(7)=(&h004200c4a029E020,&h8000a0c900c40045,0,0,0,0,0,0)

SetPin gp1,pio1  'not sure if this is needed

'configure the PIO sequencer clock and pin registers
e=Pio(execctrl 0,0,&h1f) 'use pin gp0 (no external wire, snoop pin GP0)
'e=Pio(execctrl 1,0,&h1f) 'use pin gp1 (external wire to GP0)
s=Peek(word &h503000d0) 'just to get default value reprogrammed
p=0 'no IO pins used except PIN in JMP (not part of this register)

'program the above program in the PIO and setup the machine, and start it.
PIO program 1,a%()
PIO init machine 1,0,1000000,p,e,s
PIO start 1,0

'wait a moment for data to get collected
Pause 100

'read the top of the PIO FIFO one word at at time. Since you start measuring at a
'random moment, the first reading can be wrong (incomplete cycle).
Do
 count = Peek(word &h50300020) 'reads the fifo register
 period = 2 * (count + 3)
 print "the period measured is ";period;" us"
 Pause 100
Loop While Inkey$=""

PIO stop 1,0
End

PicomiteVGA PETSCII ROBOTS
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 5705
Posted: 07:48am 12 May 2022
Copy link to clipboard 
Print this post

Lovely to see a real-life application for the PIO. :) I know VGA uses it, but that's getting complicated. lol
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8567
Posted: 08:16am 12 May 2022
Copy link to clipboard 
Print this post

Did PIO READ not work? I note you are peeking the register.
 
Tinine
Guru

Joined: 30/03/2016
Location: United Kingdom
Posts: 1646
Posted: 09:14am 12 May 2022
Copy link to clipboard 
Print this post

  Mixtel90 said  Lovely to see a real-life application for the PIO. :) I know VGA uses it, but that's getting complicated. lol


Couldn't agree more  
Some serious HP here that I also would like to tap.


Craig
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 3496
Posted: 09:25am 12 May 2022
Copy link to clipboard 
Print this post

@Peter

No, not really. So I used the peek method.


Dim h%(3)
PIO read 1,0,4,h%()
Print h%(1)


gives error

[42] PIO read 1,0,4,h%()
Error : Invalid syntax

PicomiteVGA PETSCII ROBOTS
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024