Page 1 of 2

PID in my own software

PostPosted: Wed Dec 21, 2022 4:13 pm
by danut1234
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

Re: PID in my own software

PostPosted: Thu Dec 22, 2022 6:33 am
by cncdrive
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.

Re: PID in my own software

PostPosted: Thu Dec 22, 2022 12:49 pm
by danut1234
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

Re: PID in my own software

PostPosted: Thu Dec 22, 2022 2:49 pm
by danut1234
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

Re: PID in my own software

PostPosted: Thu Dec 22, 2022 8:45 pm
by ger21
UCCNC does not work with an index. It requires an encoder.

Re: PID in my own software

PostPosted: Thu Dec 22, 2022 10:15 pm
by cncdrive
Yes, the spindle closed loop PID control and thread cutting and rigid tapping works only with spindle encoder (A, B and Index channels).

Re: PID in my own software

PostPosted: Sat Mar 11, 2023 2:38 am
by asuratman
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 ?

Re: PID in my own software

PostPosted: Sat Mar 11, 2023 2:49 am
by cncdrive
About 40kHz encoder max. frequency. The PPR depends on the required spindle max. speed, but you can calculate that from the max. frequency.

Re: PID in my own software

PostPosted: Sat Mar 11, 2023 5:58 am
by asuratman
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 ?

Re: PID in my own software

PostPosted: Sat Mar 11, 2023 8:35 am
by cncdrive
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.