Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 02:39 19 May 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 2 of 4    
Author Message
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 5770
Posted: 08:07am 27 Aug 2021
Copy link to clipboard 
Print this post

Sounds like something where a PIO would produce the video signals with the correct timing, getting video data from a double-length input shift register with a high auto-pull threshold, interrupting the 2nd cpu to get it. That feeds the shift register when timing allows, as the 2nd cpu would have to wait until ram access was available (hence the double length shift register).

Of course, it might not be a particularly quick way to get the video stream out as you might display a character some time after it was placed in the frame buffer.

This is way to early in the morning to be thinking of this stuff....  :(
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
led-bloon

Senior Member

Joined: 21/12/2014
Location: Australia
Posts: 204
Posted: 06:23am 06 Sep 2021
Copy link to clipboard 
Print this post

Peter
In general, the current steps to run a PIO program are quite clear until:

  PIO START pio block, pio machine  - currently necessary separately!
  PIO EXECUTE pio block, pio machine, entry point

Could the call to PIO START be done -INSIDE- PIO EXECUTE - as first task?
Removing the need for this non-intuitive line above, as PIO START "appears" to do
nothing physically.
PIO START (with its complimentary PIO STOP) remain functions for the programmer
to play with (pausing PIO in basic code) once up and running.
--------------------
The call to PIO INIT MACHINE ...using the helper function pio(pincntrl ....) has an
anomoly. The SET base and the SIDE SET base MUST use GP numbers (but without the prefix 'GP')
This I'm sure is also the case for IN base. It should be able to handle both pin and FULL 'GPnn' numbering.

' test04() side set pin with FAILURES!!!!!
' Output pulse on GP20 (pin 26) with side_set on GP21 (pin 27)
Option explicit

'  Using a 5khz clock: 1 cycle=100 clock ticks
'test04: NB SELF: FINAL code generated using pasm!!!!!!!
'Data "set pindirs 3 side 0"
'Data "set pins 1 side 0 [10]"
'Data "nop [10] side 0"
'Data "nop [10] side 0"
'Data "set pins 0 side 1 [10]"
'Data "nop [10] side 1"
'Data "nop [9] side 1"
'Data "JMP 1 side 1"
'Data ""

Dim integer asmcode(7)

asmcode(0)=&HAA42AA42EA01E083
asmcode(1)=&H1001B942BA42FA00
asmcode(2)=&HA042A042A042A042
asmcode(3)=&HA042A042A042A042
asmcode(4)=&HA042A042A042A042
asmcode(5)=&HA042A042A042A042
asmcode(6)=&HA042A042A042A042
asmcode(7)=&HA042A042A042A042

'SetPin 26,pio0      ' ok
'SetPin 27,pio0      ' ok
SetPin GP20,pio0     ' ok
SetPin GP21,pio0     ' ok

PIO clear 0

PIO PROGRAM 0,asmcode()

' set clock 5kHz assign 26 to SET group, 27 to SIDE SET group.
PIO init machine 0,0,5000,Pio(pinctrl 1,1,0,0,21,20)
' HERE:                                        |  | GP pins ONLY without pre-'GP'!

' and start the output
PIO start 0,0
PIO execute 0,0,0 'entry point 0

Do
   Pause 1000
   Print ".";
Loop                                                                                

Thanks again
led
Miss you George
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8605
Posted: 07:06am 06 Sep 2021
Copy link to clipboard 
Print this post

You need to read the Pico SDK to see why execute and start are very different.
pio_sm_exec vs pio_sm_restart

The helper functions only use the GPIO numbers as they define ranges where the pins may not be contiguous (compare the port command). I could mandate the gp prefix but this would be redundant. Simpler just to make it clear in the docs unless there is strong feeling on this.

PIO is non trivial so any user is going to have to understand things to use the I/F
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 3589
Posted: 08:18am 06 Sep 2021
Copy link to clipboard 
Print this post

Hi Peter,

In classic MMbasic implementations the IO pins can be referenced to with chip pin number (nn), and manufacturer port/pin designator (GPxx). These are tied together by the chip itself and will never change.

For picomite the nn stands for the board pin number. Not the chip pin number. This makes introduction of a new PCB with the same chip require a code adaptation.

But for the SET and SIDE SET commands we introduce a new format. xx (GPxx without 'GP'). That makes things confusing.

Depending on the command/function we use nn, or GPxx or xx. Where the xx is a different number from nn, but the format is the same. This is confusing. Can we avoid this confusion ?

I see 2 options...

a/ drop the nn format completely, and only support GPxx and xx. That may be a big change for those who already use the nn implementation, but it is completely consistent.

b/ allow GPxx use in SET and SIDE SET and related commands. That brings it in line with normal MMbasic. So we continue using nn and GPxx. Only the SET and SIDE SET commands do not accept the nn (board pin number) format.
PicomiteVGA PETSCII ROBOTS
 
led-bloon

Senior Member

Joined: 21/12/2014
Location: Australia
Posts: 204
Posted: 09:05am 06 Sep 2021
Copy link to clipboard 
Print this post

Peter
Thank you, for all your hard work, anyway
led

Edit: Removed the BS
Edited 2021-09-06 19:14 by led-bloon
Miss you George
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 5770
Posted: 10:30am 06 Sep 2021
Copy link to clipboard 
Print this post

As Peter says, the PIO is non-trivial. (I love that phrase! - it sounds so much nicer than "a confusing load of ****", "soddin' awkward" or "a right pain in the a**e").

a) Mandating the GP prefix would bring the PIO helper functions in line with other MMBasic functions, and it might make things less confusing when attempting to figure out someone else's programming.

