Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 16:45 11 Jul 2026 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 : STEP-DIR decoder for picomite PIO

     Page 3 of 3    
Author Message
Bryan1

Guru

Joined: 22/02/2006
Location: Australia
Posts: 2135
Posted: 03:36am 30 Aug 2024
Copy link to clipboard 
Print this post

Hi Phill thanks heaps mate that code tweak worked a treat and on doing several runs the average is 432 pulses to move 0.098" so the resolution is 0.00268" a step.

I will continue this in my cnc thread.

Regards Bryan
 
PhenixRising
Guru

Joined: 07/11/2023
Location: United Kingdom
Posts: 1986
Posted: 09:14am 30 Aug 2024
Copy link to clipboard 
Print this post

My buddy has a CNC plasma and man, talk about a rapid ROI (return on investment). He fabricates log-grabbing attachments for JCB-type backhoes. He simply lists them on eBay. It's a sideline business but he pocketed £35K from it last year.

Now he has designed and built a log splitter and the market also looks good.

He has something like £15K into the CNC Plasma.

Anyway, he called me yesterday, totally puzzled and fearing a fault developing.
During cutting, the PSU cooling fans only switch on occasionally but when standing still, the PSU fan is on full-time AND the stepper-driver fans now kick-in.

"How can this be right?"

Well I explained that stepper-motors receive the most current when standing still because there's no back EMF. If the motors were disabled, then you risk an axis being disturbed by some external force.

This doesn't sit right with him and so here was my opportunity to tell him about this development Kinda wish I hadn't because he's more excited than I expected and I am up to my ears

Anyway, there's my future test-bed. I'll start by driving free-standing motors and when happy, swap-out all three drives and motors. He's happy to spend the money because he just wants his machine to not consume power when standing still
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 5975
Posted: 10:04am 30 Aug 2024
Copy link to clipboard 
Print this post

Phenix,

Most stepper motor drivers use PWM to control the coil current of the stepper motor.
I am not sure if you can control the current limit of this particular stepper motor driver IC, but if you can, you could reduce the current when there is no activity.
This will limit the heat build up in the coils, while maintaining the (even in microstepping) position. You will however loose torque. It is depening the application if that is acceptable. For a robot arm it is not acceptable to loose torque, but for a CNC machine in "waiting" position it might.

Volhout
PicomiteVGA PETSCII ROBOTS
 
PhenixRising
Guru

Joined: 07/11/2023
Location: United Kingdom
Posts: 1986
Posted: 10:28am 30 Aug 2024
Copy link to clipboard 
Print this post

  Volhout said  Phenix,

Most stepper motor drivers use PWM to control the coil current of the stepper motor.
I am not sure if you can control the current limit of this particular stepper motor driver IC, but if you can, you could reduce the current when there is no activity.
This will limit the heat build up in the coils, while maintaining the (even in microstepping) position. You will however loose torque. It is depening the application if that is acceptable. For a robot arm it is not acceptable to loose torque, but for a CNC machine in "waiting" position it might.

Volhout


Sure but drop the torque and the machine is vulnerable to being knocked out of position and the controller will be totally unaware...next part becomes scrap.

With servo-motors, we have options:
-Disable the motor completely and position continues to be updated via the encoder
-Just let the motors hold position which typically requires milliamps (thanks to PID)
-Let the motors hold position but with a user-defined dead-band:


Deadband=1mm (in encoder counts)

do
 If abs(command_position - encoder_position) > Deadband then
   Enable_motor_and_or_PID 'bring the motor back to command_position
 else
   Disable_motor_and_or_PID 'we are within the deadband so kill the power
 end if
loop
 
Bryan1

Guru

Joined: 22/02/2006
Location: Australia
Posts: 2135
Posted: 12:06pm 30 Aug 2024
Copy link to clipboard 
Print this post

Well guy's if you at my thread on my cnc you will see this is only a small one. Now when I did have it going it was rock solid in milling pcb's also I used to cut signs in red gum using it with a round cutter. OK I only took 0.5mm cuts but at no time did any axis wander.

For large machines yes servo's are the go but back in 2011 when I built this cnc I did have a few years prior building and re building to make it solid as.
 
PhenixRising
Guru

Joined: 07/11/2023
Location: United Kingdom
Posts: 1986
Posted: 01:17pm 30 Aug 2024
Copy link to clipboard 
Print this post

  Bryan1 said  Well guy's if you at my thread on my cnc


When referencing another thread, it's always helpful to provide a link  
I had to search and it's in "Other Stuff". I never go there.

However, I see you just posted:

  Quote  I will have to use the enable signal as when enabled and not used the stepper just heats up


The same issue as my buddy's plasma. Yup  
 
Bryan1

Guru

Joined: 22/02/2006
Location: Australia
Posts: 2135
Posted: 10:56pm 30 Aug 2024
Copy link to clipboard 
Print this post

  PhenixRising said  
  Bryan1 said  Well guy's if you at my thread on my cnc


When referencing another thread, it's always helpful to provide a link  
I had to search and it's in "Other Stuff". I never go there.

