Author Topic: Commands to use for reading stepper motor encoder?  (Read 17843 times)

edmund

  • Newbie
  • Posts: 7
  • I love YaBB 1G - SP1!
    • View Profile
Commands to use for reading stepper motor encoder?
« on: January 12, 2003, 10:52:55 PM »
I am new to Trilogic product.  I am trying to program the PLC to receive the feedback pulse signal from the stepper motor. I read the Trilogic help file & i think it is the command "STEPCOUNT", but the PLC software does not recongnize the "STEPCOUNT" command (I had entered the command as such "STEPCOUNT 1".

Please kindly show me the proper command to receive pulse signal from stepper motor encoder?
« Last Edit: December 31, 1969, 04:00:00 PM by 1076562000 »

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3174
    • View Profile
    • Internet Programmable PLCs
Re: Commands to use for reading stepper motor enco
« Reply #1 on: January 13, 2003, 05:38:03 AM »
STEPCOUNT and STEPCOUNTABS are functions, so you have to assign them to some variable:

e.g.  X = STEPCOUNT(1)

the value returned by STEPCOUNT will be stored inside variable X. They cannot be used as statement without an assignment.
« Last Edit: December 31, 1969, 04:00:00 PM by 1076562000 »
Email: support@triplc.com
Tel: 1-877-TRI-PLCS

edmund

  • Newbie
  • Posts: 7
  • I love YaBB 1G - SP1!
    • View Profile
Re: Commands to use for reading stepper motor enco
« Reply #2 on: January 13, 2003, 07:45:50 PM »
Thanks 4 answering my above question!

I got another problem, it is possible to use a PID control with input feedback signal from the stepper motor encoder (detecting changing of speed) to control the time delay? Can you show me the way to do with "TBASIC"?

*the speed of the motor is inversely proportional to the time delay

What is the rules for entering values 4 the Proportional Gain, Integral Gain & the Differential Gain?
« Last Edit: December 31, 1969, 04:00:00 PM by 1076562000 »

edmund

  • Newbie
  • Posts: 7
  • I love YaBB 1G - SP1!
    • View Profile
Re: Commands to use for reading stepper motor enco
« Reply #3 on: January 13, 2003, 08:59:33 PM »
stepspeed 1,2000,20
stepmove 1,5000,10
a=1000
a=stepcount(1)+1
b=1/a*90000+1      
'a is variable for stepcount & b is variable for time delay

IF getTimerSV(1) <> b
      setTimerSV 1, b
   ENDIF

Can i enter the above command to get "a" as the variable for stepcount? But i cannot get the compute/result of "b" from the command "b=1/a*90000+1" because the simulation keep getting a value of zero for "b"?

Pls kindly help me on the above-mentioned problem.
« Last Edit: December 31, 1969, 04:00:00 PM by 1076562000 »

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3174
    • View Profile
    • Internet Programmable PLCs
Re: Commands to use for reading stepper motor enco
« Reply #4 on: January 15, 2003, 07:31:07 PM »
I don't understand what you mean by "PID control" "to control the time delay"?? PID control  generally controls a variable output such as a DAC or PWM output, not for controlling time delay.

Stepper motor controller is an output. There isn't a "stepper motor encoder" in the PLC. In any case, stepper motor motion speed is predefined by the STEPSPEED command and doesn't require feedback to the PLC. The motor usually follows the predefined speed and step signal in its rotation unless there is slippage.
« Last Edit: December 31, 1969, 04:00:00 PM by 1076562000 »
Email: support@triplc.com
Tel: 1-877-TRI-PLCS

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3174
    • View Profile
    • Internet Programmable PLCs
Re: Commands to use for reading stepper motor enco
« Reply #5 on: January 15, 2003, 07:43:09 PM »
The PLC does not process floating point, so when it executes  b = 1/a it will get a zero as long as a is greater than 1.

The correct way of writing the expression is:

   b = 90000/a + 1

Anyway, your function is not workable because you have mixed the STEPCOUNT and STEPMOVE in the same function. STEPMOVE should be executed only once for a move. The STEPCOUNT need to be executed in another custom function which is periodically be triggered by a clock pulse in order to get updates of the actual number of pulses sent out by the stepper motor.

The GETTIMESV function returns the Set Value (SV) of the timer, not the Present Value (PV). You should not need to execute this function more than once to get the timer's Set Value.  If your purpose is to change the timer's PV, then use the TIMERPV[1] = b. I don't really understand what you are trying to achieve in your program fragment, but you should not execute SETTIMERSV too frequently because it writes to the EEPROM and takes up considerable execution time as well as shortening the cycle life of the EEPROM (100K rewrite cycle). SETTIMERSV is really for you to change the preset value of a timer say from an operator interface or potentiometer ocasionally and not meant to be altered dynamically by the PLC program all the time.
« Last Edit: December 31, 1969, 04:00:00 PM by 1076562000 »
Email: support@triplc.com
Tel: 1-877-TRI-PLCS

edmund

  • Newbie
  • Posts: 7
  • I love YaBB 1G - SP1!
    • View Profile
Re: Commands to use for reading stepper motor enco
« Reply #6 on: January 15, 2003, 09:44:20 PM »
(dCusF)1
' The ADC 0 to 4096 correspond to 1.0 to 100.0 seconds.
DM[1]=ADC(1)/40 'connect to the potentiometer.    

   IF getTimerSV(1) <> DM[1]  
      setTimerSV 1, DM[1]      'save data in data memory 1 to Timer SV
   ENDIF

(CusF)2
STEPSPEED 1,DM[2],20  'Just to simulate stepper motor is moving & changing the speed
STEPMOVE 1,100000,10   'with simulated encoder feedback.
A=STEPCOUNTABS(1)       'Analog encoder pulse input(1).

(dCusF)3
A=B
IF A=0 THEN          'A is the variable for STEPCOUNT &
   C=DM[1]           'B is the variable for DELAY timer setting
ELSE                 'A is set 0 for stop to moving position
   C=200000/B
ENDIF

IF getTimerSV(1) <> C
   setTimerSV 1, C
ENDIF

My task is to change the time delay of the timer (in turns activate an output) once there is a change in the speed of the conveyor which is fitted with an encoder.
So when the speed of the conveyor increase,the delay time become shorter.

From my above commands, i am just trying to get a sampling time,say in 1 minute how many stepcounts, so can u suggest a way to do it?

Kindly reply, thanks alot!
« Last Edit: December 31, 1969, 04:00:00 PM by 1076562000 »

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3174
    • View Profile
    • Internet Programmable PLCs
Re: Commands to use for reading stepper motor enco
« Reply #7 on: January 16, 2003, 08:16:37 AM »
As with my many replies to you, the STEPCOUNT executed after STEPMOVE is going to give you zero or STEPCOUNTABS will give you current coordinate. It doesn't work.

Anyway, if you are not really using the stepper motor, then don't use the STEPCOUNT for simulation. You are only confusing yourself unncessarily. Just read the PMON and PULSEFREQUENCY command to check the speed of the motor and then make the adjustment to the timer set value.

If you want to accumulate pulses, then feed your encoder into a HSC. Let it count the pulses itself. You just trigger a 1 minute timer after you clear the HSCPV to zero. When the 1 minute timer times out you will then read the HSCPV[1] to get the total number of pulses counted by the HSC. Just remember, you don't have to execute the HSCPV in order for it to "count". You just execute it to get the end result.
« Last Edit: December 31, 1969, 04:00:01 PM by -1 »
Email: support@triplc.com
Tel: 1-877-TRI-PLCS