EETimes

Embedded Systems October 2000 Vol13_11

Issue link: http://dc.ee.ubm-us.com/i/71842

Contents of this Issue

Navigation

Page 125 of 181

i I o = with the fi ltered value and filter con- stant, and a simple first-order fi lter is performed on the system and the fi l- tered value is upda ted. Create the output driver routines The output driver routines are used to output data when direct writes to the output are not feasib le, such as in a timer output that must interrupt on each edge, or when the outputs need to be periodically refreshed. Listi ng 7 shows an output driver for a frequency output in an Intel 87C196 processor. This intermpt routine calls a frequen- cy handler that sets the time of the next interrupt. The structure member *output->time_register is a pointer to the actual compare register, and Lhe member o utput->period is the time between toggles of the o utput. EPAO has been setup to toggle th e output whenever a compare occur, which presumes that the output is a 50% LISTING 3 Obtaining an analog il}put value /************************************ * Define an access of an anaLog input that is packed in a structure with the * raw vaLue and the fiLtered vaLue. This input has the capabiLity to determine * if the input is vaLid and use a defauLt vaLue if invaLid. ************************************/ #define GetNAMEVaLue() \ ┬źNAMEstructure.vaLidvaLue == TRUE)?\ NAMEstructure.fiLteredvaLue:NAMEstructure.defauLtvaLue) U8 GetNAMEVaLue(void) { if(NAMEstructure.vaLidvaLue = TRUE) return NAMEstucture.fiLteredvaLue; eLse return NAMEstructure.defauLtvaLue; } duty cycle frequen cy Thel-efore, output->period IS o utput. th e period of the output signal. The value of FreqOutput. period has been previ- ously set using SetFreqOut putVa LueO function. Create support routines Finally, create the support routines th at wi ll be used to debounce inputs , filter inputs, and scale inputs or out- puts. These routines are gene ral in nature and will no t be covered he re. The focu, however, should be on gene ric routines that do not use any global variables. Al l information that is needed is pas ed to the routine in the fu nction call. Function name advantages and disadvantages The advantage of using the function name me thod is that access to data is fast. Reads are e ithe r d irectly to global memory, or through a quick single function call. Writes are e ithe r directly to a port, to a global memory location, or through a quick single function call. The read and write functions tllat are writlen are straigh tforward and simple. The di advantages include difficu l- LISTING 4 Setting a buffered output / ************************************ * Define an access of a timer port output that is * connected to a port on the micro. A buffer is written * that is accessed on the next sampLe of the driver. ************************************/ #define SetNAMEVaLue(A) \ ┬źNAMEvariabLe > NAMEMAX)?\ (NAMEvariabLe = NAMEMAX): (NAMEvariabLe = A┬╗ void SetNAMEVaLue(U16 vaLue) { if(vaLue > NAMEMAX) NAMEvariabLe eLse NAMEvariabLe = vaLue; } 124 OCTOBER 2000 Embedded Systems Programming = NAMEMAX; .. ty to set up, poor cod e reuse, e rror prone, and extensive use of globa l variables. Whenever tlle source of an input changes, multiple sections of tlle code may need to be re-written or new macros defined. Defi ning new macros also requires re-compi ling. Debugging of macros is vel)' difficu ll. API calls The API calls method requ ires development of a ge ne ri c API that is called by the application program usin g structures that conta in the I/O informatio n. T he amo unt of actual code written for each new applicatio n is minimal or n o n-exis- tent. T h e steps to impleme n t the API call s method can be split in to two sections-on e time code devel- opment an d integration into the appli catio n .

Articles in this issue

Archives of this issue

view archives of EETimes - Embedded Systems October 2000 Vol13_11