久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 1412|回復: 8
收起左側

關于Arduino驅動步進電機驅動器控制步進電機導致電機跑飛問題

[復制鏈接]
ID:486153 發表于 2024-8-11 12:52 | 顯示全部樓層 |閱讀模式
最近在做一個項目,主要內容是,通過Arduino Mega2560控制3個步進電機驅動器,進而控制步進電機實現帶目標物進行移動。代碼中使用了定時器中斷,1KHZ的頻率訪問定時器,再通過串口,發送指令,控制步進電機進行移動。在幾乎快調試完成后,發現一個重大問題,在有時候突然發送指令時,步進電機會不受控制的跑飛,除非再次發送指令,不然步進電機會一直按照某種異常的速度不停移動。

步進電機是通過驅動器進行控制的,所以只需要DIR和PUL兩個腳控制即可,PUL脈沖波形的頻率在正常情況下,我只給到了400HZ,50%占空比。在異常情況下,頻率會突然飚的很高,達到了幾KHZ,但是程序中沒有代碼讓他按照此種頻率運行。

而且該問題出現的時機是偶然的,都在串口發送完指令,Arduino接受解析完指令,再控制步進電機是出現,概率很高。

不知道有沒有大佬遇到類似情況,給小弟指條明路,由于是第一次使用Arduino 開發項目,代碼還是參考網上的。

定時器中斷部分代碼
timer.png
串口接收數據 部分代碼
uart.png
回復

使用道具 舉報

ID:161164 發表于 2024-8-12 10:20 | 顯示全部樓層
UART_RX_DATA_SIZE沒加限制嗎?
回復

使用道具 舉報

ID:486153 發表于 2024-8-12 15:43 | 顯示全部樓層
lkc8210 發表于 2024-8-12 10:20
UART_RX_DATA_SIZE沒加限制嗎?

沒有加限制,但是會在函數最后結束的時候 把它清零
回復

使用道具 舉報

ID:844772 發表于 2024-8-12 15:45 | 顯示全部樓層
應該是沖突造成的,看發出來的又沒啥問題,需要相對完整的程序和電路圖。
回復

使用道具 舉報

