Defining duty cycle in twincat 3

萝らか妹 提交于 2020-01-05 04:08:06

问题


for a school project I need to connect a temperature sensor to my beckhoff modules and define the temperature. the sensor I am using is an SMT160-30, it works between 1-4khz, which is cutting it close for standard io modules. I will probably need a special input module made for high speed measurements, but according to my teacher I must be able to do it with a standard module. But I am just having trouble with defining the duty cycle and can't really figure out how to solve it.

  PROGRAM MAIN
  VAR
    sensor AT %I* : BOOL;
    rtrig: R_TRIG;
    tOn: Tof;
    timeActive: TIME;
    ftrig: F_TRIG;
    tOff: Ton;
    timeNActive: TIME;
    dutyCycle: DINT;
    temp: TIME;
  END_VAR

  rtrig(clk := sensor);
  IF(rtrig.Q) THEN
     timeActive := tOn.ET - timeActive;
  END_IF

  tOn(in := rtrig.Q, pt:= T#1S);

  ftrig(clk := sensor);
  IF ftrig.Q THEN
    timeNActive := tOff.ET - timeNActive;
  END_IF
  tOff(in := ftrig.Q, pt:= T#1S);

  //dutyCycle := timeActive / (timeActive + timeNActive);
  //temp := (dutyCycle - 0.32)/0.0047;

this is the code I have so far and according to my teacher i'm heading the right way but i'm really stuck at this point.

hope you can help

best regards.


回答1:


Your timers won't work because the outputs of F_TRIG & R_TRIG are only true for the edges of sensor. The timers should get IN := sensor instead of the X_TRIG.Qs.

Furthermore I dont see any sense in the substractions. Why not just save the ETs?

dutyCycle and temp should be REAL variables.

The two commented out lines are correct for the conversion from duty cycle to temperature °C.

Another solution would be to ditch the Timers and just count the plc cycles where sensor is true and false to determine the ratio between Active and nActive.




回答2:


If I may. I would not use active inactive time for duty as only active front and frequency are needed from my point of view and that's just because your inactive time could be century if your line is broken. If you get a problem with your signal your result will be badly wrong with active inactive time. With active time and frequency (1/(time between two rising edge)) you will be able to see that your signal is still alive. Not a big deal for a sensor but for something more powerfull it would avoid risk to crash something if your line is broken. first you check that your signal is alive and after that you calculate your results.

If it helps. have a nice day



来源:https://stackoverflow.com/questions/37385495/defining-duty-cycle-in-twincat-3

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!