Documente Academic
Documente Profesional
Documente Cultură
Dr. Andrew Greensted Last modified: 8th July 2010 Hide Menu
I C Controller
The I C standard is used in a wide variety of electronic components. Everything from microcontrollers to digital compasses make use of the standard for inter-device communication. The VHDL modules described here can be used to master an I C bus. The Simple Master Module provides a simple method of interfacing a microcontroller to a I C bus, whereas the Controller Module is programmable and allows complex sequences of basic I C communication operations to be offloaded from the main host processor. System Overview The Simple Master Module The Controller Module
S stem Overview
The Simple Master Module performs the basic I C operations: S A T S O , R S A T W I E R A A Kand R A N C . This module can be TR, TP ETR, RT, ED C ED AK used on its own and can easily be interfaced to a microcontroller, see (a) in figure below. The second module is a basic controller that can be programmed to perform whole sequences of I C communication operations. The idea is to offload the task of low-level bus control from the host processor, see (b) in the figure below. For example, the controller could be programmed to periodically read values from a thermometer, compass and accelerometer without any other control required from the host processor, which then only has to read off the sensor data values once collected.
The I C Controller Module makes it possible to offload a lot of low level I C operations from the host processor
If you have a very complex I C slave peripheral, then direct control available with the Simple Master Module is probably best way to go. However, for most other tasks, you can free up valuable microprocessor cycles by making use of the Controller Module. The VHDL for the modules is linked to below. I C VHDL Modules
www.labbookpages.co.uk/fpgas/modules/i2cController.html
1/5
12/5/11
The
f he VHDL
d eae h
he e i
de c i i
be
.O eai
f he
d ei
e.
The e i ed e a i i a ied he o e a i ni prto ,a e a da a d t M t 2 u if he e a i i a I C W I E D T . aasrBs 2_RT_AA The e a i i a ed b a i g e ab e. Whe he e a i i c e e he d n ig a i g high (i e ai high oe i he e e ab e e). If he e a i a a I C W I E D T , he ac 2_RT_AA edge e e f he a e i a ai ab e s a e c . If he e a i lvAk a a I C R A _ A A A K I C R A _ A A N C he ead da a i a ai ab e 2_EDDT_C 2_EDDT_AK dtBsMt. aau2sr
File E cerpt: I C i p e a t r h l 2SmlMse. d ett ICipeatri ni 2SmlMse s gnrc TC_U eei( IKNM pr ( ck ot l rst ee slu cOt san dI sau dOt eal nbe oeain prto dn oe dtMt2u aasrBs dtBsMt aau2sr saec lvAk edICipeatr n 2SmlMse; :itgr; nee) :i sdlgc n t_oi; :i sdlgc n t_oi; :otsdlgc u t_oi; :i sdlgc n t_oi; :otsdlgc u t_oi; :i sdlgc n t_oi; :i ICMSE_P n 2_ATRO; :otsdlgc u t_oi; :i sdlgcvco( dwt 0; n t_oi_etr7 ono ) :otsdlgcvco( dwt 0; u t_oi_etr7 ono ) :otsdlgc; u t_oi)
- Sata oeain - tr n prto - Oeainrqie - prto eurd - IdctsMse i dn (o bs) - niae atr s oe nt uy - Dt fo Mse t ICBs - aa rm atr o u - Dt fo ICBs(lv)t Mse - aa rm u sae o atr - Akoldelvlfo sae(nwie - cnweg ee rm lv o rt)
be . A f a ic c
ci
ca ed t _ 2 _ A T R O i oICMSE_P e da a b .
fnto t_2_ATRO(vle:sdlgcvco( dwt 0 )rtr ICMSE_Pi ucin oICMSE_P au t_oi_etr2 ono ) eun 2_ATRO s vral rsl :ICMSE_P aibe eut 2_ATRO; bgn ei cs vlei ae au s we b00 = rsl : ICSAT hn "0" > eut = 2_TR; - 0 we b01 = rsl : ICRSAT hn "0" > eut = 2_ETR; - 1 we b00 = rsl : ICSO; hn "1" > eut = 2_TP - 2 we b01 = rsl : ICWIEDT; hn "1" > eut = 2_RT_AA - 3 we b10 = rsl : ICRA_AAAK hn "0" > eut = 2_EDDT_C; - 4 we ohr = rsl : ICRA_AANC; hn tes > eut = 2_EDDT_AK - 5 edcs; n ae rtr rsl; eun eut
www.labbookpages.co.uk/fpgas/modules/i2cController.html
2/5
12/5/11
edfnto t_2_ATRO; n ucin oICMSE_P
The waveforms below show the Simple Master in operation. Note that this simulation does not include any slave response. So, the slave acknowledge and read data is always read as logic 1.
www.labbookpages.co.uk/fpgas/modules/i2cController.html
3/5
12/5/11
NOTE: The Simple Master Module does not respect clock stretching, a technique used by slaves to pause the master. In most cases this should not be a problem. However, keep it in mind if communication fails occasionally.
The table below describes the available instructions. It's worth mentioning at this stage that the controller design is quite simple and so is easily adjusted to suite other requirements. Instruction ICWIERG 2_RT_E ICWIEIM 2_RT_M Argument, 3 Data, 8 bits bits Register Number Immediate Value Immediate Value Immediate Value Immediate value Address Lower 8 bits of delay count Instruction Address Description Write the data value held in the specified register to the I C bus. Write the immediate value to the I C bus. Read data from the I C bus and load into designated register. Can either A Kor N C the C AK slave. Load the immediate value into the selected register. Add the immediate value to a value held in the selected register. Subtraction is achieved by adding (256 - immediate value). Compare the immediate value with the data value held in the selected register. The result can be used for conditional jumps. Output the value held in the selected register to d u . Output the address value to Ot duAd Otd. Delay the controller for the selected number of milliseconds. Jump to instruction. If condition is E U L only jump if C M matched. If condition is QA, OP N T E U L only jump if C M did not match. If condition is A W Y always jump. O_QA, OP LA, Hold the controller until a the n t f input is asserted. Whilst held, the h l output is oi ed high
I C R A _ A A A K Register 2_EDDT_C I C R A _ A A N C Number 2_EDDT_AK LA OD AD D CM OP OTU UPT DLY EA JM UP HL OD Register Number Register Number Register number Register Number Upper 3 bits of delay count Condition -
The VHDL module entity is shown below. Like the Simple Master, it has a very simple interface. The C K F E generic is used to calibrate the L_RQ D L Yinstruction. Set it to the frequency of the c ksignal in Hertz. The T C _ U generic is set in the same way as described above. The EA l IKNM important part is the P O R Mgeneric that specifies what the controller does. RGA
File E cerpt: I C o t o l r h l 2Cnrle. d ett ICotolri ni 2Cnrle s gnrc(L_RQ eei CKFE ICTC_U 2_IKNM PORM RGA pr ( ck ot l rst ee slu cOt san dI sau dOt hl ed ntf oi duAd Otd :itgr nee; :itgr nee; :ICCNRLE_RG; 2_OTOLRPO) :i sdlgc n t_oi; :i sdlgc n t_oi; :otsdlgc u t_oi; :i sdlgc n t_oi; :otsdlgc u t_oi; :otsdlgc u t_oi; :i sdlgc n t_oi; :otsdlgcvco( dwt 0; u t_oi_etr3 ono )
www.labbookpages.co.uk/fpgas/modules/i2cController.html
4/5
12/5/11
d Ad O d d O n D a e a ak o cE edICo ol ; n 2Cn le :o :o :o :o
E ample Program
The controller program is specified as a generic when a controller module is instantiation. An example program is shown below. It is used to read ultrasonic and infrared data from 6 range finding modules. A flow chart for the program is shown to the right. Operation is quite simple. A module counter variable and address variable are first initialised. Then, each module is queried in turn. The counter variable is incremented after each query and checked to see if all 6 modules have been read. The H L instruction is then used to tell the OD host microprocessor that data is ready. When the n i input is asserted, reading loop is o f restarted.
cn a ICPO :ICCNRLE_RG0 o1): ( o n 2_RG 2_OTOLRPO( 7 = (p= DLY o > EA, ag= b01, > "1" d a= "8) a > E", (p= LA, o > OD (p= LA, o > OD ag= R, > 0 ag= R, > 1 d a= "0) a > 0", d a= "1) a > C", d a= a > d a= a > d a= a > d a= a > d a= a > "0) 0", "0) 0", "0) 0", "0) 0", "0) 0",
- 0 Sa - :
pDl ( ) ea 1
- 1 Iiil eMdl Nme - : n ai o e b - 2 Iiil eAde - : n ai d - 3 Sa - : - 4 - : Cn o B e(ed o l Ra) - 5 - : Ra l aon ag ed d ne - 6 - : Ra ifae ag ed n d ne - 7 So - : p - 8 O p - : - 9 O p - : - 1:O p - 0 Mdl Nme o e b l aon d ifae ag n d ne
(p= ICSAT o > 2_TR, ag= VI, > OD (p= ICWIERG o > 2_RT_E, ag= R, > 1 (p= ICRA_AAAK ag= R, o > 2_EDDT_C, > 2 (p= ICRA_AANC,ag= R, o > 2_EDDT_AK > 3 (p= ICSO, o > 2_TP ag= VI, > OD (p= OTU, o > UPT (p= OTU, o > UPT (p= OTU, o > UPT (p= DLY o > EA, (p= AD o > D, (p= AD o > D, (p= CM, o > OP (p= JM, o > UP (p= HL, o > OD (p= JM, o > UP ) ; ag= R, > 0 ag= R, > 2 ag= R, > 3 ag= b00, > "0" ag= R, > 0 ag= R, > 1
d a= "0) a > 0", d a= "1) a > 0", d a= "2) a > 0", d a= "8) a > 1", d a= "1) a > 0", d a= "2) a > 0",
ag= R, > 0 d a= "6) a > 0", - 1:T - 4 e Mdl Nme o e b ag= NTEUL d a= ad(),- 1:Jm on > O_QA, a > d 3) - 5 p e oa n ag= VI, > OD ag= AWY, > LAS
ed a
d a= "0) a > 0", - 1:Wi f - 6 a o inlfo h ga m o d a= ad() - 1:Jm oiiil eAde a > d 1) - 7 p n ai d
www.labbookpages.co.uk/fpgas/modules/i2cController.html
5/5