ID:486153 發表于 2024-8-12 15:52 | 顯示全部樓層
glinfei 發表于 2024-8-12 15:45
應該是沖突造成的,看發出來的又沒啥問題,需要相對完整的程序和電路圖。
  1. void System_IO_Init()
  2. {
  3.   pinMode(DIR_pin,    OUTPUT);
  4.   pinMode(DIR2_pin,    OUTPUT);
  5.   pinMode(DIR3_pin,    OUTPUT);
  6.   pinMode(PUL_pin,    OUTPUT);
  7.   pinMode(PUL2_pin,    OUTPUT);
  8.   pinMode(PUL3_pin,    OUTPUT);
  9.   pinMode(ENA_pin,    OUTPUT);
  10.   pinMode(ENA2_pin,    OUTPUT);
  11.   pinMode(ENA3_pin,    OUTPUT);

  12.   pinMode(STOPPER_x_pin,    INPUT_PULLUP);
  13.   pinMode(STOPPER_x_2_pin,    INPUT_PULLUP);
  14.   pinMode(STOPPER_y_pin,    INPUT_PULLUP);
  15.   pinMode(STOPPER_y_2_pin,    INPUT_PULLUP);
  16.   pinMode(STOPPER_z_pin,    INPUT_PULLUP);
  17.   
  18.   digitalWrite( DIR_pin, HIGH);   //HIGH 左  x軸
  19.   digitalWrite( ENA_pin, LOW);

  20.   digitalWrite( DIR2_pin, HIGH);   //HIGH 左
  21.   digitalWrite( ENA2_pin, LOW);

  22.   digitalWrite( DIR3_pin, HIGH);   //HIGH 左
  23.   digitalWrite( ENA3_pin, LOW);
  24. }

  25. void Timer_Init()
  26. {
  27.   cli();////關閉全局中斷

  28. //Timer 1
  29. //設置定時器1為1kHz
  30.   TCCR1A = 0;//將整個TCCR1A寄存器設置為0
  31.   TCCR1B = 0;//將整個TCCR1B寄存器設置為0
  32.   TCNT1  = 0;//將計數器值初始化為0
  33.   //設置計數器為10kHZ,即1ms
  34.   OCR1A = 19;// = (16*10^6)/(1000*8) - 1 (must be <65536)
  35.   TCCR1B |= (1 << WGM12);//打開CTC模式
  36.   TCCR1B |= (1 << CS11);//設置CS11位為1(8倍預分頻)
  37.   TIMSK1 |= (1 << OCIE1A);

  38.   //Timer 3
  39. //設置定時器3為1kHz
  40.   TCCR3A = 0;//將整個TCCR1A寄存器設置為0
  41.   TCCR3B = 0;//將整個TCCR1B寄存器設置為0
  42.   TCNT3  = 0;//將計數器值初始化為0
  43.   //設置計數器為10kHZ,即1ms
  44.   OCR3A = 19;// = (16*10^6)/(1000*8) - 1 (must be <65536)
  45.   TCCR3B |= (1 << WGM32);//打開CTC模式
  46.   TCCR3B |= (1 << CS31);//設置CS11位為1(8倍預分頻)
  47.   TIMSK3 |= (1 << OCIE3A);

  48.    sei();//打開全局中斷
  49. }

  50. void return_weizhi()
  51. {
  52.   int test=1;
  53.   digitalWrite( DIR_pin, LOW);   //HIGH 左  LOW 右
  54.   digitalWrite( DIR2_pin, LOW);
  55.   while(test)
  56.   {
  57.     while(((PINH & (B00100000)) == 32)||((PING & (B00100000)) == 32))
  58.     {
  59.       if((PINH & (B00100000)) == 32)
  60.         y_flag=1;
  61.       else
  62.        y_flag=0;
  63.       if((PING & (B00100000)) == 32)
  64.         x_flag=1;
  65.       else
  66.         x_flag=0;
  67. //       Serial.println("555");
  68.       if(((PINH & (B00100000)) == 0)&&((PING & (B00100000)) == 0))
  69.       {
  70.         delay(100);
  71. //       Serial.println("444");
  72.         if(((PINH & (B00100000)) == 0)&&((PING & (B00100000)) == 0))
  73.         {
  74.           delay(100);
  75.           if(((PINH & (B00100000)) == 0)&&((PING & (B00100000)) == 0))
  76.           {
  77.             x_flag=0;
  78.             y_flag=0;
  79.             x_pos=0;
  80.             y_pos=0;
  81.             Serial.println("{X000000-Y000000}");
  82.             test=0;
  83.             break;
  84.           }
  85.         }
  86.       }
  87.     }
  88.     test=0;
  89.   }
  90. }

  91. void setup() { // put your setup code here, to run once:
  92.   System_IO_Init();
  93.   Timer_Init();
  94.   Serial.begin(115200);
  95.   return_weizhi();     //系統返回原點
  96. }

  97. void SET_MOTOR_rotation(long num,long speed_motor)   //設置固定轉多少圈,用于測試
  98. {
  99.   for(i=0;i<num;i++)
  100.   {
  101.     digitalWrite( PUL_pin, HIGH);
  102.     delayMicroseconds(speed_motor);
  103.     digitalWrite( PUL_pin, LOW);
  104.     delayMicroseconds(speed_motor);
  105.   }
  106. }


  107. ISR(TIMER1_COMPA_vect)   //定時器1,用于觸發x,y軸電機轉動
  108. {
  109. //產生頻率為1Hz / 2 = 0.5Hz的脈沖波(全波切換為兩個周期,然后切換為低)
  110.   if(x_motor_en==1&&x_position<=11800)
  111.   {
  112.     if(time_pul1<x_position)
  113.     {
  114.       if(toggle1<15)
  115.         digitalWrite(PUL_pin,HIGH);
  116.       if(toggle1>=15)
  117.         digitalWrite(PUL_pin,LOW);
  118.         
  119.       toggle1 += 1;
  120.       if((motor1_time_set>motor1_time)&&time_pul1%16==1)  //加速
  121.         motor1_time_set-=1;

  122.       if(toggle1 > 15*2)  
  123.       {
  124.         toggle1 = 0;
  125.         if(x_fangxiang)
  126.           x_pos++;
  127.         else
  128.           x_pos--;
  129.         time_pul1++;
  130.       }
  131.     }
  132.     else
  133.     {
  134.       pinMode(PUL_pin,    INPUT_PULLUP);
  135.      
  136.       time_pul1=0;
  137.       x_motor_en=0;
  138.        sdsf++;
  139.        reback_weizhi_flag=1;
  140.       }
  141.   }

  142.   if(x_flag==1&&(digitalRead(STOPPER_y_pin) == 1))
  143.   {
  144.    
  145.       if(toggle1<30)
  146.         digitalWrite(PUL_pin,HIGH);
  147.       if(toggle1>=30)
  148.         digitalWrite(PUL_pin,LOW);
  149.       toggle1 += 1;
  150.       if(toggle1 > 30*2)
  151.       {
  152.         toggle1 = 0;
  153.       }
  154.   }
  155.   
  156.   if(y_motor_en==1&&y_position<=11000)
  157.   {
  158.     if(time_pul2<y_position)  //5.4cm 54mm
  159.     {
  160.       if(toggle2<15)
  161.         digitalWrite(PUL2_pin,HIGH);
  162.       if(toggle2>=15)
  163.         digitalWrite(PUL2_pin,LOW);
  164.       toggle2 += 1;

  165.       if((motor2_time_set>motor2_time)&&time_pul2%16==1)   //加速
  166.         motor2_time_set-=1;
  167.       
  168.       if(toggle2 > 15*2)
  169.       {
  170.         toggle2 = 0;
  171.         if(y_fangxiang)
  172.           y_pos++;
  173.         else
  174.           y_pos--;
  175.         time_pul2++;
  176.       }
  177.     }
  178.     else
  179.     {
  180.       pinMode(PUL2_pin,    INPUT_PULLUP);
  181.      
  182.       time_pul2=0;
  183.       y_motor_en=0;
  184.       sdsf++;
  185.       reback_weizhi_flag=1;
  186.     }
  187.   }

  188.   if(y_flag==1&&(digitalRead(STOPPER_x_pin) == 1))
  189.   {   
  190.       if(toggle2<30)
  191.         digitalWrite(PUL2_pin,HIGH);
  192.       if(toggle2>=30)
  193.         digitalWrite(PUL2_pin,LOW);
  194.       toggle2 += 1;
  195.       if(toggle2 > 30*2)
  196.       {
  197.         toggle2 = 0;
  198.       }
  199.   }
  200. }


  201. ISR(TIMER3_COMPA_vect)   //定時器3,用于觸發z軸電機轉動
  202. {
  203. // timer3中斷1Hz切換引腳9
  204. //產生頻率為1Hz / 2 = 0.5Hz的脈沖波(全波切換為兩個周期,然后切換為低)
  205.   
  206.   if(z_motor_en==1&&z_position<=5000)
  207.   {
  208.     if(time_pul3<z_position)  //5.4cm 54mm
  209.     {
  210. //      if(toggle3<15)
  211. //        digitalWrite(PUL3_pin,HIGH);
  212. //      if(toggle3>=15)
  213. //        digitalWrite(PUL3_pin,LOW);
  214. //      toggle3 += 1;
  215. //
  216. //      if((motor2_time_set>motor2_time)&&time_pul3%16==1)   //加速
  217. //        motor2_time_set-=1;
  218. //      
  219. //      if(toggle3 > 15*2)
  220. //      {
  221. //        toggle3 = 0;
  222. //        if(z_fangxiang)
  223. //          z_pos++;
  224. //        else
  225. //          z_pos--;
  226. //        time_pul3++;
  227. //      }
  228.     }
  229.     else
  230.     {
  231. //      time_pul3=0;
  232. //      z_motor_en=0;
  233. //      sdsf++;
  234. //      reback_weizhi_flag=1;
  235.     }
  236.   }
  237. }




  238. void goto_setposition(long x_now,long y_now)
  239. {
  240.   /*
  241.   int x_position_pass=0;      //上一次的x軸位置坐標
  242. int y_position_pass=0;      //上一次的y軸位置坐標
  243. int x_position_now=0;       //當前的x軸位置坐標
  244. int y_position_now=0;       //當前的y軸位置坐標
  245. int x_position=10;           //x軸位置坐標
  246. int y_position=10;           //z軸位置坐標
  247.   */

  248.   
  249.   if(x_now!=0)
  250.   {
  251.     x_position_now=x_now;
  252.     if(x_position_pass-x_position_now>0)
  253.     {
  254.       digitalWrite(DIR_pin,LOW);   //設置方向
  255.       x_fangxiang=0;
  256.       x_position=x_position_pass-x_position_now;  //計算步距
  257.       return_x_position=x_position;
  258.       x_position_pass=x_position_now;
  259.       x_motor_en=1;
  260.     }
  261.     else
  262.     {
  263.       digitalWrite(DIR_pin,HIGH);   //設置方向
  264.       x_fangxiang=1;
  265.       x_position=x_position_now-x_position_pass;  //計算步距
  266.       x_position_pass=x_position_now;
  267.       x_motor_en=1;
  268.     }
  269.   }

  270.   if(y_now!=0)
  271.   {
  272.     y_position_now=y_now;
  273.     if(y_position_pass-y_position_now>0)
  274.     {
  275.       digitalWrite(DIR2_pin,LOW);   //設置方向
  276.       y_fangxiang=0;
  277.       y_position=y_position_pass-y_position_now;  //計算步距
  278.       y_position_pass=y_position_now;
  279.       y_motor_en=1;
  280.     }
  281.     else
  282.     {
  283.       digitalWrite(DIR2_pin,HIGH);   //設置方向
  284.       y_fangxiang=1;
  285.       y_position=y_position_now-y_position_pass;  //計算步距
  286.       y_position_pass=y_position_now;
  287.       y_motor_en=1;
  288.     }
  289.   }
  290. }

  291. void sys_auto_move()
  292. {
  293.   if(sdsf==2)
  294.   {

  295.     if(!switch_flag)
  296.     Location_label++;
  297.     else
  298.     Location_label--;
  299.    
  300.     if(Location_label>12)
  301.     {
  302.       Location_label=12;
  303.       switch_flag=!switch_flag;
  304.     }
  305.     if(Location_label<1)
  306.     {
  307.       Location_label=1;

  308. //////////////////////////////////////////
  309.       auto_manual_flag=0;
  310.       delay(1000);
  311.       delay(1000);
  312.       pinMode(PUL_pin,    OUTPUT);
  313.       pinMode(PUL2_pin,    OUTPUT);
  314.       return_weizhi();
  315.       x_position_now=0;
  316.       y_position_now=0;
  317.       x_position_pass=0;
  318.       y_position_pass=0;
  319.       x_pos=0;
  320.       y_pos=0;
  321.       Serial.print("{D0}\r\n");

  322.       delay(1000);
  323.       delay(1000);
  324.       delay(1000);
  325.       delay(1000);

  326.       auto_manual_flag=1;
  327.       auto_move_flag=1;
  328.       sdsf=0;
  329. ///////////////////////////////////////////////
  330.       
  331.       switch_flag=!switch_flag;
  332.       cishu_cishu++;
  333.     }
  334.     sdsf=0;
  335.     auto_move_flag=1;
  336.     delay(1000);
  337.     delay(1000);
  338.     delay(1000);
  339.     delay(1000);
  340.     delay(1000);
  341.   }

  342.   if(auto_move_flag==1)
  343.   {
  344.     pinMode(PUL_pin,    OUTPUT);
  345.     pinMode(PUL2_pin,    OUTPUT);
  346.     switch(Location_label)
  347.     {
  348.       case 1:  actual_weizhi=1;goto_setposition(1500,hang1);auto_move_flag=0; break;
  349.       case 2:  actual_weizhi=2;goto_setposition(1500+1500,hang1); auto_move_flag=0;break;
  350.       case 3:  actual_weizhi=3;goto_setposition(1500+1500*2,hang1); auto_move_flag=0;break;
  351.       case 4:  actual_weizhi=4;goto_setposition(1500+1500*3,hang1); auto_move_flag=0;break;
  352.       
  353.       case 8:  actual_weizhi=5;goto_setposition(1500,hang2);auto_move_flag=0; break;
  354.       case 7:  actual_weizhi=6;goto_setposition(1500+1500,hang2); auto_move_flag=0;break;
  355.       case 6:  actual_weizhi=7;goto_setposition(1500+1500*2,hang2); auto_move_flag=0;break;
  356.       case 5:  actual_weizhi=8;goto_setposition(1500+1500*3,hang2); auto_move_flag=0;break;
  357.      
  358.       case 9:  actual_weizhi=13;goto_setposition(1500,hang3);auto_move_flag=0; break;
  359.       case 10:  actual_weizhi=14;goto_setposition(1500+1500,hang3); auto_move_flag=0;break;
  360.       case 11:  actual_weizhi=15;goto_setposition(1500+1500*2,hang3); auto_move_flag=0;break;
  361.       case 12:  actual_weizhi=16;goto_setposition(1500+1500*3,hang3); auto_move_flag=0;break;
  362.     }
  363.   }
  364. }

  365. void data_pro()    //串口數據接受與處理
  366. {
  367.   if(Serial.available()>0)
  368.   {
  369.     receive_buf[UART_RX_DATA_SIZE]=Serial.read();
  370.     if(receive_buf[UART_RX_DATA_SIZE]=='}')
  371.     {
  372.       UAER_RX_FLAG=1;
  373.       i_uart=0;
  374.     }
  375.     UART_RX_DATA_SIZE++;
  376.    
  377.   }
  378.   else if(UAER_RX_FLAG)
  379.   {
  380.     UAER_RX_FLAG=0;
  381.     #if UART_DEBUG
  382.     Serial.println(receive_buf);
  383.     #endif
  384.     while(i_uart<UART_RX_DATA_SIZE)
  385.     {
  386.       if(receive_buf[i_uart]=='{')  //{A0}
  387.       {
  388.         if(receive_buf[i_uart+1]=='A'&&receive_buf[i_uart+3]=='}')   //收到上位機發送的HALLO指令
  389.         {
  390.             Serial.print("{B0}\r\n");
  391.             i_uart+=3;
  392.         }
  393.         else if(receive_buf[i_uart+1]=='C'&&receive_buf[i_uart+3]=='}')  //全部軸歸回原點
  394.         {
  395.           pinMode(PUL_pin,    OUTPUT);
  396.           pinMode(PUL2_pin,    OUTPUT);
  397.           return_weizhi();
  398.           x_position_now=0;
  399.           y_position_now=0;
  400.           x_position_pass=0;
  401.           y_position_pass=0;
  402.           x_pos=0;
  403.           y_pos=0;
  404.           Serial.print("{D0}\r\n");
  405.           i_uart+=3;
  406.         }
  407.         else if(receive_buf[i_uart+1]=='E'&&receive_buf[i_uart+13]=='}')  //{EX000400-010}
  408.         {
  409.           pinMode(PUL_pin,    OUTPUT);
  410.           pinMode(PUL2_pin,    OUTPUT);
  411.           if(receive_buf[i_uart+2]=='X')
  412.           {
  413.             x_position_uart=(receive_buf[i_uart+3]-'0')*100000+(receive_buf[i_uart+4]-'0')*10000+(receive_buf[i_uart+5]-'0')*1000+(receive_buf[i_uart+6]-'0')*100+(receive_buf[i_uart+7]-'0')*10+(receive_buf[i_uart+8]-'0');
  414.             #if UART_DEBUG
  415.               Serial.println(x_position_uart);
  416.             #endif
  417.             goto_setposition(x_position_uart,0);
  418.             Serial.print("{F0}\r\n");
  419.           }
  420.           else if(receive_buf[i_uart+2]=='Y')
  421.           {
  422.             y_position_uart=(receive_buf[i_uart+3]-'0')*100000+(receive_buf[i_uart+4]-'0')*10000+(receive_buf[i_uart+5]-'0')*1000+(receive_buf[i_uart+6]-'0')*100+(receive_buf[i_uart+7]-'0')*10+(receive_buf[i_uart+8]-'0');
  423.             #if UART_DEBUG
  424.               Serial.println(y_position_uart);
  425.             #endif
  426.             goto_setposition(0,y_position_uart);
  427.             Serial.print("{F0}\r\n");
  428.           }
  429.           i_uart+=13;
  430.          }
  431.          else if(receive_buf[i_uart+1]=='L'&&receive_buf[i_uart+4]=='}')  //{L01}
  432.          {
  433.           int num=(receive_buf[i_uart+2]-'0')*10+(receive_buf[i_uart+3]-'0');
  434.             pinMode(PUL_pin,    OUTPUT);
  435.             pinMode(PUL2_pin,    OUTPUT);
  436.             switch(num)
  437.             {
  438.               case 1:  actual_weizhi=1;goto_setposition(1500,hang1);auto_move_flag=0; break;
  439.               case 2:  actual_weizhi=2;goto_setposition(1500+1500,hang1); auto_move_flag=0;break;
  440.               case 3:  actual_weizhi=3;goto_setposition(1500+1500*2,hang1); auto_move_flag=0;break;
  441.               case 4:  actual_weizhi=4;goto_setposition(1500+1500*3,hang1); auto_move_flag=0;break;
  442.               
  443.               case 5:  actual_weizhi=5;goto_setposition(1500,hang2);auto_move_flag=0; break;
  444.               case 6:  actual_weizhi=6;goto_setposition(1500+1500,hang2); auto_move_flag=0;break;
  445.               case 7:  actual_weizhi=7;goto_setposition(1500+1500*2,hang2); auto_move_flag=0;break;
  446.               case 8:  actual_weizhi=8;goto_setposition(1500+1500*3,hang2); auto_move_flag=0;break;
  447.             
  448.               case 9:  actual_weizhi=13;goto_setposition(1500,hang3);auto_move_flag=0; break;
  449.               case 10:  actual_weizhi=14;goto_setposition(1500+1500,hang3); auto_move_flag=0;break;
  450.               case 11:  actual_weizhi=15;goto_setposition(1500+1500*2,hang3); auto_move_flag=0;break;
  451.               case 12:  actual_weizhi=16;goto_setposition(1500+1500*3,hang3); auto_move_flag=0;break;
  452.               
  453.             }
  454.             i_uart+=4;
  455.          }
  456.          else if(receive_buf[i_uart+1]=='M'&&receive_buf[i_uart+3]=='}')  //{M0}
  457.          {
  458.           if(receive_buf[i_uart+2]=='1')
  459.           {
  460.               auto_manual_flag=1;
  461.               auto_move_flag=1;
  462.               sdsf=0;
  463.               Serial.println("auto_mode");
  464.           }
  465.           else
  466.           {
  467.               auto_manual_flag=0;
  468.           }
  469.           i_uart+=3;
  470.          }
  471.          else if(receive_buf[i_uart+1]=='F'&&receive_buf[i_uart+8]=='}')  //{F0_2500}  設定相機焦距
  472.          {
  473.             //步進值 16位
  474.             //左右旋轉標志位 Direction_flag
  475.             direction_flag=receive_buf[i_uart+2]-0x30;
  476.             Serial.println(direction_flag);
  477.             focal_step_value=(receive_buf[i_uart+4]-0x30)*1000+(receive_buf[i_uart+5]-0x30)*100+(receive_buf[i_uart+6]-0x30)*10+(receive_buf[i_uart+7]-0x30);
  478.             focal_step_value=focal_step_value/10;
  479.             Serial.println(focal_step_value);
  480.             z_motor_en=1;
  481.             
  482.               if(direction_flag==0)
  483.               {
  484.                 z_position=focal_step_value;
  485.                 digitalWrite(DIR3_pin,HIGH);
  486.                
  487.               }
  488.               else if(direction_flag==1)
  489.               {
  490.                 z_position=focal_step_value;
  491.                 digitalWrite(DIR3_pin,LOW);
  492.                
  493.               }
  494.              i_uart+=8;
  495.          }
  496.          
  497.         
  498.       }
  499.       i_uart++;
  500.     }
  501.     for(i=0;i<UART_RX_DATA_SIZE;i++)
  502.       receive_buf[i]=' ';
  503.     UART_RX_DATA_SIZE=0;
  504.   }
  505. }


  506. void loop()
  507. {
  508.   data_pro();

  509. //  if(digitalRead(STOPPER_x_pin)==1)
  510. //    Serial.println("111");
  511. //   else
  512. //    Serial.println("222");
  513.    
  514.   if(auto_manual_flag)
  515.   {
  516.     sys_auto_move();
  517.   }
  518.   if(reback_weizhi_flag)
  519.   {
  520.      sprintf(weizhi_data,"{X%06ld-Y%06ld-L%02d}",x_pos,y_pos,actual_weizhi);
  521.      Serial.println(weizhi_data);
  522.      reback_weizhi_flag=0;
  523.   }
  524.   delay(100);
  525. }