However, I see you just posted:

  Quote  I will have to use the enable signal as when enabled and not used the stepper just heats up


The same issue as my buddy's plasma. Yup  


When I do get started on the code I will start a CMM2 CNC thread in this forum so you can find it mate  

Yesterday arvo started on making the isolation board and as I do have 10 off 4n35's all of them are going on the perf board.

Now I have looked at that PIO code heaps of times and for the step movement I do think it's just a case of doing a pulse then have a count setup to control the distance traveled. But first baby steps and those limits and E-Stop need to be setup so the CMM2 can see and act when one is hit.
 
PhenixRising
Guru

Joined: 07/11/2023
Location: United Kingdom
Posts: 1986
Posted: 02:50pm 09 Jul 2026
Copy link to clipboard 
Print this post

Hey Harm,

I have just set up a RP2040 to see if I can get pulse/dir but I can't make sense of it.

I had to change:

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


to:

loop while a$<>"q"  'exit when any key not r


because it kept falling through but apart from that; how do I make it work? All I get is:


 
PhenixRising
Guru

Joined: 07/11/2023
Location: United Kingdom
Posts: 1986
Posted: 02:58pm 09 Jul 2026
Copy link to clipboard 
Print this post

Forgot to mention that I want to output pulse/dir from the new stepper driver and see if the PIO gets the right counts.
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 5975
Posted: 04:02pm 09 Jul 2026
Copy link to clipboard 
Print this post

Hi Phenix,

Did you swap step and dir?
Are you running 6.03.00 or 6.02.01 ( official releases).
There was an issue with 6.02.02 and 6.03.00 betas

Volhout
PicomiteVGA PETSCII ROBOTS
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 5975
Posted: 04:03pm 09 Jul 2026
Copy link to clipboard 
Print this post

Hi Phenix,

Did you swap step and dir?
Are you running 6.03.00 or 6.02.01 ( official releases).
There was an issue with 6.02.02 and 6.03.00 betas

Volhout
PicomiteVGA PETSCII ROBOTS
 
PhenixRising
Guru

Joined: 07/11/2023
Location: United Kingdom
Posts: 1986
Posted: 04:39pm 09 Jul 2026
Copy link to clipboard 
Print this post

OK, I'm now running 6.02.01 and I'm seeing something but the count doesn't make sense (yet).

I guess I don't understand that GP0 and GP1 are PIO inputs but the test code is addressing them as outputs
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 5975
Posted: 04:56pm 09 Jul 2026
Copy link to clipboard 
Print this post

Top of the code contains a line that enables assembly, and a line that says use test signal. Set that line from 1 to 0.

Volhout
Edited 2026-07-10 02:58 by Volhout
PicomiteVGA PETSCII ROBOTS
 
PhenixRising
Guru

Joined: 07/11/2023
Location: United Kingdom
Posts: 1986
Posted: 07:48pm 09 Jul 2026
Copy link to clipboard 
Print this post

I'd already tried that but no difference.

Not sure what happened but I chopped it down and used GP14 and GP15 to simulate and it works BEAUTIFULLY

You have no idea how excited I am about this   (big plans)

Many thanks, my friend  

'step/dir_decoder_pico_PIO_version 4

setpin gp0,pio1    'the STEP signal
setpin gp1,pio1    'the DIRECTION signal

'Generic defines
f= 63e6             '63 MHz PIO frequency
pio clear 1
dim dat%(4)         'array to store FIFO data

dim p%(7)=(&h4800c520a02020,&ha0290047a0290008,&h8000a0c1,0,0,0,0,0)
pio program 1,p%()

'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

setpin gp14,dout
setpin gp15,dout

'main MMBasic code -------------------------------------------------------------
 do:loop while inkey$<>""
'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%(3)                                  'last data in fifo
  if posi%>2147483647 then inc posi%,-4294967296 '2'th complement
  print posi%                                    'show position
 
  'just some pause
  pin(gp14)=1
  pause 10  
  pin(gp14)=0                                   'any delay needed
  pause 10
 
  if posi% >1000 then
     pin(gp15)=0
  elseif posi% <-1000 then
     pin(gp15)=1
  endif
 
  '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$<>"q"  'exit when any key not r

end

 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 5975
Posted: 06:32am 10 Jul 2026
Copy link to clipboard 
Print this post

Hi Phenix,

I am glad you have it working. In hindsight, looking at the code, it could have been better. You can clearly see that it is a derivative from the quadrature decoder, acked together rather fast. I feel a bit ashame I did not make it better.

But now we know it works...

Thank you for debugging.

Volhout
PicomiteVGA PETSCII ROBOTS
 
PhenixRising
Guru

Joined: 07/11/2023
Location: United Kingdom
Posts: 1986
Posted: 04:03pm 10 Jul 2026
Copy link to clipboard 
Print this post

PIO is wonderful  

Incredibly capable BASIC interpreter with pretty much every low level function that I could ever ask for, PIO, CSubs and TBS knowledge-base.

Just mind blowing.  

So many suckers out there, struggling for weeks on end with problems that we can solve in a heartbeat...They won't listen 🤬
 
     Page 3 of 3    
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 2026