Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 20:49 25 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 : Pico PIO Development

     Page 4 of 4    
Author Message
led-bloon

Senior Member

Joined: 21/12/2014
Location: Australia
Posts: 202
Posted: 11:20pm 27 May 2022
Copy link to clipboard 
Print this post

I stand corrected
led
Miss you George
 
utop25
Newbie

Joined: 24/05/2022
Location: Australia
Posts: 5
Posted: 02:48am 28 May 2022
Copy link to clipboard 
Print this post

Thanks to all for your help.
I now have a squarewave on GP02.
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 1781
Posted: 08:07am 28 May 2022
Copy link to clipboard 
Print this post

For the manual it may be more instructive using a pin other than the default as in Peter's example.
eg.

'1kHz square wave output on pin4 (GP2)
Dim a%(7)=(&H0001E000E101E081,0,0,0,0,0,0,0)
SetPin GP2,Pio1
PIO program 1,a%()
PIO init machine 1,0,4000, Pio(pinctrl 0,1,,,,GP2)
PIO start 1,0


Have tested it up to 20MHz (the limit of my multimeter). Could be useful.

Minimum frequency is 961.25 Hz as "Clock must be in range 3845 to 252000000" so max. should be 63 MHz. Using a lower CPU speed lowers these limits in proportion.
.
Edited 2022-05-29 18:23 by phil99
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 3516
Posted: 08:30pm 05 Jun 2022
Copy link to clipboard 
Print this post

There is no specific thread for pico PIO development except this one. So I post this here.

In my research for the programming challenge for 2022, I developed a SSTV program that makes use of the PIO sequencer (in the VGA picomite). This PIO program measures the frequency of the signal at pico pin GP0 and turns it into a number.

Prior to this however I did some experiments with the PIO sequencer to achieve the same in a different manner. This experiment measures the input frequency at pin GP0, and displays the result on LED's at GP1....GP5.
It discriminates between the SSTV specific frequencies

1900Hz (at GP1) for VIS leader signa
1500Hz (at GP2) for video black level
1300Hz (at GP3) for VIS logic "0"
1200Hz (at GP4) for SYNC signal
1100Hz (at GP5) for VIS logic "1"

Since this program uses PIO to SET pins, to MOV values from X register to GPIO pins, and uses the PIO instruction (post) DELAY to achieve timing this may be instructive to others who want to play with PIO.

'use PIO discriminator frequency on pin GP0 - works with PWM in
'to be used for SSTV reception
'since pixel clock in sstv is 0.572ms and lowest freq is 1500Hz (0.666ms)
'we measure half of input cycle (low half) at max 0.333ms
'shortest time is 1900Hz (white video)
'since we process only 1 bit, threshold is set to 1700Hz (0.294ms)

'1900Hz...1700Hz = white (GP1)
'threshold = 294us
'1700Hz...1500Hz = black (GP2)
'threshold = 333us (delta = 333-294 = 39)
'1500Hz...1250Hz = space = logic 0 (GP3)
'threshold = 400us (delta = 400 - 333 = 67)
'1250Hz...1150Hz = sync (GP4)
'threshold = 434us (delta = 434 -499 = 34)
'1150Hz...0      = mark = logic 1 (GP5)

SetPin gp1,pio1
SetPin gp2,pio1
SetPin gp3,pio1
SetPin gp4,pio1
SetPin gp5,pio1

'PIO 1 sequncer 0 is the frequency discriminator
'clock is set to 100kHz (10us)
'delay in the instructions is tuned to achieve correct timing

'generate test signal on GP0
SetPin gp0,pwm0a
PWM 0,1900,50
CLS

'pio program
'0 00C0   'wait for gp0 to become low (gp0 is not in GPIO map)
'1 E09F   'set pindirs gp1..gp5 out
'2 FA21   'set X=1 delay 26 ticks (260us)
'3 00CB   'jmp (gp0=1) to setpins
'4 E422   'set X=2 delay 4 ticks (40us)
'5 00CB   'jmp (gp0=1) to setpins
'6 E324   'set X=4 delay 3 ticks (30us)
'7 00CB   'jmp (gp0=1) to setpins
'8 E228   'set X=8 delay 2 ticks (20us)
'9 00CB   'jmp (gp0=1) to setpins
'A E030   'set X=16 delay 0
'B A001   'mov X to pins
 'if use fifo
 'C A0C1   'mov X to ISR
 'D 8000   'push noblock
 'z%=&hA0C18000  'use fifo
'C 0000   'jmp 0
z%=0      'not use fifo

Dim a%(7)=(&h00CBFA21E09F00C0,&h00CBE32400CBE422,&hA001E03000CBE228,z%,0,0,0,0)

'configure pio1
e=Pio(execctrl 0,0,&h1f)            'use gp0 for PIN
s=Peek(word &h503000d0)             'no change from default
p=Pio(pinctrl 0,5,5,,,GP1,GP1)      'p=&h14500021 gp1...gp5 for out/mov

'program pio1 and start
PIO program 1,a%()
PIO init machine 1,0,100000,p,e,s
PIO start 1,0

Print "running, input at gp0, status at gp1...gp5"
Dim zz%(3)

Do
 Input "typ frequentie :";fr
 PWM 0,fr,50
 Pause 100

 'For i=1 To 5
 '  Print (Peek(word(&h40014000+i*8)) And 2^17)/2^17,
 'Next i

 'display FIFI status
 'Print "FIFO: ";Hex$(Peek(word &h50300020))

 'display IO pin status (you can also solder LED's to the GP1-GP5 pins)
 Print Pin(gp1),Pin(gp2),Pin(gp3),Pin(gp4),Pin(gp5)

 'read FIFO
 'PIO read 1,0,4,zz%()  'actual data
 'For i=0 To 3
 '  Print "&h";Hex$(zz%(i)),
 'Next i
 Print
Loop Until fr=0

PIO stop 1,0
End


For the understanding: the PIO runs at 100kHz. The program starts at address 0 and loops back to it every new cycle.

The first instruction in the program is an endless loop until the GP0 pin becomes low.
There are 3 instructions (30us) and the 3'rd instruction has a instruction delay added (this is coded inside the instruction) of 26 cycles. This totals for 290us. Then GP0 pin is tested. When the pins is high, the frequency was higher than 1700Hz (threshold 294us), and the value in X is send to the GP1...5.
If not, another delay is added, another test is done, and anothervalue written to the GP1...5 pins. This goes on until the lowest frequency (longest period) is tested.

To test the system, PWM0A (pin GP0) is supplied with a frequency from PWM0 (50% dutycycle). This is just to verify it works without a external generator.

The picomite MMBasic (5.07.05 beta and newer) has a feature that can read the GPIO pins even when they are attached to the PIO. So if you do not plan to solder LED's to the GP1..GP5 pins the program reads the status of the pins and shows them onscreen.
When using an older version, you need to PEEK the GPIO input register (the code is in the program, but commented out).

If you wonder why there is a double asignment for IO pins in the PIO PINCTRL register, this is becuase the pin direction (pindirs) is done using the SET instruction. Where as sending data to the pins uses the MOV instruction. And these can be assigned to different ranges. In this cas the ranges overlap.

I hope some of you will study this and become a little more knowledged how the PICO PIO works. It is a great instrument with many options.
Edited 2022-06-06 06:35 by Volhout
PicomiteVGA PETSCII ROBOTS
 
     Page 4 of 4    
Print this page


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

© JAQ Software 2024