User Tools

Site Tools

한국어

moacon:count:index

count

u16 count (u8 cntChannel)

cntChannel : Channel number (0 or 1 for DP-HCNT)
returns the current value of the counter on channel, cntChannel

Reads the current value of the counter on channel, cntChannel. The counter counts independently of the processor, so while other parts of the program may be running, the counter is still counting. Calling count returns the current value in the counter.

countMode(0,0);        // Set channel 0 to function as a basic counter
u16 cnt = count(0);    // Read current count from channel 0
 
countMode(0,1);        // Set channel 0 to function as an encoder counter
u16 cnt = count(0);    // Read current count from channel 0

If reading signed values is desired, the return value should be interpreted in 2's complement (-1 = 0xFFFF) and should be stored as a singed 16 bit integer (short data type). 16 bit signed integers have a range of – 32,768 to 32,767.

countMode(0,1);          // Set channel 0 to function as an encoder counter
short cnt = count(0);    // Read current count from channel 0 (signed numbers)

If you need to scale the counter to support higher count values, use the countPrescaler function.

go MOACON home

moacon/count/index.txt · Last modified: 2016/04/14 11:07 (external edit)