Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.


Channels ▼
RSS

Implementing Direct Memory Access (DMA) in C


May 1992/Implementing Direct Memory Access (DMA) in C/Listing 6

Listing 6 (timer.c) Basic Routines for Programming the 9513 Timer Counter on the Lab Master AD

/*****************************************************

       Basic Routines for programming the 9513 timer
       counter on the Lab Master AD.

       Copyright Don Bradley, 1991.

       Permission is granted for used of these routines
       in any manner as long as this copyright notice is
       included.

       Tested using Quick C 2.5 and MSC 6.0 on a
       Toshiba T5200.

*****************************************************/

#include <math.h>
#include <conio.h>

#include "labmastr.h"

void timer_reset()
       {
       /* reset 9513 timer\counter */
       outp(TIMER_CONTROL, 0xFF);

       /* Enable 16-bit Data Access */
       outp(TIMER_CONTROL, 0xEF);

       /* initalize master mode reg */
       outp(TIMER_CONTROL, 0x17);

       /* BCD Division, 16 Bit Data */
       outpw(TIMER_DATA, 0xA000);
       }

void timer5_on()
/*& Turns timer 5 on. Used to start ADC output from the
        fifo thru manual or DMA control. */
       {
       /* turn timer 5 on */
       outp(TIMER_CONTROL, 0x30);
       }

void timer5_off()
/*& Turns timer 5 off. Used to stop or disable ADC
        output from the fifo thru manual or DMA control. */
       {
       /* turn timer 5 off */
       outp(TIMER_CONTROL, 0xD0);
       }

#define COUNTSTART 0xb
#define COUNTHIGH 0xf

double timerad(double freq)
/*& Sets timer 5 of the labmaster board to the desired
        frequency for data collection. */
       {
       double time;
       unsigned count = COUNTSTART;

       time = TIMER_F1 / freq;
       while (1) {
              if (time < 65536.0)
                     break;
              time /= TIMER_DIVISOR;
              ++count;
              }
       if (count <= COUNTHIGH) {
              timer5_off();

              freq = TM_TIMER F1 / ((unsigned) (time) *
                    pow(10.0, (double) (count - COUNTSTART)));

              // initalize master mode register
              outp(TIMER_CONTROL, 0x17);
              // BCD Division, 16 Bit Data Bus counter 5 setup
              outpw(TIMER_DATA, 0xA000);
              outp(TIMER_CONTROL, 0x5);

              // No Gating, Count on Rising Edge,
              // F(count-COUNTSTART), Count Repetitively,
              // Count Down, Active High Terminal Count Pulse
              // frequency range 400Hz to 4MHz
              outpw(TIMER_DATA, (count << 8) | 0x21);

              outpw(TIMER_DATA, (int) time);

              timer5_on();
              }
       else
              freq = 0.0;
       return (freq);
       }

void step_timerad()
       {

       timer5_off();

       // Point to Counter 5
       outp(TIMER_CONTROL, 0x5);

       // Active High output, Count Down, Binary Counting,
       // Count Repeatedly, Reload from Load Register
       // only, No Gateing, No Special Gate, Count Falling
       // Edges and Use Source 5.
       outpw(TIMER_DATA, 0x1521);
       outpw(TIMER_DATA, 2);

       // Load Counter 5
       outp(TIMER_CONTROL, 0x50);
       timer5_on()
       // Step Counter 5
       outp(TIMER_CONTROL, 0xF5);
       }
/* End of File */

Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.