PID in my own software

If you have a question about the software please ask it here.

PID in my own software

Postby danut1234 » Wed Dec 21, 2022 4:13 pm

Hi, i am trying to use PID function of the AXBB-e board in my own software but i do something wrong.
The Stat->SpindleRPM; shows the corect value, when i use it only with relay control and external speed controler.
When i activate the PID control, and start the spindle with UC100.SetSpindleSpeed(10000); UC100.SpindleOn(true);
the spindle start to ramp up and passes the set speed until it reaches the spindle maximum speed, i hoked up the oscilloscope to the assigned pin and the PWM signal seems to increase up to 100% without stopping when the commanded speed is reached. (10% is the minimum PWM and 100% is the maximum setting sent to the board)


Another problem is that i don't know how to use this method in C#, so i can see what is trying the board to execute, and what it sees as the actual RPM.
unsafe public static extern int GetPIDData(out IntPtr CommandedRPM, out IntPtr MeasuredRPM, out IntPtr PIDOut);

Dan
danut1234
 
Posts: 40
Joined: Thu Aug 25, 2022 9:26 am

Re: PID in my own software

Postby cncdrive » Thu Dec 22, 2022 6:33 am

Hi,

That function returns the Measured RPM, the Commanded (programmed) RPM as a pointer.
The pointer points to an integer array.
The motion control API continously updating that array with shifting the data in the array using the newly measured values as the first item in the array and shifting all the rest of the array.
You can use these arrays to for example draw a diagram of the Commanded and Measured RPM.

Please also note that you have to configure and use a spindle encoder for the spindle PID controller to work, without that the PWM will increase to maximum always, because then there is no feedback to control to if there is no encoder connected.
cncdrive
Site Admin
 
Posts: 4887
Joined: Tue Aug 12, 2014 11:17 pm

Re: PID in my own software

Postby danut1234 » Thu Dec 22, 2022 12:49 pm

Index pin is configured and the RPM retrieved is correct, i have stated this in previous post (Stat->SpindleRPM). I did not configured and used a 2 channel (quadrature) encoder because the spindle does not have such a thing. public int EncoderPinA; public int EncoderPinB; are not assigned... is somewhere a setting where i can chose between index pin and encoder pins as PID feedback?

I will try my luck with GetPIDData...

Dan
danut1234
 
Posts: 40
Joined: Thu Aug 25, 2022 9:26 am

Re: PID in my own software

Postby danut1234 » Thu Dec 22, 2022 2:49 pm

int[] arrayRPMcom = new int[500];
IntPtr pointerRPMcom;
IntPtr pointerRPMread;
IntPtr pointerPIDout;

UC100.GetPIDData(out pointerRPMcom, out pointerRPMread, out pointerPIDout);
Marshal.Copy(pointerRPMcom, arrayRPMcom, 0, 500);
textBox9.Text = String.Join("\r\n", arrayRPMcom);

This piece of code returns something like an array of pointers... or other gibberish values... for CommandedRPM and PIDOut. For MeasuredRPM does not return anything, so probably the lack of encoder is the problem, although i have the index pin. In Mach3 the PID works with index pin.

Dan
danut1234
 
Posts: 40
Joined: Thu Aug 25, 2022 9:26 am

Re: PID in my own software

Postby ger21 » Thu Dec 22, 2022 8:45 pm

UCCNC does not work with an index. It requires an encoder.
Gerry
UCCNC 2022 Screenset - http://www.thecncwoodworker.com/2022.html
ger21
 
Posts: 2714
Joined: Sat Sep 03, 2016 2:17 am

Re: PID in my own software

Postby cncdrive » Thu Dec 22, 2022 10:15 pm

Yes, the spindle closed loop PID control and thread cutting and rigid tapping works only with spindle encoder (A, B and Index channels).
cncdrive
Site Admin
 
Posts: 4887
Joined: Tue Aug 12, 2014 11:17 pm

Re: PID in my own software

Postby asuratman » Sat Mar 11, 2023 2:38 am

Yes, the spindle closed loop PID control and thread cutting and rigid tapping works only with spindle encoder (A, B and Index channels).


How many ppr encoder max can be handled by uccnc ?
asuratman
 
Posts: 118
Joined: Sun Jan 28, 2018 1:50 pm

Re: PID in my own software

Postby cncdrive » Sat Mar 11, 2023 2:49 am

About 40kHz encoder max. frequency. The PPR depends on the required spindle max. speed, but you can calculate that from the max. frequency.
cncdrive
Site Admin
 
Posts: 4887
Joined: Tue Aug 12, 2014 11:17 pm

Re: PID in my own software

Postby asuratman » Sat Mar 11, 2023 5:58 am

I just want to make sure for calc. As said max freq encoder max 40000hz, max rpm of motor 1500 rpm,
then encoder required : 40000 x 60/1500 = 1600 ppr.
Is this right ?
asuratman
 
Posts: 118
Joined: Sun Jan 28, 2018 1:50 pm

Re: PID in my own software

Postby cncdrive » Sat Mar 11, 2023 8:35 am

Yes, for a 1500 RPM motor 1600 PPR encoder is the maximum what you can use, because if you use a higher resolution encoder then the controller cannot read the encoder signals properly because the pulses will be too fast, faster than 40kHz.
In practise a 100 PPR encoder do the job basically for everything, it is enough for spindle speed measurement and it is also enough for thread cutting and rigid tapping.
Our spindle encoder handling algorithm implements velocity and acceleration feedforward calculations, so the controller looks ahead to determinate the position with sub encoder counts.
cncdrive
Site Admin
 
Posts: 4887
Joined: Tue Aug 12, 2014 11:17 pm

Next

Return to Ask a question from support here

Who is online

Users browsing this forum: No registered users and 34 guests