User`s manual

BL1600 System Development s 37
High-Speed DMA Counter
The two DMA channels of the Z180 are used as high-speed counters (up to
500 kHz). Function calls load the countdown value for the DMA channel
and enable the DMA interrupt. Once a counter reaches zero, flags for the
DMA channel are set to 1. Your program can monitor these flags.
void DMA0Count( unsigned integer count )
Loads DMA Channel 0 with the count value and enables the DMA
Channel 0 interrupt. The function sets the flag
_
DMAFLAG0 to zero.
When count negative edges have been detected, the channel will cause
an interrupt and the interrupt service routine will set the flag
_
DMAFLAG0
to 1. A program can monitor
_
DMAFLAG0
to determine if
the number of counts has occurred.
void DMA1Count( unsigned integer count )
Loads DMA Channel 1 with the count value and enables the DMA Chan-
nel 1 interrupt. The function sets the flag
_
DMAFLAG1
to zero. When count
negative edges have been detected, the channel will cause an interrupt and
the interrupt service routine will set the flag
_
DMAFLAG1
to 1. A program
can monitor
_
DMAFLAG1
to determine if the number of counts has occurred.
unsigned integer DMASnapShot( byte channel,
unsigned integer *counter )
Reads the number of pulses that a DMA channel (0 or 1) has counted. A
DMA counter is initialized with one of the two preceding functions. If a
DMA channel is counting too fast to allow for stable reading of the count
value, the function returns 0. If the function reads a stable count value, it
returns 1 and sets the parameter count. Note that even if you are unable
to read the counts, DMA interrupts will still occur when the DMA channel
counts down from its loaded value.
Sample DMA Counter Program
main(){
unsigned integer count, oldcount;
oldcount = 0;
DMA0Count( 100 ); // count 100 pulses
while( !DMA0FLAG ){ // not finished
if( DMASnapShot(0,&count) ){ // is it stable?
if( oldcount != count ){
oldcount = count;
printf( DMA counted %u\n, count );
}
}
}
printf( finished counting\n );
}