復制代碼

這是所有程序了
回復

使用道具 舉報

ID:486153 發表于 2024-8-12 15:54 | 顯示全部樓層
glinfei 發表于 2024-8-12 15:45
應該是沖突造成的,看發出來的又沒啥問題,需要相對完整的程序和電路圖。

主要就是串口接收到指令,一些變量置1,然后定時器那邊見到變量置1,開始發送脈沖,記錄指定脈沖數后,自動置零,等待下次
回復

使用道具 舉報

ID:1128898 發表于 2024-8-12 20:47 | 顯示全部樓層
有些驅動廠家會有詳細的手冊 編程應對應驅動信號
回復

使用道具 舉報

ID:161164 發表于 2024-8-13 10:24 | 顯示全部樓層
小楓啊 發表于 2024-8-12 15:43
沒有加限制,但是會在函數最后結束的時候 把它清零

但是你receive_buf的長度有多大?
UART_RX_DATA_SIZE會不會有機會大于receive_buf的長度引致地址溢出?
回復

使用道具 舉報

ID:844772 發表于 2024-8-13 16:35 | 顯示全部樓層
我覺得,如果arduino就按它的玩法,都用庫函數解決,不要混用單片機的程序思路,特別是沒研究底層結構,嵌入寄存器控制部分,經常有沖突。比如上邊的時間中斷,就不要使用寄存器控制,否則不如直接用32呢;還有明明有String 類型,定義成數組是留隱患呢。另外別在時間中斷函數放那么多東西啊。
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 国产精彩视频一区 | 日本成年免费网站 | 天天干天天爱天天爽 | 日韩中文字幕在线播放 | 日韩一区二区三区四区五区 | 国产高清在线精品一区二区三区 | www.久久久.com| 国产不卡在线观看 | 国产特黄一级 | 操夜夜| 国产在线精品一区二区 | 精品欧美一区免费观看α√ | 日日干日日色 | 最新日韩在线 | 精品视频导航 | 免费观看一级特黄欧美大片 | 日韩欧美在线观看视频 | 韩日免费视频 | 91精品国产综合久久小仙女图片 | 爱草在线 | 91在线观看免费视频 | 国产97碰免费视频 | 久久人操 | 激情小说综合网 | 国产精品视频在线播放 | 国产精品久久久久久久毛片 | 国产精品成人在线 | 亚洲成人午夜在线 | 91视频免费视频 | 久久爱综合| 黄色一级大片在线观看 | 中文字幕99| 在线精品亚洲欧美日韩国产 | 国产在线一区二区三区 | 国产精品一区在线观看 | 欧美一区免费 | 欧美日韩在线精品 | 亚洲一区视频在线 | 国产欧美一区二区三区日本久久久 | www.亚洲视频 | 激情91|