Advertisement
Sidsh

UART messages added to Pick and Place+e

Mar 3rd, 2022
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VeriLog 17.18 KB | None | 0 0
  1. module LSA(
  2.     output [7:0]m1,  //motor1                                            PIN_D3
  3.      output [7:0]m1b,
  4.     output [7:0]m2,  //motor2                                            PIN_C3
  5.      output [7:0]m2b,
  6.     input s1,  //12-bit output of ch. 5 (parallel)
  7.     input s2,  //12-bit output of ch. 6 (parallel)
  8.     input s3,  //12-bit output of ch. 7 (parallel)
  9.     input clk_1,    //50 MHz clock
  10.     input reset,
  11.      input [6:0]Clr,
  12.      output Led1,    //Led used to indicate position of bot i.e. node or line
  13.      output Led2,
  14.      output Led3,
  15.      output HL1,        // to control uart
  16.      output [6:0] id,
  17.      output EM,
  18.      output Clr_en,
  19.      output Clr_r
  20.     );
  21.  
  22. reg signed[7:0]error = 0;
  23. reg signed[7:0]difference = 0;
  24. reg signed[7:0]correction = 0;
  25. reg signed[7:0]cumulative_error = 0;
  26. reg signed[7:0]preverror = 0;
  27. reg [4:0]nodecount = -5'd1;     //No. of nodes bot has traversed, initially set to -1
  28. reg flag = 0;  
  29.  
  30. reg led1=0;
  31. reg led2=0;
  32. reg led3=0;
  33.  
  34. reg [7:0]odc =58;     //optimum duty cycle
  35. reg [7:0]mo1 = 50;    // pwm to motor1, initially set to 50
  36. reg [7:0]mo1r= 0;
  37. reg [7:0]mo2 = 50;    // pwm to motor2, initially set to 50
  38. reg [7:0]mo2r= 0;
  39. reg [7:0]ml1 = 50;    // pwm to motor1 when it is on line
  40. reg [7:0]ml1r=0;
  41. reg [7:0]ml2 = 50;    // pwm to motor2 when it is on line
  42. reg [7:0]ml2r=0;
  43. reg [7:0]mn1 = 50;    // pwm to motor1 when it is on node
  44. reg [7:0]mn1r= 0;
  45. reg [7:0]mn2 = 50;    // pwm to motor2 when it is on node
  46. reg [7:0]mn2r= 0;
  47.  
  48. reg [6:0] id1 =0;        //to control uart
  49. reg hl=0;
  50. reg n=0;
  51.  
  52. reg en=0;
  53. reg [1:0]state = 0; //0: arena, 1: pick, 2:place
  54. reg [1:0]path_no = 0;  //no. of path
  55. reg [1:0]path[3:0][11:0];
  56. reg [4:0]path_len[3:0]; //length of each path
  57. reg [1:0]clrPath[8:0][9:0];   //enter 9 S paths in sequence RGB
  58. reg [4:0]clrPathlen[8:0]; //enter 9 S paths length in sequence RGB
  59. reg [1:0]DepPath[8:0][12:0];
  60. reg [4:0]DepPath_len[8:0];
  61.  
  62. reg clr_reset=0;
  63. reg clr_en = 1;  //disable clr detection
  64. reg clr_en1 = 1;  //disable clr detection
  65. reg [1:0]clrsN=0;
  66. reg [2:0]clrs[0:2];
  67. reg [4:0]dest[2:0];
  68. reg [1:0]rcount=3;     //count no. of red color patches
  69. reg [1:0]gcount=0;     //count no. of green color patches
  70. reg [1:0]bcount=0;     //count no. of blue color patches
  71.  
  72. reg flag2=0;
  73. reg flag3=0;
  74.  
  75. reg done = 0;
  76. reg [20:0]delay=0;
  77.     //Arena
  78.  
  79. function automatic pwm;
  80.     input [1:0]n;
  81.     begin
  82.         case(n)
  83.         0:begin
  84.             mn1 = 56;
  85.             mn1r=0;
  86.             mn2 = 56;
  87.             mn2r=0;
  88.           end
  89.         1:begin
  90.             mn1 = 0;
  91.             mn1r=40;
  92.             mn2 = 54;
  93.             mn2r=0;
  94.           end
  95.         2:begin
  96.             mn1 = 54;
  97.             mn1r=0;
  98.             mn2 = 0;
  99.             mn2r=38;
  100.           end
  101.         3:begin
  102.             mn1=0;
  103.             mn1r=odc;
  104.             mn2=odc;
  105.             mn2r=0;
  106.           end
  107.         endcase
  108.         pwm = 1;
  109.      end
  110.     endfunction
  111.  
  112. always @(posedge clk_1) begin
  113. if(clr_en1==0)
  114. begin
  115.     delay<=delay+1;
  116.     if(delay==350000)
  117.     begin
  118.         clr_en<=0;
  119.     end
  120. end else
  121. begin
  122.     delay<=0;
  123. end
  124. if(done == 0)
  125. begin
  126.     state <=0;
  127.     path[0][0] <= 0;
  128.    path[0][1] <= 0;
  129.    path[0][2] <= 0;
  130.    path[0][3] <= 0;
  131.    path[0][4] <= 2;
  132.    path[0][5] <= 0;
  133.    path[0][6] <= 1;
  134.    path[0][7] <= 0;
  135.    path[0][8] <= 1;
  136.    path[0][9] <= 0;
  137.    path[0][10] <= 0;
  138.    
  139.    path[1][0] <= 2;
  140.    path[1][1] <= 0;
  141.    path[1][2] <= 0;
  142.    path[1][3] <= 0;
  143.    path[1][4] <= 1;
  144.    path[1][5] <= 0;
  145.    path[1][6] <= 0;
  146.    path[1][7] <= 1;
  147.    path[1][8] <= 0;
  148.    path[1][9] <= 2;
  149.    path[1][10] <= 2;
  150.  
  151.    path[2][0] <= 1;
  152.    path[2][1] <= 0;
  153.    path[2][2] <= 1;
  154.    path[2][3] <= 1;
  155.     path[2][4] <= 0;
  156.    path[2][5] <= 1;
  157.    path[2][6] <= 0;
  158.    path[2][7] <= 2;
  159.    
  160.    path[3][0] <= 1;
  161.    path[3][1] <= 0;
  162.    path[3][2] <= 1;
  163.    path[3][3] <= 0;
  164.     path[3][4] <= 1;
  165.    path[3][5] <= 0;
  166.    path[3][6] <= 1;
  167.    path[3][7] <= 0;
  168.    path[3][8] <= 2;
  169.    path[3][9] <= 2;
  170.    path[3][10] <= 0;
  171.    path[3][11] <= 0;  
  172.    
  173.    path_len[0] <= 10;
  174.    path_len[1] <= 10;
  175.    path_len[2] <= 7;
  176.    path_len[3] <= 11;
  177.    
  178.     clrPath[0][0] <= 0;
  179.     clrPath[0][1] <= 1;
  180.     clrPath[0][2] <= 3;
  181.     clrPath[0][3] <= 2;
  182.     clrPath[0][4] <= 0;
  183.  
  184.     clrPath[1][0] <= 0;
  185.     clrPath[1][1] <= 0;
  186.     clrPath[1][2] <= 0;
  187.     clrPath[1][3] <= 1;
  188.     clrPath[1][4] <= 3;
  189.     clrPath[1][5] <= 2;
  190.     clrPath[1][6] <= 0;
  191.     clrPath[1][7] <= 0;
  192.     clrPath[1][8] <= 0;
  193.  
  194.     clrPath[2][0] <= 3;
  195.     clrPath[2][1] <= 3;
  196.     clrPath[2][2] <= 3;
  197.     clrPath[2][3] <= 3;
  198.     clrPath[2][4] <= 3;
  199.     clrPath[2][5] <= 3;
  200.     clrPath[2][6] <= 3;
  201.     clrPath[2][7] <= 3;
  202.  
  203.     clrPath[3][0] <= 0;
  204.     clrPath[3][1] <= 2;
  205.     clrPath[3][2] <= 3;
  206.     clrPath[3][3] <= 1;
  207.     clrPath[3][4] <= 0;
  208.  
  209.     clrPath[4][0] <= 0;
  210.     clrPath[4][1] <= 0;
  211.     clrPath[4][2] <= 0;
  212.     clrPath[4][3] <= 2;
  213.     clrPath[4][4] <= 3;
  214.     clrPath[4][5] <= 1;
  215.     clrPath[4][6] <= 0;
  216.     clrPath[4][7] <= 0;
  217.     clrPath[4][8] <= 0;
  218.  
  219.     clrPath[5][0] <= 3;
  220.     clrPath[5][1] <= 3;
  221.     clrPath[5][2] <= 3;
  222.     clrPath[5][3] <= 3;
  223.     clrPath[5][4] <= 3;
  224.  
  225.     clrPath[6][0] <= 0;
  226.     clrPath[6][1] <= 0;
  227.     clrPath[6][2] <= 1;
  228.     clrPath[6][3] <= 3;
  229.     clrPath[6][4] <= 2;
  230.     clrPath[6][5] <= 0;
  231.     clrPath[6][6] <= 0;
  232.  
  233.     clrPathlen[0] <= 4;
  234.     clrPathlen[1] <= 8;
  235.     clrPathlen[2] <= 7;
  236.     clrPathlen[3] <= 4;
  237.     clrPathlen[4] <= 8;
  238.     clrPathlen[5] <= 4;
  239.     clrPathlen[6] <= 6;
  240.     clrPathlen[7] <= 0;
  241.     clrPathlen[8] <= 0;
  242.  
  243.      DepPath [0][0] <= 2;
  244.     DepPath [0][1] <= 0;
  245.     DepPath [0][2] <= 1;
  246.     DepPath [0][3] <= 1;
  247.     DepPath [0][4] <= 3;
  248.     DepPath [0][5] <= 2;
  249.     DepPath [0][6] <= 2;
  250.     DepPath [0][7] <= 0;
  251.     DepPath [0][8] <= 0;
  252.     //for DZP2
  253.     DepPath [1][0] <= 2;
  254.     DepPath [1][1] <= 1;
  255.     DepPath [1][2] <= 3;
  256.     DepPath [1][3] <= 2;
  257.     DepPath [1][4] <= 0;
  258.     //for DZM1
  259.     DepPath [2][0] <= 1;
  260.     DepPath [2][1] <= 1;
  261.     DepPath [2][2] <= 2;
  262.     DepPath [2][3] <= 3;
  263.     DepPath [2][4] <= 1;
  264.     DepPath [2][5] <= 2;
  265.     DepPath [2][6] <= 1;
  266.     //for DZM2
  267.     DepPath [3][0] <= 1;
  268.     DepPath [3][1] <= 1;
  269.     DepPath [3][2] <= 0;
  270.     DepPath [3][3] <= 2;
  271.     DepPath [3][4] <= 2;
  272.     DepPath [3][5] <= 3;
  273.     DepPath [3][6] <= 1;
  274.     DepPath [3][7] <= 1;
  275.     DepPath [3][8] <= 0;
  276.      DepPath [3][9] <= 2;
  277.     DepPath [3][10] <= 1;
  278.  
  279.     //for DZM3
  280.     DepPath [4][0] <= 1;
  281.     DepPath [4][1] <= 0;
  282.     DepPath [4][2] <= 0;
  283.     DepPath [4][3] <= 0;
  284.     DepPath [4][4] <= 1;
  285.     DepPath [4][5] <= 1;
  286.     DepPath [4][6] <= 3;
  287.     DepPath [4][7] <= 2;
  288.     DepPath [4][8] <= 2;
  289.     DepPath [4][9] <= 0;
  290.     DepPath [4][10] <= 0;
  291.      DepPath [4][11] <= 0;
  292.     DepPath [4][12] <= 1;
  293.     //for DZV2
  294.     DepPath [5][0] <= 1;
  295.     DepPath [5][1] <= 2;
  296.     DepPath [5][2] <= 3;
  297.     DepPath [5][3] <= 1;
  298.     DepPath [5][4] <= 1;
  299.     //for DZV1
  300.     DepPath [6][0] <= 0;
  301.     DepPath [6][1] <= 1;
  302.     DepPath [6][2] <= 3;
  303.     DepPath [6][3] <= 1;
  304.     //for DZN1
  305.     DepPath [7][0] <= 1;
  306.     DepPath [7][1] <= 0;
  307.     DepPath [7][2] <= 2;
  308.     DepPath [7][3] <= 1;
  309.     DepPath [7][4] <= 3;
  310.     DepPath [7][5] <= 2;
  311.     DepPath [7][6] <= 1;
  312.     DepPath [7][7] <= 0;
  313.     DepPath [7][8] <= 2;//end
  314.     //for DZN2
  315.     DepPath [8][0] <= 1;
  316.     DepPath [8][1] <= 0;
  317.     DepPath [8][2] <= 0;
  318.     DepPath [8][3] <= 2;
  319.     DepPath [8][4] <= 3;
  320.     DepPath [8][5] <= 1;
  321.     DepPath [8][6] <= 0;
  322.     DepPath [8][7] <= 0;
  323.     DepPath [8][8] <= 2;//end
  324.  
  325.     DepPath_len [0] <= 8;
  326.     DepPath_len [1] <= 4;
  327.     DepPath_len [2] <= 6;
  328.     DepPath_len [3] <= 10;
  329.     DepPath_len [4] <= 12;
  330.     DepPath_len [5] <= 4;
  331.     DepPath_len [6] <= 3;
  332.     DepPath_len [7] <= 8;
  333.     DepPath_len [8] <= 8;
  334.      
  335.     done <= 1;
  336. end
  337.    
  338.      led1 <= (s1);              //Led lights up when s1 has a greater value than 2000
  339.      led2 <= (s2);                  //Led lights up when s2 has a greater value than 2000
  340.      led3 <= (s3);                  //Led lights up when s3 has a greater value than 2000
  341.  
  342.     error <= (s1) - (s3);      //Relative error between sensors s1 and s3: values range from -1 to 1  P
  343.  
  344.     cumulative_error <= cumulative_error + error;  //Adds up the error to give a cumulative error  I
  345.      
  346.     if (cumulative_error > 10)     //Condition to reset the value of cumulative error to 10 if it crosses 10  
  347.     begin
  348.         cumulative_error <= 10;
  349.     end
  350.     if (cumulative_error < -10)    //Condition to reset the value of cumulative error to -10 if it crosses -10  
  351.     begin
  352.         cumulative_error <= -10;
  353.     end
  354.      
  355.      if ((s1==0) && s2 && (s3==0)) //Cumulative error resets to zero when the bot is on line i.e WBW
  356.      begin
  357.             cumulative_error <= 0;  
  358.             hl <=0;
  359.             id1 <= 0;
  360.      end
  361.      
  362.      difference <= error-preverror;                                  //forms the differential part D
  363.      correction <= ((10*error) + cumulative_error + (2*difference)); // kp = 10, ki = 1, kd =2
  364.       preverror <= error;  // Stores value of current error to previous error so that it can be used in next loop cycle
  365.      
  366.      
  367.      ml1 <= odc - correction;  // PID tuning for motor 1
  368.      ml2 <= odc + correction;  // PID tuning for motor 2
  369.  
  370.      if (ml1>70)      //Resetting value of ml1 to 70 if it crosses 70
  371.      begin
  372.          ml1 <= 70;
  373.      end
  374.      if (ml2>70)      //Resetting value of ml2 to 70 if it crosses 70
  375.      begin
  376.          ml2 <= 70;
  377.      end
  378.      if (ml1<30)       //Resetting value of ml1 to 30 if it becomes less than 30
  379.      begin
  380.          ml1 <= 30;
  381.      end
  382.      if (ml2<30)       //Resetting value of ml2 to 30 if it becomes less than 30
  383.      begin
  384.          ml2 <= 30;
  385.      end
  386.    
  387.     if ((s1==0) && s2 && (s3==0)) //ready for next node, flag resets to zero on line : WBW
  388.     begin
  389.         flag <= 0;
  390.           ml1r <= 0;
  391.           ml2r <= 0;
  392.     end
  393.  
  394.     if (s1 && s2 && s3 && flag == 0)  //detect node
  395.     begin
  396.             id1 <= 4;
  397.             hl <= 1;
  398.             nodecount <= nodecount + 1;
  399.          flag <= 1;   //node
  400.             flag2 <= 1;  //clr lock
  401.             clr_en <= 1; //color enable 1 disable
  402.     end
  403.    
  404.     if(flag == 1)                                  //if node
  405.     begin
  406.         if(state==0)                                //is arena?
  407.         begin
  408.             n<=pwm(path[path_no][nodecount]);         //follow arena
  409.         end else
  410.         if((state==1)&&(nodecount<10))                                //is pick?
  411.         begin
  412.             if((clrs[clrsN][0]==1)&&(clrs[clrsN][1]==0))
  413.             begin
  414.                 n<=pwm(clrPath[0+rcount][nodecount]);
  415.             end else if((clrs[clrsN][0]==0)&&(clrs[clrsN][1]==1))
  416.             begin
  417.                 n<=pwm(clrPath[3+gcount][nodecount]);
  418.             end else if((clrs[clrsN][0]==1)&&(clrs[clrsN][1]==1))
  419.             begin
  420.                 n<=pwm(clrPath[6+bcount][nodecount]);
  421.             end
  422.            
  423.            
  424.             if ((clrs[clrsN][0]==1)&&(clrs[clrsN][1]==0)&&(rcount==0) && (nodecount== 2 ))
  425.                 begin
  426.                     en<=1;
  427.                           id <= 54;
  428.                           hl <=1;  
  429.                 end else if((clrs[clrsN][0]==1)&&(clrs[clrsN][1]==0)&&(rcount==1) && (nodecount ==4 ))
  430.                 begin
  431.                     en<=1;
  432.                 end else if((clrs[clrsN][0]==1)&&(clrs[clrsN][1]==0)&&(rcount==2) && (nodecount ==4 ))
  433.                 begin
  434.                     en<=1;
  435.                 end else if((clrs[clrsN][0]==0)&&(clrs[clrsN][1]==1)&&(gcount==0) && (nodecount ==2 ))
  436.                 begin
  437.                     en<=1;
  438.                           id <= 40;
  439.                           hl <=1;
  440.                 end else if((clrs[clrsN][0]==0)&&(clrs[clrsN][1]==1)&&(gcount==1) && (nodecount ==3 ))
  441.                 begin
  442.                     en<=1;
  443.                 end else if((clrs[clrsN][0]==0)&&(clrs[clrsN][1]==1)&&(gcount==2) && (nodecount ==2 ))
  444.                 begin
  445.                     en<=1;
  446.                 end else if((clrs[clrsN][0]==1)&&(clrs[clrsN][1]==1)&&(bcount==0) && (nodecount ==2 ))
  447.                 begin
  448.                     en<=1;
  449.                           id <= 8;
  450.                           hl <=1;
  451.                 end
  452.         end else if((state==2)&&(nodecount<13))
  453.         begin
  454.             n<=pwm(DepPath[dest[clrsN]][nodecount]);
  455.             if(dest[clrsN]==0 && nodecount == 4 )
  456.                 begin
  457.                     en<=0;
  458.                           clr_reset <= 1;
  459.                           id<=41;
  460.                           hl<=1;
  461.                 end else if(dest[clrsN]==1 && nodecount ==2 )
  462.                 begin
  463.                     en<=0;
  464.                           clr_reset <= 1;
  465.                 end else if(dest[clrsN]==2 && nodecount ==3 )
  466.                 begin
  467.                     en<=0;
  468.                           clr_reset <= 1;
  469.                           id<=55;
  470.                           hl<=1;
  471.  
  472.                 end else if(dest[clrsN]==3 && nodecount ==5 )
  473.                 begin
  474.                     en<=0;
  475.                           clr_reset <= 1;
  476.                          
  477.                 end else if(dest[clrsN]==4 && nodecount ==6 )
  478.                 begin
  479.                     en<=0;
  480.                           clr_reset <= 1;
  481.                 end else if(dest[clrsN]==5 && nodecount ==2 )
  482.                 begin
  483.                     en<=0;
  484.                           clr_reset <= 1;
  485.                           id<=19;
  486.                           hl<=1;
  487.                 end else if(dest[clrsN]==6 && nodecount ==2 )
  488.                 begin
  489.                     en<=0;
  490.                           clr_reset <= 1;
  491.                 end else if(dest[clrsN]==7 && nodecount ==4 )
  492.                 begin
  493.                     en<=0;
  494.                           clr_reset <= 1;
  495.                           id<=9;
  496.                           hl<=1;
  497.                 end else if(dest[clrsN]==8 && nodecount ==4 )
  498.                 begin
  499.                     en<=0;
  500.                           clr_reset <= 1;
  501.                 end
  502.                      else
  503.                      begin
  504.                         clr_reset <= 0;
  505.                      end
  506.         end
  507.            
  508.     end
  509.    
  510.     if(flag == 0)    //assigning values of ml1 and ml2 (line condition) to mo1 and mo2 respectively
  511.     begin
  512.     if(state==0)
  513.     begin
  514.         if(path_no ==0 && nodecount ==5 )        //enable clr module at patch1
  515.             begin
  516.                 clr_en1 <= 0;
  517.                 if((Clr != 0)&&(flag2==1))
  518.                 begin
  519.                     clrsN <= clrsN +1;
  520.                     clrs[clrsN+1] <= Clr[2:0];
  521.                     dest[clrsN+1] <= 1;
  522.                     flag2 <= 0;
  523.                 end
  524.         end else if(path_no ==0 && nodecount ==7 )      //enable clr module only at patches
  525.         begin
  526.             clr_en1 <= 0;
  527.             if((Clr != 0)&&(flag2==1))
  528.             begin
  529.                 clrsN <= clrsN +1;
  530.                 clrs[clrsN+1] <= Clr[2:0];
  531.                 dest[clrsN+1] <= 0;
  532.                 flag2 <= 0;
  533.             end
  534.         end else if(path_no ==1 && nodecount ==5 )      //enable clr module only at patches
  535.         begin
  536.             clr_en1 <= 0;
  537.             if((Clr != 0)&&(flag2==1))
  538.             begin
  539.                 clrsN <= clrsN +1;
  540.                 clrs[clrsN+1] <= Clr[2:0];
  541.                 dest[clrsN+1] <= 4;
  542.                 flag2 <= 0;
  543.             end
  544.         end else if(path_no ==1 && nodecount ==6 )      //enable clr module only at patches
  545.         begin
  546.             clr_en1 <= 0;
  547.             if((Clr != 0)&&(flag2==1))
  548.             begin
  549.                 clrsN <= clrsN +1;
  550.                 clrs[clrsN+1] <= Clr[2:0];
  551.                 dest[clrsN+1] <= 3;
  552.                 flag2 <= 0;
  553.             end
  554.         end else if(path_no ==1 && nodecount ==7 )      //enable clr module only at patches
  555.         begin
  556.             clr_en1 <= 0;
  557.             if((Clr != 0)&&(flag2==1))
  558.             begin
  559.                 clrsN <= clrsN +1;
  560.                 clrs[clrsN+1] <= Clr[2:0];
  561.                 dest[clrsN+1] <= 2;
  562.                 flag2 <= 0;
  563.             end
  564.         end else if(path_no ==2 && nodecount ==1 )      //enable clr module only at patches
  565.         begin
  566.             clr_en1 <= 0;
  567.             if((Clr != 0)&&(flag2==1))
  568.             begin
  569.                 clrsN <= clrsN +1;
  570.                 clrs[clrsN+1] <= Clr[2:0];
  571.                 dest[clrsN+1] <= 6;
  572.                 flag2 <= 0;
  573.             end
  574.         end else if(path_no ==2 && nodecount ==6 )      //enable clr module only at patches
  575.         begin
  576.             clr_en1 <= 0;
  577.             if((Clr != 0)&&(flag2==1))
  578.             begin
  579.                 clrsN <= clrsN +1;
  580.                 clrs[clrsN+1] <= Clr[2:0];
  581.                 dest[clrsN+1] <= 5;
  582.                 flag2 <= 0;
  583.             end
  584.         end else if(path_no ==3 && nodecount ==5 )      //enable clr module only at patches
  585.         begin
  586.             clr_en1 <= 0;
  587.             if((Clr != 0)&&(flag2==1))
  588.             begin
  589.                 clrsN <= clrsN +1;
  590.                 clrs[clrsN+1] <= Clr[2:0];
  591.                 dest[clrsN+1] <= 8;
  592.                 flag2 <= 0;
  593.             end
  594.         end else if(path_no ==3 && nodecount ==7 )      //enable clr module only at patches
  595.         begin
  596.             clr_en1 <= 0;
  597.             if((Clr != 0)&&(flag2==1))
  598.             begin
  599.                 clrsN <= clrsN +1;
  600.                 clrs[clrsN+1] <= Clr[2:0];
  601.                 dest[clrsN+1] <= 7;
  602.                 flag2 <= 0;
  603.             end
  604.         end else
  605.         begin
  606.             clr_en <= 1;
  607.         end
  608.     end else
  609.     begin
  610.         clr_en <= 1;
  611.     end
  612.         if((state==0)&&(nodecount == (path_len[path_no]-1)))       //if about to reach end of path
  613.         begin
  614.             if(clrsN != 0)                           //detected color?
  615.             begin
  616.                 state <= 1;                             //go to pick
  617.             end else if(clrsN == 0)
  618.             begin
  619.                 nodecount <= -5'd1;                      //reset nodecount
  620.                 path_no <= path_no + 1;                  //change path
  621.             end
  622.         end
  623.         if(state==1)
  624.         begin
  625.             if((nodecount == path_len[path_no])&&(flag3==0))
  626.             begin
  627.             nodecount <= -5'd1;
  628.             flag3<=1;
  629.             end
  630.             if((clrs[clrsN][0]==1)&&(clrs[clrsN][1]==0))
  631.             begin
  632.                 if(nodecount == clrPathlen[0+rcount])
  633.                 begin
  634.                 nodecount <= -5'd1;
  635.                 state <= 2;
  636.                 end
  637.             end else if((clrs[clrsN][0]==0)&&(clrs[clrsN][1]==1))
  638.             begin
  639.                 if(nodecount == clrPathlen[3+gcount])
  640.                 begin
  641.                 nodecount <= -5'd1;
  642.                 state <= 2;
  643.                 end
  644.             end else if((clrs[clrsN][0]==1)&&(clrs[clrsN][1]==1))
  645.             begin
  646.                 if(nodecount == clrPathlen[6+bcount])
  647.                 begin
  648.                 nodecount <= -5'd1;
  649.                 state <= 2;
  650.                 end
  651.             end
  652.         end else if(state==2)
  653.         begin
  654.             if(nodecount==DepPath_len[dest[clrsN]])
  655.             begin
  656.                 nodecount<=0;
  657.                 state<=0;
  658.                 path_no<=path_no+1;
  659.                 clrsN<= 0;
  660.                 clrs[0]<=0;
  661.                 clrs[1]<=0;
  662.                 clrs[2]<=0;
  663.                 flag3<=0;
  664.                 rcount <= rcount+1;
  665.             end
  666.         end
  667.         mo1 <= ml1;
  668.         mo1r<= ml1r;
  669.         mo2 <= ml2;
  670.         mo2r<= ml2r;
  671.     end else
  672.     begin            //assigning values of mn1 and mn2 (node condition) to mo1 and mo2 respectively
  673.         mo1 <= mn1;
  674.         mo1r<= mn1r;
  675.         mo2 <= mn2;
  676.         mo2r<= mn2r;
  677.     end
  678. end
  679.        
  680. assign Led1 = led1;
  681. assign Led2 = led2;
  682. assign Led3 = led3;
  683.  
  684. assign id = id1;
  685. assign HL1 = hl;
  686. assign m1 = mo1;
  687. assign m1b= mo1r;
  688. assign m2 = mo2;
  689. assign m2b= mo2r;
  690.  
  691. assign EM = en;
  692. assign Clr_en = clr_en;
  693. assign Clr_r = clr_reset;
  694. endmodule
  695.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement