銆怌odesys銆慏INT绫诲瀷鐜舰璁℃暟澶勭悊锛岃鏁板埌2鐨64娆℃柟-CODESYS璧勬簮涓嬭浇鍖-閰峰痉缃 - CoDeSys杞欢鏁欑▼涓嬭浇,CoDeSys宸ユ帶璧勮闂ㄦ埛
HSC6490-cn涓浗鍒堕狅紝涓浗鑺瘇
鏌ョ湅: 84|鍥炲: 0

銆怌odesys銆慏INT绫诲瀷鐜舰璁℃暟澶勭悊锛岃鏁板埌2鐨64娆℃柟

[澶嶅埗閾炬帴]
  • TA鐨勬瘡鏃ュ績鎯
    寮蹇
    2017-11-20 22:07
  • 绛惧埌澶╂暟: 2 澶

    [LV.1]鍒濇潵涔嶅埌

    鍙戣〃浜 2024-11-6 20:02:14 | 鏄剧ず鍏ㄩ儴妤煎眰 |闃呰妯″紡
    鏈杩戞湁閬囧埌缂栫爜鍣ㄨ鏁扮殑璁℃暟澶勭悊锛屾姄鍙栫紪鐮佸櫒閿佸瓨鐨勬暟鍊煎彧鑳藉湪DINT绫诲瀷鑼冨洿鍐咃紝鏄粠-2147483648鍒2147483647鏁板硷紝浣嗘槸鐜板満浼氭湁姝e悜澶氬湀鐨勬儏鍐点傛鏃堕渶瑕佽褰曡繖涓暟鐨勪綅缃笺傚氨闇瑕佽褰曞鍦堣鏁颁笅锛屽湀鏁扮殑澶勭悊銆
    PROGRAM FB_DintCirAcc
    VAR  
         currentCount :  DINT; // 褰撳墠璁℃暟鍣ㄧ殑鍊,DINT绫诲瀷鐨勮寖鍥存槸浠-2147483648鍒2147483647
         circle1 : ULINT := 0; // 缁忚繃鐨勬瀬闄愬煎湀鏁  
         circle2 : ULINT := 0; // 缁忚繃鐨勪竴娆16浣嶆渶澶у肩殑鍦堟暟
         maxThreshold :  DINT := 2147470000; // 鎺ヨ繎鏈澶у肩殑闃堝  
         minThreshold :  DINT := -2147470000; // 鎺ヨ繎鏈灏忓肩殑闃堝  
         ZeroThreshold :  DINT := -10000; // 鎺ヨ繎闆跺肩殑闃堝  
         approachingMax :  BOOL := FALSE; // 鏍囧織浣嶏紝琛ㄧず鏄惁鎺ヨ繎鏈澶у  
         approachingMin :  BOOL := FALSE; // 鏍囧織浣嶏紝琛ㄧず鏄惁鎺ヨ繎鏈灏忓  
         approachingZero :  BOOL := FALSE; // 鏍囧織浣嶏紝琛ㄧず鏄惁鎺ヨ繎闆跺
         LastCount: DINT;//璁板綍涓婁竴鍛ㄧ殑璁℃暟銆
         bInit: BOOL:=TRUE;  //鍒濆鍖
         bCountStrat: BOOL;    //妯℃嫙寮濮嬪懆鏈熻鏁
         EncoderPos: LREAL;//缂栫爜鍣ㄤ綅缃
         CalcPos: LREAL;//璁℃暟鍊肩疮鍔犱綅缃
         ulCurrentCount:ULINT;//绱姞璁℃暟鍊
         DiffData: DINT;//璐熷悜绱姞宸
         UlCirData: ULINT;//璐熷悜鏃跺湀鏁板
    END_VAR  

    //妯℃嫙鍏堢粰鏈澶у硷紝璺戝埌绗竴鍦堢殑鏈澶у
    IF bInit THEN
         currentCount:=2147400000;
         Encoder.diEncoderPosition:=currentCount;
         bInit:=FALSE;
    END_IF
    // 鍋囪currentCount鍦ㄦ瘡涓懆鏈熸洿鏂  
    IF bCountStrat THEN
         currentCount := currentCount+10000;  
         Encoder.diEncoderPosition:=currentCount;
    END_IF

    // 妫娴嬫槸鍚︽帴杩戞渶澶у兼垨鏈灏忓  
    IF (currentCount > maxThreshold) AND NOT approachingMax THEN  
         // 寮濮嬫帴杩戞渶澶у  
         approachingMax := TRUE;  
    ELSIF currentCount>0 AND  (currentCount <= maxThreshold) AND approachingMax THEN  
         // 涓嶅啀鎺ヨ繎鏈澶у  
         approachingMax := FALSE;  
    END_IF  
    // 妫娴嬫槸鍚︽帴杩戞渶澶у兼垨鏈灏忓
    IF (currentCount < minThreshold) AND NOT approachingMin THEN  
         // 寮濮嬫帴杩戞渶灏忓  
         approachingMin := TRUE;  
    ELSIF currentCount<0 AND (currentCount >= minThreshold) AND approachingMin THEN  
         // 涓嶅啀鎺ヨ繎鏈灏忓  
         approachingMin := FALSE;  
    END_IF  
    // 妫娴嬭礋鍊肩疮鍔犳槸鍚︽帴杩0鍊笺  
    IF (currentCount < ZeroThreshold)
         AND (currentCount>(ZeroThreshold*2))
         AND NOT approachingZero THEN  
         // 寮濮嬫帴杩戞渶灏忓  
         approachingZero := TRUE;  
    END_IF  
    // 妫娴嬫槸鍚︿粠鎺ヨ繎鏈澶у艰繃娓″埌鎺ヨ繎鏈灏忓硷紝绱姞涓娆¤鏁
    IF approachingMax AND approachingMin THEN  
         // 浠庢渶澶у艰繃娓″埌鏈灏忓硷紝璁′负涓鍦  
         circle1 := circle1 + 1;  
         circle2    := circle2 + 1;
         approachingMax := FALSE; // 閲嶇疆鎺ヨ繎鏈澶у肩殑鏍囧織  
         approachingMin := FALSE; // 閲嶇疆鎺ヨ繎鏈灏忓肩殑鏍囧織  
    END_IF  
    // 妫娴嬫槸鍚︿粠鎺ヨ繎0鍊硷紝绱姞涓娆¤鏁
    IF approachingZero AND currentCount>0 THEN
         circle2    := circle2 + 1;
         approachingZero:=FALSE;
    END_IF
    Encoder.iTurn;
    IF  circle1 = 0 THEN
         ulCurrentCount:=(currentCount);
    ELSE
         IF currentCount>0 THEN
             ulCurrentCount:=(circle2*2147483647)+DINT_TO_ULINT(currentCount);
         ELSE
             IF circle1=1 THEN
                 DiffData:=ABS((2147483647-currentCount));
                 UlCirData:=(circle1*2147483647);
                 ulCurrentCount:=DINT_TO_ULINT(DiffData)+UlCirData;
             ELSIF circle1>1 THEN
                 DiffData:=ABS((2147483647-currentCount));
                 UlCirData:=(((circle1*2)-1)*2147483647);
                 ulCurrentCount:=DINT_TO_ULINT(DiffData)+UlCirData;
             END_IF
         END_IF
    END_IF
    EncoderPos:=Encoder.fActPosition;
    CalcPos:=(ulCurrentCount*97.456)/10000;

    銆怌odesys銆慏INT绫诲瀷鐜舰璁℃暟澶勭悊锛岃鏁板埌2鐨64娆℃柟-1.png
    +10
    涓嶈禐涓涓紵
    鎵撹祻榧撳姳涓涓嬶紒
    鍥炲

    浣跨敤閬撳叿 涓炬姤

    鎮ㄩ渶瑕佺櫥褰曞悗鎵嶅彲浠ュ洖甯 鐧诲綍 | 绔嬪嵆娉ㄥ唽 鏂版氮寰崥鐧婚檰

    鏈増绉垎瑙勫垯

    椤堕儴qrcode搴曢儴
    鍏虫敞閰峰痉缃戣闃呭彿锛岃幏鍙栨洿澶氳祫璁紒

    QQ|灏忛粦灞|鎵嬫満鐗|Archiver|閰峰痉璁哄潧 ( 鑻廔CP澶16065247鍙-1 )|缃戠珯鍦板浘

    GMT+8, 2024-11-23 16:35 , Processed in 0.148810 second(s), 60 queries .

    閰峰痉缃

    © 2001-2013 Hicodesys. 鎶鏈敮鎸 by 閰峰痉缃

    蹇熷洖澶 杩斿洖椤堕儴 杩斿洖鍒楄〃