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 : STEP-DIR decoder for picomite PIO
Page 1 of 3 | |||||
Author | Message | ||||
Volhout Guru Joined: 05/03/2018 Location: NetherlandsPosts: 4223 |
PhenixRising requested this function, to emulate a stepper motor on a DC motor with encoder. This is a first version. When this works to satisfaction, I can easily combine it with the Quadrature decoder. Then an RP2040 board can emulate 4 stepper motors into 4 DC motors (quad convertor(. The current code used PIO 1 (since my VGA board have PIO 1 free). The above mentioned Quad convertor will use PIO0 for STEP decoding, and PIO1 for Q-decoding. The PID algorithms will have to be written bij somone else, since these will require tuning on actual hardware that I do not poses. To test below code: GP0 = STEP pulse (low=idle, rising edge of the clock the direction) GP1 = DIRECTION signal. 'step/dir_decoder_pico_PIO_version 4 'program options do_assemble=0 'either assemble the code, or brute force program use_test_signal=1 'internally generate test signal 'step pulse generation for testing if use_test_signal then stp_init 'init GPIO pins settick 10,do_step '10ms = 100Hz step frequency cntr = 0 'step counter direction = 0 '0 = count up, 1 = count down else setpin gp0,pio1 'the STEP signal setpin gp1,pio1 'the DIRECTION signal end if 'Generic defines f= 63e6 '63 MHz PIO frequency pio clear 1 dim dat%(4) 'array to store FIFO data ' PIO code ------------------------------------------------------------------- if do_assemble then 'assemble 'header and start of the PIO code pio assemble 1,".program test" pio assemble 1,".line 0" 'wait for step pulse pio assemble 1,"wait 0,pin,0" 'wait for GP0 to become 0 pio assemble 1,"wait 1,pin,0" 'wait for GP0 to become 1 = rising edge STEP pulse pio assemble 1,"JMP pin, plus1" 'jump according state GP1 pin 'The plus and minus routines, X is the actual 32 bit position counter pio assemble 1,"minus1:" 'label:jump here to decrement X pio assemble 1,"JMP X--, push_out" 'decrement X pio assemble 1,"JMP push_out" 'regardless X value go to push_out pio assemble 1,"plus1:" 'label to increment X pio assemble 1,"mov X, !X" 'invert X pio assemble 1,"JMP X--, next1" 'decrement x pio assemble 1,"next1:" 'label:regardless X value come here pio assemble 1,"mov X, !X" 'invert back 'send the most recent position to FIFO pio assemble 1,"push_out:" 'label pio assemble 1,"mov ISR, X" 'move X to ISR pio assemble 1,"push" 'push ISR into FIFO, not blocked 'jump to start of PIO program pio assemble 1,"JMP 0" 'jump to beginning pio assemble 1,".end program" '50900RC4 and newerr 'pio assemble 1,".end program list" 'needed for 50900RC3 else 'brute force program the same code dim p%(7)=(&h4800c520a02020,&ha0290047a0290008,&h8000a0c1,0,0,0,0,0) pio program 1,p%() end if 'configure PIO 1 statemachine 0 (PIO 1 is free on PicoMiteVGA) p0=pio(pinctrl 0,0,0,gp0) 'gp0 is lowest IN pin (gp0,gp1) e0=pio(execctrl gp1,0,31) 'GP1=dir, wrap and wrap target s0=pio(shiftctrl 0,0,0,0,0,0) 'shift IN direction is left (the 5'th '0') 'initialize PIO 1 state machine 0 pio init machine 1,0,f,p0,e0,s0,0) 'init machine @ start loop 'start the quadrature decoder PIO 1 statemachine 0 pio start 1,0 'main MMBasic code ------------------------------------------------------------- 'main loop do a$=inkey$ 'just for control 'get the data from the fifo pio read 1,0,5,dat%() 'read whole fifo posi%=dat%(4) 'last data in fifo if posi%>2147483647 then inc posi%,-4294967296 '2'th complement print posi% 'show position '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 pio execute 1,0,&hA023 '= assembly "mov X, null" (zero the X register) a$="" end if 'set defined position in register X under control of the keyboard if a$="s" then input "desired count ";cnt% cnt%=cnt% and &hffffffff pio write 1,0,1,cnt% 'write the count cnt% in the fifo pio execute 1,0,&h8080 '= assemble "pull" (moves FIFO to OSR register) PIO execute 1,0,&hA027 '= assemble "mov X, OSR" moves the OSR value to X a$="" end if loop while a$="" 'exit when any key not r end 'test code in MMBasic that drives GP0 and GP1 according sub stp_init setpin gp0,dout : pin(gp0)=0 'step pin setpin gp1,dout : pin(gp1)=0 'dir pin end sub sub do_step 'this rountine counts 1000 steps up, then down, etc... inc cntr,1 'new step pulse gp0,0.1 '1 ms step pulse if cntr>=1000 then cntr = 0 direction = 1 - direction pin(gp1) = direction end if end sub Edited 2024-08-24 03:02 by Volhout PicomiteVGA PETSCII ROBOTS |
||||
PhenixRising Guru Joined: 07/11/2023 Location: United KingdomPosts: 857 |
Hey....a guy can only take so much excitement You and matherp conspiring to give me a heart attack???? This is AWESOME, Harm...Thanks very much |
||||
PhenixRising Guru Joined: 07/11/2023 Location: United KingdomPosts: 857 |
I might be in a position to test on a real machine some time during the weekend. Just hit my pet-peeve roadblock with one of these Yaskawa drives. I need to disable the internal control-loops because the PicoMite will be handling the PID, etc. There is a small control panel on the front of the drive with buttons and seven-segment display but the display disappears after a couple of seconds. Ah-ha, I can connect serially which is actually easier and I have the programming software. It requires a USB to serial cable of which I have many....BUT... Naturally....I need a special cable So sick of these games that these big manufacturers play...OK they charge stupid money for the cable but for the end-user? Yeah it takes a week to get one. "Sorry employees, we need to shut the doors for a week and we might lose the contract" At least I can work on the other axis |
||||
Volhout Guru Joined: 05/03/2018 Location: NetherlandsPosts: 4223 |
I can imagine you test this by paralleling the pico to the actual stepper motor driver signals, and monitor the readings on the terminal when you run some CNC sequence. See if you end up at count 0 when the machine is ready with its job. Volhout PicomiteVGA PETSCII ROBOTS |
||||
PhenixRising Guru Joined: 07/11/2023 Location: United KingdomPosts: 857 |
I don't actually have any stepper drives/motors. I'll have the servo loop closed on Pico #1 and have Pico #2 generate pulse and direction, feeding Pico #1. Whatever I generate should reflect on the encoder position from the AC servo, displayed by Pico #1. Going to use the rotary axis because it can't crash. The linear axis is a huge 5KW AC servo...pretty expensive if I crash that one. |
||||
PhenixRising Guru Joined: 07/11/2023 Location: United KingdomPosts: 857 |
This is one example of a fully capable CNC control but no good by itself because it only outputs pulse/dir. To retrofit an existing servo controlled machining centre, new drives and motors are also required and important capabilities are lost. The PicoMite will convert to the industry standard +-10v motor command and will also allow the user to retain such things as acceleration and velocity feed forwards, torque limiting etc. The Mach3 and Mach4 guys will go for this also Don't know what happened to the image (on my phone) Edited 2024-08-24 06:24 by PhenixRising |
||||
Bryan1 Guru Joined: 22/02/2006 Location: AustraliaPosts: 1344 |
G'Day Volhout I'm just waiting for this 7" spi SD1963 lcd to get here then I can setup a zero then pump this code straight into a DM556 micro stepper. Those boards from JLCPCB should be here anyday so the zero can be mounted with a inline pinout and setup with a new breadboard and eh with that motherboard one pico-zero could handle each axis where the master just sends out the code for each as needed. It will be interesting to try this out and eh if it does work then my CMM2 can take over and the fun of a CMM2 cnc can get started. Regards Bryan Edited 2024-08-25 18:13 by Bryan1 |
||||
Volhout Guru Joined: 05/03/2018 Location: NetherlandsPosts: 4223 |
If this works I will make it more universal. Add polarity setting on both STEP and DIRECTION signals. Volhout PicomiteVGA PETSCII ROBOTS |
||||
Bryan1 Guru Joined: 22/02/2006 Location: AustraliaPosts: 1344 |
Well the DM556 can work off 5 volt npn and pnp signals so yes it will be interesting to see if this works and if it does then anyway can try with the same microsteppers. Regards Bryan |
||||
Bryan1 Guru Joined: 22/02/2006 Location: AustraliaPosts: 1344 |
G"day Guy's, Yesterday those RPZ Compute boards arrived from JLCPCB so made a board up and have it all setup on my breadboard. So I have copied and pasted that code into MMBasic and as Option Explicit was enable got the error do_assemble not declared. So blanked out Option Explicit and now got this error > run [82] PIO init machine 1,0,f,p0,e0,s0,0) 'init machine @ start loop Error : Clock must be in range 2029 to 133000000 Now as this is my first picomite I do think a few things need to be setup first before this code will run. So any help will be great Now as the GP0 and GP1 pins are Low Idle this should mean I pull down the DM556 step and direction inputs. Regards Bryan Edited 2024-08-27 11:42 by Bryan1 |
||||
Volhout Guru Joined: 05/03/2018 Location: NetherlandsPosts: 4223 |
Hi Bryan, Yes, I did not pre define variables, so option explicit must be commented out. The PIO frequency is set f= 63e6 No idea why this is not working for you. Run the program again until it errors, and then type print f On the commandline. It will show you what f is set to. Volhout PicomiteVGA PETSCII ROBOTS |
||||
PhenixRising Guru Joined: 07/11/2023 Location: United KingdomPosts: 857 |
Hi Bryan, Looks like something wrong with that line because it has only a closed parenthesis. Remove it. f is set to 63000000: The code that I am running starts with a label ".wrap target" and the the last line of the code "JMP"s to it, like a goto-label. This new code simply "JMP"s to line zero. So the last parameter that you need...I'm guessing either: OR Volhout should be along to confirm before too long. |
||||
PhenixRising Guru Joined: 07/11/2023 Location: United KingdomPosts: 857 |
Oh Harm's already here |
||||
Bryan1 Guru Joined: 22/02/2006 Location: AustraliaPosts: 1344 |
Hi Volhout mate I find that doccy you did on this PIO and been reading it for a while now and yes it is a heap to take in. Now f= 63e6 is in the program and I did just type that on the command line the when I run it. > run [82] PIO init machine 1,0,f,p0,e0,s0,0) 'init machine @ start loop Error : Clock must be in range 2029 to 133000000 > print f Error : Attempt to print reserved word So it does look like I do need to set a heap of options as I did and wire up my ILI9341 2.5" tft display I have here and the error that the spi channel isn't setup. So alot more reading and head scratching to do as I try and let all this soak in. Regards Bryan |
||||
PhenixRising Guru Joined: 07/11/2023 Location: United KingdomPosts: 857 |
Just copied/pasted and ran it on a regular PicoMite....Didn't complain. Sitting here continuously printing numbers to the screen. Even with the oddball ")" in the init parameter list. Edited 2024-08-27 16:01 by PhenixRising |
||||
Volhout Guru Joined: 05/03/2018 Location: NetherlandsPosts: 4223 |
PIO init machine 1,0,f,p0,e0,s0,0) should be PIO init machine 1,0,f,p0,e0,s0,0 That is a typing error from my side. I have no idea why Bryan's PicoZero behaves like that. I would re-install MMBasic. Make sure you have the PicMite version (not the VGA or Webmite). This is strange.... One other alternative to try is: copy the whole program in "NotePad" (not NotePad++) in Windows, save it. Then copy the text from NotePad (autosave) to the pico. Maybe there is a hidden character in the text somewhere. Notepad removes those. Volhout PicomiteVGA PETSCII ROBOTS |
||||
Bryan1 Guru Joined: 22/02/2006 Location: AustraliaPosts: 1344 |
Well tried this to get the SPI going for the LCD > spi open 1000, 0, 16 Error : Not all pins set for SPI > setpin GP4, GP7, GP6, SPI > spi open 1000, 0, 16 > option lcdpanel ili9341, OR, GP5, GP8, GP3 Error : System SPI not configured So not sure what I'm doing wrong here |
||||
PhenixRising Guru Joined: 07/11/2023 Location: United KingdomPosts: 857 |
Is "1000" even a valid speed setting? > spi open 1000, 0, 16 |
||||
PhenixRising Guru Joined: 07/11/2023 Location: United KingdomPosts: 857 |
Very little experience with displays, here but I believe that OR (orientation) needs to be: |
||||
Mixtel90 Guru Joined: 05/10/2019 Location: United KingdomPosts: 6780 |
Just a comment - the orientation argument is just a letter or word, not a string. You can't use ' "LANDSCAPE" ' for example. Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
Page 1 of 3 |
Print this page |