我们正在从引脚读取一些信号,并根据此读数设置更多事件.
为了安全起见,我想对引脚进行3次采样,比较三个值并使用最常见的值(即样本A为1,B为3,C为1,如果AB和C为全部,我想使用1 2然后使用2但是如果A是1,B是2而C是3,我想再次捕获三个样本).
目前我正在使用:
int getCAPValues (void)
{
// Get three samples to check CAP signals are stable:
uint32_t x = (PORT->Group[IN_PORT_CAP].IN.reg & IN_PORT_CAP_MASK) >> IN_PORT_CAP_PIN; // First set of CAP values
for (uint32_t i = 0; i < 7; i++) dummy = i; // Pause
uint32_t y = (PORT->Group[IN_PORT_CAP].IN.reg & IN_PORT_CAP_MASK) >> IN_PORT_CAP_PIN; // second set
for (uint32_t i = 0; i < 7; i++) dummy = i; // Pause
uint32_t z = (PORT->Group[IN_PORT_CAP].IN.reg & IN_PORT_CAP_MASK) >> IN_PORT_CAP_PIN; // …Run Code Online (Sandbox Code Playgroud)