Advertisement
Sidsh

LSA Documented 2.0

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