b) Personally I wouldn't normally be in favour of using GP numbers without the prefix, even if it does reduce the amount of typing I have to do.

c) The helper functions are a special case in that it's impossible for them to use PicoMite PCB pin numbers because of their function. All numbers in them have to be RP2040 (GP) references, prefixed or not. I can live with a lack of prefix, providing it's documented.
Mick

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

Joined: 11/12/2012
Location: United Kingdom
Posts: 8605
Posted: 10:57am 06 Sep 2021
Copy link to clipboard 
Print this post

  Quote  Mandating the GP prefix would bring the PIO helper functions in line with other MMBasic functions


I'll do that in the next beta
 
led-bloon

Senior Member

Joined: 21/12/2014
Location: Australia
Posts: 204
Posted: 11:23pm 09 Sep 2021
Copy link to clipboard 
Print this post

@Matherp - Peter
Problems with (simple) side set test - toggle()
Multiple codes worked until a reboot/restart.
The "current fix" makes the code work both after a restart and a cold boot ok.
Is this a bug or I'm missing something?
' toggle() simple toggle of set & side set pins out of phase
' Output pulse on GP20 (pin 26) with side_set on GP21 (pin 27)
' Runs from both a cold start and reboot ok, with the "fix".
Option Explicit

Dim integer MakeItWork=0
Dim string ip$

Print "Fix code y/N? ";
Do
   ip$=Inkey$
Loop While ip$=""
Print ip$

If ip$ = "y" Or ip$="Y" Then
   Print "Toggle will now work ok!"
   MakeItWork=1
EndIf

'toggle() NB: FINAL code generated using RPF pioasm!
'.side_set 1   <--- max delay reduced to 15
'    set pindirs 3 side 1
'.wrap_target
'    set pins 1 side 0 [15]
'    set pins 0 side 1 [15]
'.wrap

Dim integer asmcode(7)

asmcode(0)=&HA042FF00EF01F083
asmcode(1)=&HA042A042A042A042
asmcode(2)=&HA042A042A042A042
asmcode(3)=&HA042A042A042A042
asmcode(4)=&HA042A042A042A042
asmcode(5)=&HA042A042A042A042
asmcode(6)=&HA042A042A042A042
asmcode(7)=&HA042A042A042A042

