![]() |
Forum Index : Microcontroller and PC projects : Quadrature multichannel decoder for PicoMite using PIO
![]() ![]() |
|||||
Author | Message | ||||
allie Regular Member ![]() Joined: 06/10/2018 Location: CanadaPosts: 43 |
|
||||
allie Regular Member ![]() Joined: 06/10/2018 Location: CanadaPosts: 43 |
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: CanadaPosts: 43 |
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: NetherlandsPosts: 4919 |
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: CanadaPosts: 43 |
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: NetherlandsPosts: 4919 |
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 '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 '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 KingdomPosts: 1193 |
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 |
||||
![]() ![]() |
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |