Sunday, 24 April 2016

Hexadecimal operations





Bit rate Vs Baud Rate

In digital Communication our Intention is to transfer Digital Data which is obviously seen in bit and therefore for that we use the term bit rate.

But As we can't send this digital data directly so for that we have to convert this digital data into some sought of signal and that is achieved by line coding techniques like NRZ, Manchester coding ....etc etc.
Now when we talk about speed here in sense of this signal then we talk about baud rate which is also known as pulse rate/ modulation rate/ baud rate or simply baud. 

You can also make a analogy of above concept as by a example of train where each carrier of a train is the signal element (baud) and passenger sitting inside that carrier is a data element (bit).
similarly signal rate (baud rate) and data rate(bit rate)

For Higher efficieny bit rate > baud rate
and To increase this efficiency only we have many line coding techniques

Formula for Baud rate is

Baud Rate = Bit rate
                     ------------
                     No. of data element carried by each signal element



There is some examples also for detail Understanding
For that [Click Here]

Saturday, 23 April 2016

CPU VS FPGA VS ASIC

CPU---SOFTWARE--LIST OF INSTRUCTIONS
FPGA--FIRMWARE--GATES---PROGRAMED WITH THE HELP OF VERILOG,VHDL
ASIC--IT CAN BE USED AS FPGA BUT NOT REPROGRAMMED

it means you will test your design on fpga practically verify it and then give chip manufacturing industry to manufacture a chip.




Friday, 22 April 2016

Microprocessor 8085 Verilog


  1. /*module processor(a,b, );
  2.   input [2:0]opcode;
  3.   input a,b;
  4.   output o;

  5. case(opcode)
  6.   begin
  7.   000: assign o<=a+b;
  8.   001: assign o<a-b;
  9.   010: assign 
  10.   */
  11.   
  12. module meomory(addr,,enable,out);
  13. input [2:0]addr;    //pc
  14. output reg [10:0] out;
  15. reg [10:0]mem[7:0];
  16. input enable;      //read
  17. initial
  18. $readmemb("input.txt",mem);
  19.   always @(*)
  20.   if(enable)
  21.  out=mem[addr];
  22.  else
  23.    out=out;
  24.    
  25. endmodule


  26. module ir(a,en,out);
  27.   input [10:0]a;
  28.   input en;
  29.   output reg [10:0]out;
  30.   always @(*)
  31.   begin
  32.     if(en==1)
  33.   out=a;
  34. end
  35. endmodule

  36. module decoder(in,en,opcode,data);
  37. input [10:0]in;
  38. input en;
  39. output reg [2:0]opcode; 
  40. output reg[7:0]data;
  41.   always @(*)
  42.   begin
  43.     if(en==1)
  44.       begin
  45.   opcode=in[10:8];
  46.   data=in[7:0];
  47.    end
  48.    /*else
  49.      begin
  50.      opcode=0;
  51.      data=0;
  52.     end*/
  53. end
  54. endmodule

  55. //module meomory_tb;
  56. //  reg [3:0]addr;
  57. //  reg enable;
  58.   
  59. module ir_tb;
  60.   reg [10:0]a;
  61.   reg en;
  62.   wire [10:0]out;
  63.   ir v1(a,en,out);
  64.   
  65.   initial
  66.     begin 
  67.       #1 en=1;
  68.       #5 a=11'b10001100110;
  69.       #10 en=0;
  70.       #11 a=11'b01011001101;
  71.   end
  72. endmodule

  73. module decoder_tb;
  74.   reg [10:0]in;
  75. reg en;
  76. wire [2:0]opcode; 
  77. wire [7:0]data;
  78. decoder v2(in,en,opcode,data);
  79.    initial
  80.      begin
  81.        #1 en=1;
  82.       #5 in=11'b10001100110;
  83.       #10 en=0;
  84.       #11 in=11'b01011001101;
  85.   end
  86. endmodule

  87. module alu4pro(opcode,vala,valb,aluout);
  88.   input [2:0]opcode;
  89.   input [7:0]vala;
  90.   input [7:0]valb;
  91.   output reg [10:0]aluout;
  92.   parameter add_op=3'b000,sub_op=3'b001,nand_op=3'b010,nor_op=3'b011,xor_op=3'b100,and_op=3'b101,or_op=3'b110,xnor_op=3'b111;

  93.   always @(*)
  94.   
  95.   case(opcode)
  96.   
  97.       
  98.     add_op: begin
  99.       aluout=vala+valb;
  100.     end
  101.     
  102.     sub_op:begin
  103.       aluout=vala-valb;
  104.     end
  105.     
  106.     nand_op:begin
  107.       aluout=~(vala&valb);
  108.     end
  109.     
  110.     nor_op:begin
  111.       aluout=~(vala|valb);
  112.     end
  113.     
  114.     xor_op:begin
  115.       aluout=vala^valb;
  116.     end
  117.     
  118.     and_op:begin
  119.       aluout=vala&valb;
  120.     end
  121.     
  122.     or_op:begin
  123.       aluout=vala|valb;
  124.     end
  125.     
  126.     xnor_op:begin
  127.       aluout=~(vala^valb);
  128.     end
  129.   
  130.   endcase
  131.     
  132. endmodule

  133. module alu4pro_tb;
  134.   reg [2:0]opcode;
  135.   reg [7:0]vala;
  136.   reg [7:0]valb;
  137.   wire [10:0]aluout;
  138.   alu4pro b2(opcode,vala,valb,aluout);
  139.   initial
  140.   begin
  141.     opcode=3'b000;
  142.     vala=3'b10;
  143.     valb=3'b11;
  144. #20opcode=3'b110;
  145. vala=3'b111;
  146. valb=3'b101;
  147. end
  148. //$monitor("time=%d,opcode=%b,vala=%b,valb=%b,aluout=%b",$time,opcode,vala,valb,aluout);
  149. endmodule

  150. module accumulator(aluout,clk,rst,accout);
  151.   input [7:0]aluout;
  152.   input clk;
  153.   input rst;
  154.   output reg [7:0]accout;
  155.   always@(clk)
  156.   if(rst)
  157.     begin
  158.      accout=aluout;
  159.   end
  160. else
  161.   accout=0;
  162. endmodule

  163. module accumulator_tb;
  164.   reg [7:0]aluout;
  165.   reg clk;
  166.   reg rst;
  167.   wire [7:0]accout;
  168.   accumulator b3(aluout,clk,rst,accout);
  169.   initial
  170.     begin
  171.       clk=0;
  172.       rst=1;
  173.       aluout=6'b101011;
  174.       #10 rst=0;
  175.       #15 rst=1;
  176.       
  177.     end
  178.       always #5 clk=~clk;
  179. endmodule
  180.  
  181. /*module controller();
  182.   output reg rd,rw,de,en;
  183.   reg ps,ns;
  184.  input clk,rst;
  185.   always @(clk)
  186. */
  187. module controller(rst,clk,read,addr,fe,de,ex);
  188.   input rst,clk;
  189.   reg [2:0]ps;
  190.   reg [2:0]ns;
  191.   output reg read,fe,de,ex;
  192.   parameter fetch=3'b000,decode=3'b001,execute=3'b010;
  193.   output reg [3:0]addr=4'b0000;
  194.   always @(posedge clk ,posedge rst)
  195.     if (rst)
  196.       ps<=fetch;
  197.     else
  198.       ps<=ns;
  199.     
  200. always @(clk)
  201.    case(ps)
  202.      fetch: begin
  203.        read=1;
  204.        fe=0;
  205.        de=0;
  206.        ex=0;
  207.     end
  208.     decode:begin
  209.       read=0;
  210.        fe=0;
  211.        de=1;
  212.        ex=0;
  213.      end
  214.      execute:begin
  215.       read=0;
  216.        addr=addr+1;
  217.        fe=0;
  218.        de=0;
  219.        ex=1;
  220.      end
  221. endcase
  222. endmodule


  223. module controller_tb;
  224.   reg rst,clk;
  225.   //reg[2:0]ns;
  226.   wire read;
  227.   wire fe,de,ex;
  228.   controller b1(rst,clk,read,fe,de,ex);
  229.   initial
  230.    begin
  231.      clk=0;
  232.      rst=0;
  233.      #10 rst=1;
  234.      #12 rst=0;
  235.     // #2 ns=3'b001;
  236.   end
  237.      always #5 clk=~clk;
  238. endmodule


  239. module processor(rst,clk,inp,outp);
  240.   input rst;
  241.   input clk;
  242.   input [10:0]inp;
  243.   output [10:0]outp;
  244.   wire accout;
  245.   wire rd;
  246.   wire ex;
  247.   wire de;
  248.   wire read;
  249.   wire addr;  //pc
  250.   wire mout; //meomory output
  251.   wire opcode;
  252.   meomory hk1(addr,read,mout); //read=enable
  253.   ir hk2(mout,rd,out);  //rd-enable  mout-a
  254.   decoder hk3(out,de,opcode,data); //de-enable
  255.   alu4pro hk4(opcode,inp,accout,aluout);    //decoder ka de 8bit data kaise use karon !!!! pehle hi ek acc se i/p ek main i/p donga is module se dusra i/p decoder wale ka kya karonga ...refer to diagram 
  256.   accumulator hk5(outp,clk,ex,accout);  //ex-rst
  257.   controller hk6(rst,clk,read,addr,fe,de,ex);
  258.   
  259. endmodule

  260. module processor_tb;
  261.   reg rst,clk;
  262.   reg[7:0]inp;
  263.   wire [7:0]outp;
  264.   processor hk10(rst,clk,inp,outp);
  265.   initial
  266.     begin
  267.       rst=0;
  268.       clk=0;
  269.       #2 inp=8'b01110101;
  270.       #5 rst=1;
  271.       #7 rst=0;
  272.     end
  273.     
  274.   always #10 clk=~clk;
  275. endmodule
simulation of proccessor_tb

Simulation of ir_tb



Simulation of decoder_tb


simulation of alu4pro_tb


simulation of controller_tb



simulation of accumulator_tb


Scope of Chip Manufacturing

1. AI on Chip


Work Started in 2011




Dhamendra Modha has written a Blog Career Opportunities in Brain-inspired Computing at IBM Research


Power Amplifier [How to read graphs in Analog Electronics]



How RFID works


RFIC Architecture





Top Electronics & Electrical Branch People from Whom you can Inspire .

1.Yael Maguire



2.Mayank Shrivastava


For List of Patents by him [Click Here]

As far as I make out I guess Majority of its Patent are Possible due to its Job in Infineon Technologies ic fabrication plant as experiments are difficult to do .But Anyway in today's life there are many tools like Pyxis where you do gate level modelling and test the simulations without such a plant like its Topic is

1. A DeMOS Device realized using dual STI process 8,097,930

2. A Novel Architecture for Improving Slew Rate in FinFET-based Op-Amps and OTAs  8,089,314

3. ESD Robust Drain Extended MOS Device 8,536,648

4. An IGBT device with plugged-in SCR for robust ESD protection in FinFET technology

5. "Dual Gate STI DeMOS for improved mixed signal and hot carrier behavior

6.Single Halo DeMOS for robust ESD protection in advanced high voltage CMOS

7.Nonvolatile floating gate Analog memory cell

8. High voltage semiconductor devices

9.Independently Driven Double Gate (IDDG) Nonvolatile floating gate analog memory cell

10.Novel Ways of Introducing High Voltage Handling Capabilities in FinFET Technologies  08664720


Friday, 15 April 2016

Error Checking Techniques in Data link Layer

In any communication system there is layer in the top-bottom order in one device shown below

1) Application Layer-encryption
2)Presentation Layer
3)Session Layer-check till how many pages data has sended properly
4)Transport Layer-convert big files to small messages
5)Network Layer-it adds source and destination addresses
6)Data Link Layer-it check error and also further break the messages
7)Physical Layer-Here coding techniques like NRZ-L,NRZ-M,NRZ-S,Biphase-L(Manchester                                          coding),Biphase-M,Biphase s,Bipolar NRZ, Unipolar NRZ etc etc happen here.

at each there there is some memory containing | H | Data | T | i.e Header data tail is updated which finally have to send

Similarly other device say another mobile phone will have these layers in order

Between these devices there is a routers in which communication happen through packet switching,circuit switch,store and forward switching etc etc.

Communication Happening Between one device to another is termed as end to end communication

and Communicative Happening Between router to one particular device is Known as link to link communication.error checking,network checking happen link to link only .you thick yourself if it happens end to end how much time it have taken.Actually Every layer is linked by link to link connection i.e

Session Layer--SLP
Tansport Layer-TLP
in above short forms P stands for protocol similarly others also have some name ..search about it..

In Data Link Layer there are Many Error checking techniques
these are as follow
1)Even parity
2)Odd Parity
3)Cycle redundancy check
4)Bit Stream check-in this we divide by no. of bits and put some remainder and then store this data in                                  tail and send.
5)check sum
and etc etc.


ODD Parity
XOR gate is a ODD parity checker as if there is a odd number of 1's then output gets 1(HIGH)
in veriog you apply XOR operation as ^(100011100)

A     B    OUT
0      0       0          <--Even No of  1  
0      1       1          <--Odd  No of  1    Output--1
1      0       1          <--Odd  No of  1    Output--1
1      1       0          <--Even No of  1    

Even Parity
XNOR gate is a Even parity checker as if there is a even number of 1's then output gets 1(HIGH).
in verilog you apply XNOR operation as ~^(100001111)

A     B    OUT
0      0       1          <--Even No of  1      Output--1
0      1       0          <--Odd  No of  1    
1      0       0          <--Odd  No of  1
1      1       1          <--Even No of  1       Output--1



Processors

DSP Processor

Keypoints that is mentioned in the video given below.But Anyway for detailed information watch just 8:26 minute video given below

Meomory -considering Ram.In Ram Meomory your size of Meomory is judged by no. of chips meomory chips present on it.

DSP processor is a chip that go into the circuit module known as PVDM's{ packet voice dsp module}.Similar to Ram Meomory no. of chips of dsp in PVDM's make me know how big is my PVDMS

DSP processor is used in your router(gateway) to convert TDM format by PSTN into IP format that is understandable by your telephone.

DSP processor  also switch your organization telephone system from PSTN(G711) to WAN(G729).you can say DSP processor is used in transcode.

DSP processor is also used in conferencing between organizations seperated by WAN .both having dedicated DSP's.Moreover ,DSP also enables organization to have confrencing among there team members also via just use of router having DSP's



DSP Processor Commercial




Monday, 11 April 2016

Designing a circuits in mind.

I am visioning an Engineer who don't see the truth table of logic gates and many other devices like BJT,FET etc and test the circuit outputs directly in mind .

And Gate- Non expert person Knows that if any i/p 0 then o/p 0 but side by side to become expert you should also know if both i/p 1 o/p 1

i.e say if any        i/p 0 then o/p 0
            if both/all i/p 1 then o/p 1


For Nand Gate

you know it is an invert of above gate but you might don't grab below thing

i.e say if any        i/p 0 then o/p 1
            if both/all i/p 0 then o/p 0

Or Gate
Non expert person Knows that if any i/p 1 then o/p 1 but side by side to become expert you should also know if both i/p 0 o/p 0

i.e say if any        i/p 1 then o/p 1
            if both/all i/p 0 then o/p 0



similarly remember for other gates also

What More you should Know
BJT peactical working
FET practical working
Monostable
Bistable

Sunday, 10 April 2016

AMBA AHB [BLOG UNDER CONSTRUCTION]

[BLOG UNDER CONSTRUCTION]

AMBA

AMBA is a bus protocol.

What is a protocol ?
In Practical life you can say
It is a way of communication from one entity(let mobile) to another entity (say cloud).
Now every communication system has its specific syntax,semantics and timing.

In Nasa Mars rover   protocol is so slow that rover  data takes 1 hour to reach to the earth. 




AMBA BURST


AMBA RETRY


AMBA SPLIT









'















Code for Master
  1. module ahb_master4(
  2. //transfer response
  3. input hready,
  4. //global signals
  5. input hclk,
  6. input hresetn, //active low
  7. input [1:0]hresp,
  8. //read data
  9. input [31:0]hrdata,
  10. input hgrant,
  11. //address and control

  12. output reg [31:0]haddr,
  13. output reg hwrite,
  14. output reg [2:0]hsize,
  15. output reg [2:0]hburst,
  16. output reg [1:0]htrans,
  17. output reg hreq,
  18. //DATA
  19. output reg [31:0]hwdata
  20.     );
  21. reg [31:0] rhaddr;
  22. reg [31:0]rhrdata;
  23. reg [31:0] mem[8:0];   //it means it has nine meom loc under which there is further 32 locations
  24. reg [2:0] ps,ns;
  25. integer count;
  26. parameter idle=3'b000,trans=3'b001,check=3'b010,Nonseq=3'b011,Seq=3'b100,Write=3'b101,Read=3'b110; 

  27. always @(posedge hclk)
  28. begin
  29. $readmemb("memory.txt",mem);
  30. case(ps)
  31. idle : begin
  32.  if(!hresetn)
  33. begin
  34. haddr=0;
  35. hsize=0;
  36. hburst=0;
  37. htrans=0;
  38. hwdata=0;
  39. hwrite=1;
  40. ns=idle;
  41. end
  42. else if(hready & !hresp)
  43. begin
  44. hreq=1'b1;
  45. ns=trans;
  46. end
  47. end


  48. trans : begin
  49. if(hready & hgrant & !hresp)
  50. begin
  51. htrans<=2'b10;
  52. haddr<=32'd00;
  53. rhaddr<=haddr;
  54. hburst<=3'b010;
  55. hwrite<=1;
  56. hsize<=3'b010;
  57. ns=check;
  58. end
  59. else
  60. ns=idle;
  61. end

  62. check : begin
  63. if(hready & !hresp) begin
  64. if(htrans==2'b10)
  65. begin
  66. ns=Nonseq;
  67. count=0;
  68. end
  69. else if(htrans==2'b11)
  70. begin
  71. ns=Seq;
  72. count=0;
  73. end
  74. else if(htrans==2'b00)
  75. ns=idle;
  76. end
  77. end


  78. Nonseq : begin
  79. if((hgrant==1'b1) & hready & !hresp)
  80. begin
  81. /*haddr<=haddr;
  82. hburst<=3'b000;
  83. hsize<=3'b010;
  84. hwrite<=0;
  85. end*/
  86. if(hwrite)
  87. ns=Write;
  88. else
  89. ns=Read;
  90. end
  91. end

  92. Seq : begin
  93. if((hgrant==1'b1) && hready && !hresp && htrans!=2'b01) //Busy transfer htrans=2'b01
  94. begin
  95. htrans=2'b11;
  96. case(hburst) 
  97. 3'b000 : haddr=haddr; //Single Burst
  98. 3'b001 : begin //Incrementing Burst with undefined length
  99. count=count+1;
  100. if(hsize==3'b000)
  101. haddr=haddr+1;
  102. else if(hsize==3'b001)
  103. haddr=haddr+2;
  104. else if(hsize==3'b010)
  105. haddr=haddr+4;
  106. end
  107. 3'b010 : begin
  108. count=count+1; //Wrapping Burst with 4 beats
  109. if(hsize==3'b000)
  110. begin 
  111. haddr=haddr+1;
  112. if(haddr==rhaddr+16)
  113. haddr=rhaddr;
  114. end
  115. else if(hsize==3'b001)
  116. begin 
  117. haddr=haddr+2;
  118. if(haddr==rhaddr+16)
  119. haddr=rhaddr;
  120. end
  121. else if(hsize==3'b010)
  122. begin 
  123. haddr=haddr+4;
  124. if(haddr==rhaddr+16)
  125. haddr=rhaddr;
  126. end
  127. end
  128.  
  129. 3'b011 : begin
  130. count=count+1; // Incrementing Burst with 4 beats
  131. if(hsize==3'b000)
  132. haddr=haddr+1;
  133. else if(hsize==3'b001)
  134. haddr=haddr+2;
  135. else if(hsize==3'b010)
  136. haddr=haddr+4;
  137. end
  138. 3'b100 : begin
  139. count=count+1;
  140. if(hsize==3'b000) //8 Beat wrapping burst
  141. begin 
  142. haddr=haddr+1;
  143. if(haddr!=rhaddr+32)
  144. haddr=rhaddr;
  145. end
  146. else if(hsize==3'b001)
  147. begin 
  148. haddr=haddr+2;
  149. if(haddr!=rhaddr+32)
  150. haddr=rhaddr;
  151. end
  152. else if(hsize==3'b010)
  153. begin 
  154. haddr=haddr+4;
  155. if(haddr!=rhaddr+32)
  156. haddr=rhaddr;
  157. end
  158. end

  159. 3'b101 : begin
  160. count=count+1; // Incrementing Burst with 8 beats
  161. if(hsize==3'b000)
  162. haddr=haddr+1;
  163. else if(hsize==3'b001)
  164. haddr=haddr+2;
  165. else if(hsize==3'b010)
  166. haddr=haddr+4;
  167. end
  168. 3'b110 : begin
  169. count=count+1;
  170. if(hsize==3'b000) //16 Beat wrapping burst
  171. begin 
  172. haddr=haddr+1;
  173. if(haddr!=rhaddr+64)
  174. haddr=rhaddr;
  175. end
  176. else if(hsize==3'b001)
  177. begin 
  178. haddr=haddr+2;
  179. if(haddr!=rhaddr+64)
  180. haddr=rhaddr;
  181. end
  182. else if(hsize==3'b010)
  183. begin 
  184. haddr=haddr+4;
  185. if(haddr!=rhaddr+64)
  186. haddr=rhaddr;
  187. end
  188. end
  189. 3'b111 : begin
  190. count=count+1; // Incrementing Burst with 16 beats
  191. if(hsize==3'b000)
  192. haddr=haddr+1;
  193. else if(hsize==3'b001)
  194. haddr=haddr+2;
  195. else if(hsize==3'b010)
  196. haddr=haddr+4;
  197. end
  198. endcase
  199. if(hwrite)
  200. ns=Write;
  201. else
  202. ns=Read;
  203. end
  204. else if(hresp==2'b10)
  205. begin
  206. htrans=0;
  207. ns=idle; end
  208. else if(hresp==2'b11)
  209. begin ns<=ps; htrans<=0; end
  210. end

  211. Write : begin
  212. if(hready & !hresp) begin
  213. if(hsize==3'b000)
  214. begin
  215. hwdata[7:0]=mem[7];
  216. end
  217. else if(hsize==3'b001)
  218. begin
  219. hwdata[15:0]=mem[5];
  220. end
  221. else if(hsize==3'b010)
  222. begin
  223. hwdata=mem[2];
  224. end

  225. if(hburst!=0)
  226. begin
  227. if(hburst==3'b001)
  228. ns=Seq;
  229. else if((hburst==3'b010 | hburst==3'b011) & count<3)
  230. ns=Seq;
  231. else if((hburst==3'b100 | hburst==3'b101) & count<7)
  232. ns=Seq;
  233. else if((hburst==3'b110 | hburst==3'b111) & count<15)
  234. ns=Seq;
  235. else
  236. ns=idle;
  237. end
  238. else 
  239. ns=idle;
  240. end
  241. end

  242. Read :begin if(hready & !hresp)
  243. begin
  244. if(hsize==3'b000)
  245. begin
  246. rhrdata=hrdata[7:0];
  247. end
  248. else if(hsize==3'b001)
  249. begin
  250. rhrdata=hrdata[15:0];
  251. end
  252. else if(hsize==3'b010)
  253. begin
  254. rhrdata=hrdata;
  255. end


  256. if(hburst!=0)
  257. begin
  258. if(hburst==3'b001)
  259. ns=Seq;
  260. else if((hburst==3'b010 | hburst==3'b011) & count<3)
  261. ns=Seq;
  262. else if((hburst==3'b100 | hburst==3'b101) & count<7)
  263. ns=Seq;
  264. else if((hburst==3'b110 | hburst==3'b111) & count<15)
  265. ns=Seq;
  266. else
  267. ns=idle;
  268. end
  269. else 
  270. ns=idle;
  271. end
  272. end
  273. endcase
  274. end



  275. always@(posedge hclk)
  276. begin
  277. if(!hresetn)
  278. ps<=idle;
  279. else
  280. ps<=ns;
  281. end

  282. endmodule


Testbench for Master


  1. module ahb_master4_tb;

  2. // Inputs
  3. reg hready;
  4. reg hclk;
  5. reg hresetn;
  6. reg [1:0]hresp;
  7. reg [31:0] hrdata;
  8. reg hgrant;

  9. // Outputs
  10. wire [31:0] haddr;
  11. wire hwrite;
  12. wire [2:0] hsize;
  13. wire [2:0] hburst;
  14. wire [1:0] htrans;
  15. wire hreq;
  16. wire [31:0] hwdata;

  17. // Instantiate the Unit Under Test (UUT)
  18. ahb_master4 uut (
  19. .hready(hready), 
  20. .hclk(hclk), 
  21. .hresetn(hresetn), 
  22. .hresp(hresp), 
  23. .hrdata(hrdata), 
  24. .hgrant(hgrant), 
  25. .haddr(haddr), 
  26. .hwrite(hwrite), 
  27. .hsize(hsize), 
  28. .hburst(hburst), 
  29. .htrans(htrans), 
  30. .hreq(hreq), 
  31. .hwdata(hwdata)
  32. );

  33. initial begin
  34. // Initialize Inputs
  35. hready = 0;
  36. hclk = 0;
  37. hresetn = 0;
  38. hresp = 0;
  39. hrdata = 0;
  40. hgrant = 0;

  41. // Wait 100 ns for global reset to finish
  42. #100;
  43. hready <= 1;
  44. hresetn <= 1;
  45. hresp <= 0;
  46. hrdata <= 32'd4100450780;
  47. hgrant <= 1;

  48. // Wait 100 ns for global reset to finish
  49. #200;
  50. hready <= 1;
  51. hresetn <= 1;
  52. hresp <= 0;
  53. hrdata <= 32'd4123450460;
  54. hgrant <= 1;

  55. #200;
  56. hready <= 0;
  57. hresetn <= 1;
  58. hresp <= 0;
  59. hrdata <= 32'd4123450461;
  60. hgrant <= 1;

  61. // Wait 100 ns for global reset to finish
  62. #200;
  63. hready <= 1;
  64. hresetn <= 1;
  65. hresp <= 2'b11;
  66. hrdata <= 32'd4123450461;
  67. hgrant <= 1;

  68. // Wait 100 ns for global reset to finish
  69. #200;
  70. hready <= 1;
  71. hresetn <= 1;
  72. hresp <= 0;
  73. hrdata <= 32'd4123450461;
  74. hgrant <= 1;

  75. end
  76.       always #20 hclk=~hclk;
  77. initial
  78. $monitor("time=%d,hready=%b,read_data=%d,address=%d",$time,hready,uut.rhrdata,haddr);
  79.         
  80. // Add stimulus here

  81.       
  82. endmodule

Code for slave


  1. module ahb_slave2(
  2. input hsel,
  3. //Address and control
  4. input [31:0]haddr,
  5. input hwrite,
  6. input [1:0]htrans,
  7. input [2:0]hsize,
  8. input [2:0]hburst,
  9. //Data
  10. input [31:0]hwdata,
  11. //Global Signal
  12. input hclk,
  13. input hresetn,
  14. //Output signals
  15. output reg hready,
  16. output reg [1:0]hresp,
  17. output reg [31:0]hrdata
  18.     );
  19. reg rhsel;
  20. reg [31:0]rhaddr;
  21. reg rhwrite;
  22. reg [1:0]rhtrans;
  23. reg [2:0]rhsize;
  24. reg [2:0]rhburst;
  25. reg [31:0]mem[12:0];
  26. always @(posedge hclk,negedge hresetn)
  27. begin
  28. if(!hresetn)
  29. begin
  30. rhsel<=hsel;
  31. rhaddr<=0;
  32. rhwrite<=0;
  33. rhtrans<=0;
  34. rhsize<=0;
  35. rhburst<=0;
  36. hready<=1;
  37. hresp<=0;
  38. end
  39. else if(rhsel)
  40. begin
  41. rhaddr<=haddr;
  42. rhwrite<=hwrite;
  43. rhtrans<=htrans;
  44. rhsize<=hsize;
  45. rhburst<=hburst;
  46. hready=1;
  47. end
  48. end
  49. always @(posedge hclk,rhaddr)
  50. begin
  51. if(rhsel && rhwrite)
  52. begin
  53. if(rhsize==3'b000)
  54. mem[rhaddr[29:0]]=hwdata[7:0];
  55. else if(rhsize==3'b001)
  56. mem[rhaddr[29:0]]=hwdata[15:0];
  57. else if(rhsize==3'b010)
  58.         mem[rhaddr[29:0]]=hwdata;
  59.   
  60.  if(rhaddr<=12) begin
  61. hready=1;
  62. hresp=0; 
  63. end
  64. else begin
  65. hready=0;
  66. hresp=2'b01;
  67. end
  68.  end
  69. else if(rhsel && !rhwrite)
  70. begin
  71. if(rhsize==3'b000) begin
  72. hrdata[7:0]=8'd13;
  73. hrdata[31:8]=24'bx; end
  74. else if(rhsize==3'b001) begin
  75. hrdata[15:0]=16'd34;
  76. hrdata[31:16]=16'bx; end
  77. else if(rhsize==3'b010)
  78. hrdata=32'd134;
  79. if(rhaddr<=12) begin
  80. hready=1;
  81. hresp=0; 
  82. end
  83. else begin
  84. hready=0;
  85. hresp=2'b01;
  86. end
  87. end
  88. end

  89. endmodule

Test Bench for Slave


  1. module ahb_slave2_tb;

  2. // Inputs
  3. reg hsel;
  4. reg [31:0] haddr;
  5. reg hwrite;
  6. reg [1:0] htrans;
  7. reg [2:0] hsize;
  8. reg [2:0] hburst;
  9. reg [31:0] hwdata;
  10. reg hclk;
  11. reg hresetn;

  12. // Outputs
  13. wire hready;
  14. wire [1:0] hresp;
  15. wire [31:0] hrdata;

  16. // Instantiate the Unit Under Test (UUT)
  17. ahb_slave2 uut (
  18. .hsel(hsel), 
  19. .haddr(haddr), 
  20. .hwrite(hwrite), 
  21. .htrans(htrans), 
  22. .hsize(hsize), 
  23. .hburst(hburst), 
  24. .hwdata(hwdata), 
  25. .hclk(hclk), 
  26. .hresetn(hresetn), 
  27. .hready(hready), 
  28. .hresp(hresp), 
  29. .hrdata(hrdata)
  30. );

  31. initial begin
  32. // Initialize Inputs
  33. hsel = 1;
  34. haddr = 0;
  35. hwrite = 0;
  36. htrans = 0;
  37. hsize = 0;
  38. hburst = 0;
  39. hwdata = 0;
  40. hclk = 0;
  41. hresetn = 0;

  42. // Wait 100 ns for global reset to finish
  43. #100;
  44.       
  45. hsel = 1;
  46. haddr = 32'd00;
  47. hwrite = 1;
  48. htrans = 2'b10;
  49. hsize = 3'b010;
  50. hburst = 3'b010;
  51. hwdata = 32'd49;
  52. hresetn = 1;

  53. // Wait 100 ns for global reset to finish
  54. #100;
  55. hsel = 1;
  56. haddr = 32'd04;
  57. hwrite = 1;
  58. htrans = 2'b11;
  59. hsize = 3'b010;
  60. hburst = 3'b010;
  61. hwdata = 32'd45;
  62. hresetn = 1;

  63. // Wait 100 ns for global reset to finish
  64. #100;
  65. hsel = 1;
  66. haddr = 32'd08;
  67. hwrite = 1;
  68. htrans = 2'b11;
  69. hsize = 3'b010;
  70. hburst = 3'b010;
  71. hwdata = 32'd47;
  72. hresetn = 1;

  73. // Wait 100 ns for global reset to finish
  74. #100;
  75. hsel = 1;
  76. haddr = 32'd12;
  77. hwrite = 1;
  78. htrans = 2'b11;
  79. hsize = 3'b010;
  80. hburst = 3'b010;
  81. hwdata = 32'd43;
  82. hresetn = 1;
  83. // Add stimulus here

  84. end
  85.       always #50 hclk=~hclk;
  86. endmodule

Code for AHB


  1. module ahb(
  2. input hclk,
  3. input hresetn,
  4. input hgrant,
  5. output  reg hreq,
  6. input hsel
  7.     );
  8. wire hready;
  9. wire [1:0]hresp;
  10. wire hwrite;
  11. wire [31:0]haddr;
  12. wire [31:0]hwdata;
  13. wire [31:0]hrdata;
  14. wire [2:0]hsize;
  15. wire [2:0]hburst;
  16. wire [1:0]htrans;  

  17. ahb_master4 m1(hready,hclk,hresetn,hresp,hrdata,hgrant,haddr,hwrite,hsize,hburst,htrans,hreq,hwdata);
  18. ahb_slave s1(hsel,haddr,hwrite,htrans,hsize,hburst,hwdata,hclk,hresetn,hready,hresp,hrdata);


  19. endmodule

Code for AHB test bench

module ahb_tb;

  1. // Inputs
  2. reg hclk;
  3. reg hresetn;
  4. reg hgrant;
  5. reg hsel;

  6. // Outputs
  7. wire hreq;

  8. // Instantiate the Unit Under Test (UUT)
  9. ahb uut (
  10. .hclk(hclk), 
  11. .hresetn(hresetn), 
  12. .hgrant(hgrant), 
  13. .hreq(hreq), 
  14. .hsel(hsel)
  15. );

  16. initial begin
  17. // Initialize Inputs
  18. hclk = 0;
  19. hresetn = 0;
  20. hgrant = 0;
  21. hsel = 0;

  22. // Wait 100 ns for global reset to finish
  23. #200;
  24. hresetn =0;
  25. hgrant = 1;
  26. hsel = 1;

  27. // Wait 100 ns for global reset to finish
  28. #100;        
  29. // Add stimulus here
  30. hresetn = 1;
  31. hgrant = 1;
  32. hsel = 1;

  33. // Wait 100 ns for global reset to finish
  34. end
  35.       always #50 hclk=~hclk;
  36. endmodule



Battery Charging Circuits

In your Home Socket there comes an AC that you convert into DC using your adapter [AC-->Transformer[Coils Mutual Induction] {for step down} + Rectifier [wave shaping circuits] + Capacitor-->DC]

once DC come out of Adapter Via USB you charge your battery

Between USB port and battery there is some circuit that charges the Battery which is embedded with many features.

Q What are these Circuits Responsible for ?

Ans . Many things like
1) Battery protection circuit-Sometime Battery itself featured by this function.Sometime we have to provide this function using some special circuitry like using IC-DW01A
beside this function there is many more fuction .To Know about it Watch the Video that is provided in the end.

Q What Kind of Circuits/IC's that are currently available in the Market to charge battery via USB ?

Ans
  1.  MCP73831-charge 0.5 A 
  2.  TP4056 -charge 1 A [Recoccmended for  LiPos Battery]   {LiPos are rectangular shaped batteries        where as Lions are cylinderical shaped Batteries }


Buy TP4056 at Rs 119/- from Ebay [Click Here] to Buy One


For Detailed In-depth Understanding about TP4056 Watch the Video Shown below