SetPin GP20,pio0
SetPin GP21,pio0

PIO CLEAR 0

PIO PROGRAM 0,asmcode()

' NB: Base pins are GP pins sans "GP"
Dim integer dum0 = Pio(pinctrl 1,1,0,0,20,21)  ' Reversed pin bases!!!
Dim integer dum1 = Pio(pinctrl 1,1,0,0,21,20)
Dim integer dum2 = Pio(execctrl 0,1,2)

'Print "&H"+Hex$(dum1)    <<<<< Correct data for this call
'Print "&H"+Hex$(dum2)    <<<<< Correct    ditto
'End

If MakeItWork = 1 Then
   PIO INIT MACHINE 0,0,1000000,dum0,dum2  ' Initial pin bases reversed
   PIO START 0,0
EndIf
PIO INIT MACHINE 0,0,1000000,dum1,dum2      ' Correct call
PIO START 0,0
'PIO EXECUTE 0,0,0       ' Not needed when default start 0?

Do
   Pause 1000
   Print ".";
Loop

End

led
Edited 2021-09-10 12:04 by led-bloon
Miss you George
 
led-bloon

Senior Member

Joined: 21/12/2014
Location: Australia
Posts: 204
Posted: 11:18pm 13 Sep 2021
Copy link to clipboard 
Print this post

The following is some pre-demo code for a 640x480 60Hz 1 colour VGA O/P.
It has not been tested on a monitor because NO RAM buffer, or DMA channel,
has been allocated to feed the VGA generator.  Currently the RGB data is
a single 1 bit held high for the full 640x40 nSecs "line time" (clock 25MHz).
64 uSec vSync pulses are at every 16.6 mSecs with a 1.02 mSec back porch.
4 uSec hSync pulses are at approx. 38 uSecs with a back porch of 3 uSecs.
(RGB) Data follows each hSync back porch for a period of 27 uSecs approx.

The PIO code consists of 4 blocks of code to feed 4 state machines. I have
manually modified the code to include 4 "wrap_target/wrap" addresses which
allows the entire code to EXACTLY fit the 32 instructions allowed. IRQs 4-7
are used to communicate between each state machine for syncing purposes.

Adding real RGB data will involve adding 2+ more opcodes, so major changes
would need to be made involving adding pio1 block code.
I re-iterate this is NOT working VGA code, just some pre-demo stuff to ponder,
IF you are that way inclined.
I am not even suggesting that VGA code be implemented in the Pico - period!
led
; vSync7
; NB: Mod'd for multiple wraps!!!!
; Moved all irqs to 4-7
.program vSync7
;
; sMachine 0 starts here!
;
   set pindirs 7       ; 3 O/P pins vSync, hSync, pix Data
   set pins 3          ; Both syncs Hi, pix Lo
   pull block          ; Get loop count 16619 @ 1MHz (once only!)
   mov y osr           ; Store for re-use every loop
.wrap_target
   Set pins 2 [31]     ; vSync Lo hSync Hi for 64uSecs
   nop [30]
   Set pins 3          ; Revert to both default Hi
   irq 4               ; SET signal for sMachine 1
   mov x y             ; Get delay count
loop1:
   jmp x-- loop1       ; 16.6 mSecs delay
.wrap
;
; sMachine 1 starts here!
;
   pull block          ; vBack porch delay @ 1MHz clock 1.02 mSecs
   mov y osr           ; Store 1020 for re-use every loop
vBPorch:
   mov x y             ; Pre-set the counter
   wait 1 irq 4        ; Wait for vSync signal irq4 & clear
loop2:
   jmp x-- loop2       ; delay back porch
   irq 5               ; Signal sMachine 2
;>>>    jmp vBPorch     changed to wrap in sMachine 1
;
; sMachine 2 starts here - hSync + hBackPorch
;
   pull block          ; Read in 480 line count
   mov y osr           ; Store for re-use every loop
mloop:
   mov x y             ; Pre-set counter
   wait 1 irq 5        ; Wait for signal and clear
loop3:
   set pins 1 [3]      ; hSync pulse 4 uSecs (vsync Hi data Lo)
   set pins 3 [2]      ; hSync BPorch - Both syncs Hi & data Lo
   irq 6               ; Signal sMachine 3 GO
   wait 1 irq 7        ; Wait for sMachine 3 to return
   jmp x-- loop3       ; Do next line
;>>>    jmp mloop       changed to wrap in sMachine 2
;
; sMachine 3 starts here
;
   pull block          ; Read in 640 (pix/line)
   mov y osr           ; Store for re-use each loop
pix:
   mov x y             ; Pre-set counter
   wait 1 irq 6        ; Wait for sMachine 2 & clear
   set pins 7          ; pix 1 Hi, vSync & hSync Hi <<<< current RGB data
loop4:
;    OUT pins 1         ; OUT instruction for 1 bit (each pixel B/W data)...
   jmp x-- loop4       ; ...this would take 2 cycles - go to 50MHz clock?
   irq 7               ; Signal next line - sMachine 2
;>>>    jmp pix         changed to wrap in sMachine 3



' vsync7 - using irq 4-7 for inter-machine signalling
' Output vSync 64uS pulses on GP20 (pin 26) continuous
' Output 480 hSync 4uS pulses after each vSync Backporch
' Output 640 pixels after hSync Backporch
' Manually mod'd asmcode for 4 wrap/wrap_targets to fit code in
Option explicit

Dim integer asmcode(7)

asmcode(0)=&HA04780A0E003E087
asmcode(1)=&HC004E003BE42FF02
asmcode(2)=&HA04780A00049A022
asmcode(3)=&HC005004EA02220C4
asmcode(4)=&HA02220C5A04780A0
asmcode(5)=&H20C7C006E203E301
asmcode(6)=&H20C6A04780A00054
asmcode(7)=&HC007005EE007A022

SetPin GP20,pio0
SetPin GP21,pio0
SetPin GP22,pio0

PIO clear 0
PIO PROGRAM 0,asmcode()

' assign 3 pins to SET group, base GP20. 4 wrap_target/wrap manually attained.
PIO INIT MACHINE 0,0,1000000,Pio(pinctrl 0,3,0,0,0,20),Pio(execctrl 0,4,9)
PIO INIT MACHINE 0,1,1000000,,Pio(execctrl 0,12,15)  'No pins touched
PIO INIT MACHINE 0,2,1000000,Pio(pinctrl 0,3,0,0,0,20),Pio(execctrl 0,18,24)
PIO INIT MACHINE 0,3,25000000,Pio(pinctrl 0,3,0,0,0,20),Pio(execctrl 0,27,31)

' start each sMachine backwards 3 to 0
' sMachine 0 kicks it all off and running (vSync)
PIO START 0,3
PIO EXECUTE 0,3,25     ' PIO 0, Machine 3, instruction 25
PIO WRITE 0,3,1,640    ' dummy 640 pixels/line

'FillBuf               ' sMachine 3 - pixel data

PIO START 0,2
PIO EXECUTE 0,2,16     ' PIO 0, Machine 2, instruction 16
PIO WRITE 0,2,1,480    ' 480 scan lines

PIO START 0,1
PIO EXECUTE 0,1,10     ' PIO 0, Machine 1, instruction 10
PIO WRITE 0,1,1,1019   ' sMachine 1 - backporch delay 1.02 mSecs

PIO START 0,0
PIO EXECUTE 0,0,0     ' PIO 0, Machine 0, instruction 0
PIO WRITE 0,0,1,16619 ' sMachine 0 - vSync delay 16.6 mSecs

Do
   Pause 1                   ' Every 1 mSecs
   Print ".";
'    FillBuf
Loop

