RP Store Tìm linh kiện theo mã, gửi BOM nhận báo giá Gửi BOM

[GIÚP ĐỠ] Về Code điều khiển tốc độ ENCODER

Collapse
X
 
  • Giờ
  • Show
Clear All
new posts
  • longhinhquyen11
    Nhập môn đệ tử
    • Oct 2015
    • 4

    #1

    [GIÚP ĐỠ] Về Code điều khiển tốc độ ENCODER

    #include "E:\aaaaa\PIC\VD\VD5.h"

    int8 duty=0, pulse=0;
    #int_RB
    void RB_isr(void)
    {

    if (pulse==105)
    duty=614;
    else
    {duty=614;
    while(pulse < 105)
    {duty=duty+10;
    }
    }
    }






    void main()
    {

    setup_adc_ports(NO_ANALOGS|VSS_VDD);
    setup_adc(ADC_CLOCK_DIV_2);
    setup_spi(SPI_SS_DISABLED);
    setup_timer_0(RTCC_EXT_L_TO_H|RTCC_DIV_256);
    setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
    set-timer0(0);
    setup_timer_2(T2_DIV_BY_16,255,1);
    setup_ccp1(CCP_PWM);
    set_pwm1_duty(1023);
    setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard

    RB_INT_EDGE(B4,L_TO_H);
    enable_interrupts(INT_RB);
    enable_interrupts(GLOBAL);
    output_D(0x01);
    //TODO: User Code
    WHILE(1)
    {if ((input(Pin_B4))==0)
    pulse++;

    set_pwm1_duty(duty);
    }
    }


    #### Xin cho em hỏi, đây là code em dùng để điều khiển encoder để xác định tốc độ của DC motor. ý nghĩa là nếu Motor DC không tải thì vận tốc đạt được bằng với vận tốc lúc DC MOTOR ở trạng thái có tải.
    Em chọn tốc độ là hằng số. Moi người cho em xin hỏi là code như vậy sai chỗ nào, giải thuật có bị nhầm lẫn không mà em cho vận hành thì không cho kết quả đúng.
    XIn mọi người giúp đỡ ạ
Working...