User Tools

Site Tools

한국어

moacon:countmode:index

countMode

void countMode (u8 cntChannel, u8 cntMode)

cntChannel Channel number (0 or 1 for DP-HCNT)
cntMode 0 = basic counter increments on both the rising and falling edge of the input.
1 = encoder counter that counts up or down based on the phase difference between A and B
2 = basic counter increments on the rising edge of the input.
3 = basic counter increments on the falling edge of the input.

When cntMode is 0, 2, or 3 the channel functions as a basic counter. The module reads from port A (A0 for channel 0, A1 for channel 1). When in this mode, nothing should be connected to port B (B0 for channel 0, B1 for channel 1).

When cntMode is 1, the channel functions as an encoder counter.

The module counts up or down based on the phase difference between A and B. If A leads B, the counter counts up. If B leads A, the counter counts down. The count is updated on both rising and falling edges.

countMode will always initialize the count to 0. The count will roll over (65,535 to 0 if increasing, and 0 to 65,535 if decreasing) when the count exceeds 65,535 (16 bit maximum) or falls below 0.

When using a 24V open-collector type encoder, connect like this.

countMode(0,0); // Simply, set the counter mode
cnt = count(0); // Reads the current count value of channel 0

MOACON home

moacon/countmode/index.txt · Last modified: 2020/11/06 15:12 by COMFILE Technology