' NOT used!
' Need to join RX_FIFO to TX_FIFO, add Auto-Pull & change def direction
' Then change the O/P pixel code to OUT instruction (2 cycle) and up the
' sMachine frequency to 50MHz and add a screen buffer and DMA!
' That's all.
Sub FillBuf
Local integer i

  For i = 1 To 160
       PIO WRITE 0,3,1,&HAAAAAAAA
   Next i
End Sub

End

Edited 2021-09-14 12:23 by led-bloon
Miss you George
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8605
Posted: 12:37pm 14 Sep 2021
Copy link to clipboard 
Print this post

led-bloon

Found it

The sideset pin needs to be included in the count of set pins otherwise set pindirs doesn't see it. Your "fix" implemented pindirs for each pin one at a time. So no bug in the firmware but another "learning" point for both of us.

Mixtel90: please could you include something to this effect in the docs - thanks

' toggle() simple toggle of set & side set pins out of phase
' Output pulse on GP20 (pin 26) with side_set on GP21 (pin 27)
Option Explicit


'toggle() NB: FINAL code generated using RPF pioasm!
'.side_set 1   <--- max delay reduced to 15
'    set pindirs 3 side 1
'.wrap_target
'    set pins 1 side 0 [15]
'    set pins 0 side 1 [15]
'.wrap

Dim integer asmcode(7)

asmcode(0)=&HA042FF00EF01F083
asmcode(1)=&HA042A042A042A042
asmcode(2)=&HA042A042A042A042
asmcode(3)=&HA042A042A042A042
asmcode(4)=&HA042A042A042A042
asmcode(5)=&HA042A042A042A042
asmcode(6)=&HA042A042A042A042
asmcode(7)=&HA042A042A042A042

SetPin GP20,pio0
SetPin GP21,pio0

PIO CLEAR 0

PIO PROGRAM 0,asmcode()

' NB: GP prefix needed for b16 onwards
Dim integer dum1 = Pio(pinctrl 1,2,0,gp0,gp21,gp20)
Dim integer dum2 = Pio(execctrl 0,1,2)

'Print "&H"+Hex$(dum1)    <<<<< Correct data for this call
'Print "&H"+Hex$(dum2)    <<<<< Correct    ditto
'End

PIO INIT MACHINE 0,0,1000000,dum1,dum2      ' Correct call
PIO START 0,0

Do
  Pause 1000
  Print ".";
Loop

Edited 2021-09-14 22:39 by matherp
 
led-bloon

Senior Member

Joined: 21/12/2014
Location: Australia
Posts: 204
Posted: 02:32pm 14 Sep 2021
Copy link to clipboard 
Print this post

Peter
Concur, fixes my problem, thank you!
What is your view of the "PIO EXECUTE..." line not being needed to get an output?
led
Edited 2021-09-15 01:18 by led-bloon
Miss you George
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 5770
Posted: 03:51pm 14 Sep 2021
Copy link to clipboard 
Print this post

So, in PINCTRL:
set_base is the number of the base pin
side_set_base will be the same or higher than the above
no_side_set_pins will be the number of side set pins, which will not exceed the highest set_pin
no_set_pins will be the total number of set and side_set pins
??

Does that tie in with
"Each of these operations is on one of four contiguous ranges of GPIOs, with the base and count of each range
configured via each state machine's PINCTRL register. There is a range for each of OUT, SET, IN and side-set operations.
Each range can cover any of the GPIOs accessible to a given PIO block (on RP2040 this is the 30 user GPIOs), and the
ranges can overlap"?

<confused>  :)
Mick

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

Joined: 11/12/2012
Location: United Kingdom
Posts: 8605
Posted: 04:16pm 14 Sep 2021
Copy link to clipboard 
Print this post

PicoMiteV5.07.01b18.zip


User display is now #25 (untested)

setpin n,intl,myint now allowed on the touch irq pin when GUI functionality is not enabled. If the number of GUI controls is set to something other than 0 then use GUI INTERRUPT. In this case the setpin will error.

