module whole(clk,btn1,btn2,btn3,CP_P,CP_N,CW_P,CW_N); input clk,btn1,btn2,btn3; output CP_P,CP_N,CW_P,CW_N; reg CP_P=0,CP_N=0,CW_P=0,CW_N=0; reg[24:0] count=0; reg flag=0; reg rst=0,dir=0; reg btn1_en=0,btn2_en=0,btn3_en=0; reg btn1_blk=0,btn2_blk=0,btn3_blk=0; reg S1=0,S2=0; integer Cn=0; integer step=0; integer distance=0;
always @(posedge btn1) begin if(btn2==0&&btn3==0) begin btn1_en=1; end end
always @(posedge btn2) begin if(btn1==0&&btn3==0) begin btn2_en=1; end end always @(posedge btn3) begin if(btn1==0&&btn2==0) begin btn3_en=1; end end
always @(step or distance) begin if(btn1_en==1) btn1_blk=1 ; //move if(btn1_blk==1) begin CW_P=0; //direction if(btn1) begin if(step<200) //reallocate accelerate begin S1=1; S2=0; end else //reallocate invariablenes speed begin S1=1; S2=1; end end else if(step>0) //reallocate decelerate begin S1=0; S2=1; end else begin //stop S1=0; S2=0; btn1_blk=0; end end
if(btn2_en==1) btn2_blk=1; if(btn2_blk==1) begin CW_P=0; //direction if(btn2) begin if(step<333) //reallocate accelerate begin S1=1; S2=0; end else //reallocate invariablenes speed begin S1=1; S2=1; end end else if(step>0) //reallocate decelerate begin S1=0; S2=1; end else begin //stop S1=0; S2=0; btn2_blk=0; end end
if(btn3_en==1) btn3_blk=1; if(btn3_blk==1) begin CW_P=1; //direction if(btn3) begin if(step<200) //reallocate accelerate begin S1=1; S2=0; end else //reallocate invariablenes speed begin S1=1; S2=1; end end else if(step>0) //reallocate decelerate begin S1=0; S2=1; end else begin //stop S1=0; S2=0; btn3_blk=0; end end end always @(posedge clk) begin CP_N=0; CW_N=0; if(rst) //reset begin distance=0; step=0; end if(S1==0&&S2==0) //stop begin CP_P=0; step=0; end
if(S1==1&&S2==0) //accelerate begin if(count<Cn) begin count=count+1; begin if(count<500) begin CP_P=1; end else begin CP_P=0; end end end else begin count=0; step=step+1; distance=distance+1; end end
if(S1==0&&S2==1) //decelerate begin if(count<Cn) begin count=count+1; begin if(count<500) begin CP_P=1; end else begin CP_P=0; end end end else begin count=0; step=step-1; distance=distance+1; end end
if(S1==1&&S2==1) //invariablenes speed begin if(count<Cn) begin count=count+1; begin if(count<500) begin CP_P=1; end else begin CP_P=0; end end end else begin count=0; distance=distance+1; end end case(step) 0 :Cn= 2738613 ; 1 :Cn= 1134371 ; 2 :Cn= 870433 ; 3 :Cn= 733809 ; 4 :Cn= 646499 ; 5 :Cn= 584480 ; 6 :Cn= 537484 ; 7 :Cn= 500278 ; 8 :Cn= 469872 ; 9 :Cn= 444416 ; 10 :Cn= 422697 ; 11 :Cn= 403882 ; 12 :Cn= 387376 ; 13 :Cn= 372742 ; 14 :Cn= 359651 ; 15 :Cn= 347849 ; 16 :Cn= 337139 ; 17 :Cn= 327360 ; 18 :Cn= 318386 ; 19 :Cn= 310112 ; 20 :Cn= 302452 ; 21 :Cn= 295332 ; 22 :Cn= 288693 ; 23 :Cn= 282482 ; 24 :Cn= 276656 ; 25 :Cn= 271176 ; 26 :Cn= 266009 ; 27 :Cn= 261127 ; 28 :Cn= 256504 ; 29 :Cn= 252119 ; 30 :Cn= 247951 ; 31 :Cn= 243983 ; 32 :Cn= 240199 ; 33 :Cn= 236587 ; 34 :Cn= 233132 ; 35 :Cn= 229825 ; 36 :Cn= 226655 ; 37 :Cn= 223612 ; 38 :Cn= 220688 ; 39 :Cn= 217877 ; 40 :Cn= 215170 ; 41 :Cn= 212561 ; 42 :Cn= 210046 ; 43 :Cn= 207617 ; 44 :Cn= 205271 ; 45 :Cn= 203003 ; 46 :Cn= 200808 ; 47 :Cn= 198683 ; 48 :Cn= 196624 ; 49 :Cn= 194627 ; 50 :Cn= 192690 ; 51 :Cn= 190810 ; 52 :Cn= 188984 ; 53 :Cn= 187210 ; 54 :Cn= 185484 ; 55 :Cn= 183806 ; 56 :Cn= 182172 ; 57 :Cn= 180581 ; 58 :Cn= 179030 ; 59 :Cn= 177519 ; 60 :Cn= 176046 ; 61 :Cn= 174609 ; 62 :Cn= 173206 ; 63 :Cn= 171837 ; 64 :Cn= 170500 ; 65 :Cn= 169193 ; 66 :Cn= 167916 ; 67 :Cn= 166668 ; 68 :Cn= 165447 ; 69 :Cn= 164252 ; 70 :Cn= 163083 ; 71 :Cn= 161939 ; 72 :Cn= 160818 ; 73 :Cn= 159720 ; 74 :Cn= 158644 ; 75 :Cn= 157590 ; 76 :Cn= 156557 ; 77 :Cn= 155544 ; 78 :Cn= 154550 ; 79 :Cn= 153575 ; 80 :Cn= 152618 ; 81:Cn=151678; 82:Cn=150756; 83:Cn=149851; 84:Cn=148962; 85:Cn=148088; 86:Cn=147229; 87:Cn=146386; 88:Cn=145556; 89:Cn=144741; 90:Cn=143939; 91:Cn=143150; 92:Cn=142374; 93:Cn=141611; 94:Cn=140860; 95:Cn=140120; 96:Cn=139392; 97:Cn=138676; 98:Cn=137970; 99:Cn=137275; 100:Cn=136590; 101:Cn=135915; 102:Cn=135251; 103:Cn=134596; 104:Cn=133950; 105:Cn=133314; 106:Cn=132687; 107:Cn=132068; 108:Cn=131458; 109:Cn=130856; 110:Cn=130263; 111 :Cn= 129677 ; 112 :Cn= 129100 ; 113 :Cn= 128530 ; 114 :Cn= 127967 ; 115 :Cn= 127412 ; 116 :Cn= 126864 ; 117 :Cn= 126323 ; 118 :Cn= 125789 ; 119 :Cn= 125262 ; 120 :Cn= 124741 ; 121 :Cn= 124226 ; 122 :Cn= 123718 ; 123 :Cn= 123216 ; 124 :Cn= 122720 ; 125 :Cn= 122231 ; 126 :Cn= 121746 ; 127 :Cn= 121268 ; 128 :Cn= 120795 ; 129 :Cn= 120328 ; 130 :Cn= 119866 ; 131 :Cn= 119409 ; 132 :Cn= 118958 ; 133 :Cn= 118512 ; 134 :Cn= 118070 ; 135 :Cn= 117634 ; 136 :Cn= 117202 ; 137 :Cn= 116775 ; 138 :Cn= 116353 ; 139 :Cn= 115935 ; 140 :Cn= 115522 ; 141 :Cn= 115113 ; 142 :Cn= 114708 ; 143 :Cn= 114308 ; 144 :Cn= 113911 ; 145 :Cn= 113519 ; 146 :Cn= 113131 ; 147 :Cn= 112747 ; 148 :Cn= 112367 ; 149 :Cn= 111990 ; 150 :Cn= 111618 ; 151 :Cn= 111249 ; 152 :Cn= 110883 ; 153 :Cn= 110522 ; 154 :Cn= 110163 ; 155 :Cn= 109809 ; 156 :Cn= 109457 ; 157 :Cn= 109109 ; 158 :Cn= 108764 ; 159 :Cn= 108423 ; 160 :Cn= 108085 ; 161 :Cn= 107749 ; 162 :Cn= 107417 ; 163 :Cn= 107088 ; 164 :Cn= 106762 ; 165 :Cn= 106439 ; 166 :Cn= 106119 ; 167 :Cn= 105802 ; 168 :Cn= 105488 ; 169 :Cn= 105176 ; 170 :Cn= 104867 ; 171 :Cn= 104561 ; 172 :Cn= 104257 ; 173 :Cn= 103956 ; 174 :Cn= 103658 ; 175 :Cn= 103362 ; 176 :Cn= 103069 ; 177 :Cn= 102778 ; 178 :Cn= 102490 ; 179 :Cn= 102204 ; 180 :Cn= 101921 ; 181 :Cn= 101640 ; 182 :Cn= 101361 ; 183 :Cn= 101084 ; 184 :Cn= 100810 ; 185 :Cn= 100538 ; 186 :Cn= 100268 ; 187 :Cn= 100000 ; 188 :Cn= 99734 ; 189 :Cn= 99471 ; 190 :Cn= 99210 ; 191 :Cn= 98950 ; 192 :Cn= 98693 ; 193 :Cn= 98437 ; 194 :Cn= 98184 ; 195 :Cn= 97933 ; 196 :Cn= 97683 ; 197 :Cn= 97436 ; 198 :Cn= 97190 ; 199 :Cn= 96946 ; 200 :Cn= 96704 ; 201 :Cn= 96464 ; 202 :Cn= 96225 ; 203 :Cn= 95988 ; 204 :Cn= 95753 ; 205 :Cn= 95520 ; 206 :Cn= 95289 ; 207 :Cn= 95059 ; 208 :Cn= 94830 ; 209 :Cn= 94604 ; 210 :Cn= 94379 ; 211 :Cn= 94156 ; 212 :Cn= 93934 ; 213 :Cn= 93713 ; 214 :Cn= 93495 ; 215 :Cn= 93278 ; 216 :Cn= 93062 ; 217 :Cn= 92848 ; 218 :Cn= 92635 ; 219 :Cn= 92424 ; 220 :Cn= 92214 ; 221 :Cn= 92006 ; 222 :Cn= 91799 ; 223 :Cn= 91593 ; 224 :Cn= 91389 ; 225 :Cn= 91186 ; 226 :Cn= 90984 ; 227 :Cn= 90784 ; 228 :Cn= 90585 ; 229 :Cn= 90388 ; 230 :Cn= 90191 ; 231 :Cn= 89996 ; 232 :Cn= 89803 ; 233 :Cn= 89610 ; 234 :Cn= 89419 ; 235 :Cn= 89229 ; 236 :Cn= 89040 ; 237 :Cn= 88852 ; 238 :Cn= 88666 ; 239 :Cn= 88481 ; 240 :Cn= 88296 ; 241 :Cn= 88113 ; 242 :Cn= 87932 ; 243 :Cn= 87751 ; 244 :Cn= 87571 ; 245 :Cn= 87393 ; 246 :Cn= 87215 ; 247 :Cn= 87039 ; 248 :Cn= 86864 ; 249 :Cn= 86689 ; 250 :Cn= 86516 ; 251 :Cn= 86344 ; 252 :Cn= 86173 ; 253 :Cn= 86003 ; 254 :Cn= 85834 ; 255 :Cn= 85665 ; 256 :Cn= 85498 ; 257 :Cn= 85332 ; 258 :Cn= 85167 ; 259 :Cn= 85003 ; 260 :Cn= 84839 ; 261 :Cn= 84677 ; 262 :Cn= 84515 ; 263 :Cn= 84355 ; 264 :Cn= 84195 ; 265 :Cn= 84037 ; 266 :Cn= 83879 ; 267 :Cn= 83722 ; 268 :Cn= 83566 ; 269 :Cn= 83411 ; 270 :Cn= 83256 ; 271 :Cn= 83103 ; 272 :Cn= 82950 ; 273 :Cn= 82798 ; 274 :Cn= 82647 ; 275 :Cn= 82497 ; 276 :Cn= 82348 ; 277 :Cn= 82200 ; 278 :Cn= 82052 ; 279 :Cn= 81905 ; 280 :Cn= 81759 ; 281 :Cn= 81613 ; 282 :Cn= 81469 ; 283 :Cn= 81325 ; 284 :Cn= 81182 ; 285 :Cn= 81040 ; 286 :Cn= 80898 ; 287 :Cn= 80757 ; 288 :Cn= 80617 ; 289 :Cn= 80478 ; 290 :Cn= 80339 ; 291 :Cn= 80201 ; 292 :Cn= 80064 ; 293 :Cn= 79928 ; 294 :Cn= 79792 ; 295 :Cn= 79657 ; 296 :Cn= 79522 ; 297 :Cn= 79388 ; 298 :Cn= 79255 ;   |