Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 03:43 24 May 2025 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 : Quadrature multichannel decoder for PicoMite using PIO

     Page 2 of 2    
Author Message
allie
Regular Member

Joined: 06/10/2018
Location: Canada
Posts: 43
Posted: 08:21pm 22 May 2025
Copy link to clipboard 
Print this post

  Volhout said  Hi Allie,

You may have been confused with the different versions.

The " _ " underscore to make the lines longer only works in 6.00.02rc24 (the latest rc). If you are using 5.08.00 then do following:

Run the program
You will get an error
Press F4 (that will open the editor)

Move the cursor to the first character on the "&h001A0015....." line
Press <backspace> on the keyboard

The editor will glue the 2 lines together, but the end of the line is invisible.
You will have a working program now.
You can run it (F2).

I would suggest you save the program
Press F1
Save "quadrature.bas"

You will have saved the program with the glued line, and next time you load it, the problem will not occur.

Volhout
.
 
allie
Regular Member

Joined: 06/10/2018
Location: Canada
Posts: 43
Posted: 08:30pm 22 May 2025
Copy link to clipboard 
Print this post

I did what Volhout said and it seems to work. I have to hook up my cnc x,y,z and rotary table axis encoders to try. May be also modify my MMBasic code to select one of the axis and wait for the input signal.
I'm baby sitting my two great granddaughters twins now so I'll try it later.

Regards Allie
 
allie
Regular Member

Joined: 06/10/2018
Location: Canada
Posts: 43
Posted: 09:03am 23 May 2025
Copy link to clipboard 
Print this post

I put in the input "Select sm0 to sm3";sm  *** command in the main MMBasic code section in the main loop after

                              do

                                a$=inkey$

I not sure if it was before or after a$=inkey$

Now the program is stuck in a loop, asking for the input. I pressed Esc ** no affect.
Then pressed Ctrl and Esc and the program stopped. The next time I ran the program with pressing F2 it went back to the input command asking to input "select sm0 to sm3
it is still in the loop.
How do I reset the picomite with out losing the PIO program. I know you can use one of the pins on the 2040, but I want to make sure I don't lose the PIO program as I had to type all of the code in my self.
I could not get the * copy to clipboard * to work right, the PIO program went into tera term terminal but not right. When I typed it in myself it was O.K.

Regards Allie
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 4919
Posted: 09:24am 23 May 2025
Copy link to clipboard 
Print this post

Hi Allie,

When the pico is stuck, <CTRL>-C will stop the program.
Then type SAVE "Quadrature.bas", and the program will be saved on the A:/ drive.
The A:/ drive is flash, so it will remain stored, also without power.

You can disconnect the pico from power, reset it, whatever...

If you need to run the program again:
LOAD "Quadrature.bas"
RUN

Volhout

P.S. I think the program allows you to select a number of quadrature decoders, but just at start. You can not dynamically resize them during run. You select that you need 3, and then that is it. When you stop and RUN again, then you can select 4 (or 2)... But not change while the program is running.
.
Edited 2025-05-23 19:27 by Volhout
PicomiteVGA PETSCII ROBOTS
 
allie
Regular Member

Joined: 06/10/2018
Location: Canada
Posts: 43
Posted: 10:44am 23 May 2025
Copy link to clipboard 
Print this post

I had the picomite disconnected from the laptop and it did end the loop. thank you for the info. I have to go to work now so I'll try to work at it when I come home.

I want to use the RP2040 PicoMite to count the milling machine x,y,and z encoders then

send the count to the color MaxiMite 2 gen 2 which will be the main controller for my milling machine and lath setup.

I thought I could put the MMBasic code in the MMBasic section of the main loop to select which axis to count with an input statement.

Any thoughts on this?

Regards Allie
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 4919
Posted: 12:11pm 23 May 2025
Copy link to clipboard 
Print this post

Hi Allie,

The code you have from PhenixRising prints the counts to screen.
If you open a serial port on the picomite, you can send the same data to the CMM2.

This is the current main loop

'main loop
do
a$=inkey$                                     'just for control

'get the data from the fifo and print
if sm0 then print str$(read_fifo(0),12,0);    'get data from decoder
if sm1 then print str$(read_fifo(1),12,0);    'get data from decoder
if sm2 then print str$(read_fifo(2),12,0);    'get data from decoder
if sm3 then print str$(read_fifo(3),12,0);    'get data from decoder
print

'just some pause
pause 100                                     'any delay needed

'reset position (PIO X register) under control of keyboard
if a$="r" then                                'press r to zero position
  if sm0 then pio execute 1,0,&hA023 '= assembly "mov X, null" (zero X reg)
  if sm1 then pio execute 1,1,&hA023 '= assembly "mov X, null" (zero X reg)
  if sm2 then pio execute 1,2,&hA023 '= assembly "mov X, null" (zero X reg)
  if sm3 then pio execute 1,3,&hA023 '= assembly "mov X, null" (zero X reg)
  a$=""
end if

loop while a$=""  'exit when any key not r


That would convert to


'serial comms to CMM2 using GP20 and GP21
SETPIN GP21,GP20,COM2
OPEN "COM2:112500" AS #1

'main loop
do
a$=inkey$                                     'just for control

'get the data from the fifo and print
if sm0 then print #1,str$(read_fifo(0),12,0);    'get data from decoder
if sm1 then print #1,str$(read_fifo(1),12,0);    'get data from decoder
if sm2 then print #1,str$(read_fifo(2),12,0);    'get data from decoder
if sm3 then print #1,str$(read_fifo(3),12,0);    'get data from decoder
print

'just some pause
pause 100                                     'any delay needed

'reset position (PIO X register) under control of keyboard
if a$="r" then                                'press r to zero position
  if sm0 then pio execute 1,0,&hA023 '= assembly "mov X, null" (zero X reg)
  if sm1 then pio execute 1,1,&hA023 '= assembly "mov X, null" (zero X reg)
  if sm2 then pio execute 1,2,&hA023 '= assembly "mov X, null" (zero X reg)
  if sm3 then pio execute 1,3,&hA023 '= assembly "mov X, null" (zero X reg)
  a$=""
end if

loop while a$=""  'exit when any key not r


In this code you would still use the keyboard of the picomite (or console) to reset the counters. For full automation using the CMM2 you would replace the a$=inkey$ with  a$=INPUT(#1,1) or similar.
And maybe you want to replace the
loop while a$=""

with
loop


To make sure the loop on the pico never stops.

Volhout
.
Edited 2025-05-23 22:16 by Volhout
PicomiteVGA PETSCII ROBOTS
 
PhenixRising
Guru

Joined: 07/11/2023
Location: United Kingdom
Posts: 1193
Posted: 02:48pm 23 May 2025
Copy link to clipboard 
Print this post

  allie said  
I want to use the RP2040 PicoMite to count the milling machine x,y,and z encoders then

send the count to the color MaxiMite 2 gen 2 which will be the main controller for my milling machine and lath setup.

I thought I could put the MMBasic code in the MMBasic section of the main loop to select which axis to count with an input statement.

Any thoughts on this?

Regards Allie


You really want to send the encoder counts fast enough for the CMM2 to close four MATH.PID loops @ 1ms. A 1KHz loop-rate is a kind of standard for CNC and it is based off of machine bandwidth (mechanical response time). This is also the fastest that we can get with MATH.PID.

Edit: Or close all four MATH.PID loops on the PicoMite and have the CMM2 feed command positions to the PIDs. We have the power  
Edited 2025-05-24 00:52 by PhenixRising
 
     Page 2 of 2    
Print this page


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

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025