Additional parameter on PIO INIT
PIO INIT MACHINE pio%, statemachine%, clockspeed [,pinctrl] [,execctrl] [,shiftctrl][,startinstruction]


The startinstruction parameter tells the PIO which is the first instruction when PIO START is used (was previously always 0)

PIO EXECUTE need now only be used when you want to interrupt an existing program. It immediately terminates the currently executing instruction and starts running from the instruction specified
Edited 2021-09-15 02:20 by matherp
 
utop25
Newbie

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

I am using PicoMite firmware V5.07.04 but can't get PIO to work.
My hardware is the Silicon Chip Pico BackPack (March 2022).
I have tried the example in "PicoMite_User_Manual Appendix E – The PIO Programming Package
The PIO Programming Package".  This is a simple program to output a squaewave on pin 1 ie GP0.
I observe no waveform at all. It appears that pin 1 is floating ie has not been configured for output.
I have also tried the 2 examples in this thread and still no output.
Pin 1 output works as expected when I use a simple Basic program to drive it.
Any ideas?
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8605
Posted: 10:49am 24 May 2022
Copy link to clipboard 
Print this post

I think the example needs updating. From what I remember the init command doesn't assign a set pin. I think it may need  ,pio(pinctrl 0,1) adding but this may be rubbish
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 1813
Posted: 12:50pm 24 May 2022
Copy link to clipboard 
Print this post

Found this recently but can't remember where or by whom.


PIO 1kHz square wave

The manual is just wrong, the SDK call used to initialise the PIO specifically clears pinctrl. If using any outputs you must then set up pinctrl. In the manual the command should be

PIO init machine 0,0,100000,Pio(pinctrl 0,1)


The attached is tested and works perfectly on the PicoMiteVGA

Dim a%(7)=(&H0001E000E101E081,0,0,0,0,0,0,0)
SetPin 1,pio1
PIO program 1,a%()
PIO init machine 1,0,100000,Pio(pinctrl 0,1)
PIO start 1,0

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

 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 3589
Posted: 03:15pm 24 May 2022
Copy link to clipboard 
Print this post

Hi Phil,

I wrote this, as a test for using the PIO to decode SSTV.
the

count = peek(word &h50300020)


can be replaced by

pio read 1,0,count

(count must be integer)

since at time I wrote the program there was a bug in PIO READ.

The idea was to have a continuous monitoring of the input frequency (the PIO does that) and independent of that process being able to look at the current frequency.
SSTV uses a pixel time of 0.572ms and that pixel time is not related to the modulation frequency that can be anywhere between 1100Hz (0.91ms) and 2300Hz (0.44ms). So you cannot wait for a period meter of frequency counter to finish. They stop at at integer intervals of the modulation frequency or integer miliseconds.

The currently implemented algorithm measures positive phase, and negative phase of a period separately to get closest to pixel alignment.

Volhout
Edited 2022-05-25 01:21 by Volhout
PicomiteVGA PETSCII ROBOTS
 
utop25
Newbie

Joined: 24/05/2022
Location: Australia
Posts: 5
Posted: 08:37pm 24 May 2022
Copy link to clipboard 
Print this post

Thanks to both matherp and phil99.

This statement indeed fixed the problem:
PIO init machine 1,0,100000,Pio(pinctrl 0,1)
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 1813
Posted: 04:21am 25 May 2022
Copy link to clipboard 
Print this post

Matherp and Volhout are the ones to thank, all I did was copy and paste. I keep a Bits and Pieces file of anything that looks useful, but have not been consistent in including source and author.
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 3589
Posted: 06:04am 25 May 2022
Copy link to clipboard 
Print this post

removed
Edited 2022-05-25 16:06 by Volhout
PicomiteVGA PETSCII ROBOTS
 
     Page 2 of 4    
Print this page
© JAQ Software 2024