Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Input pullup was on for half cycle!? #36

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions CapacitiveSensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,12 @@ void CapacitiveSensor::set_CS_Timeout_Millis(unsigned long timeout_millis){
int CapacitiveSensor::SenseOneCycle(void)
{
noInterrupts();
DIRECT_WRITE_LOW(sReg, sBit); // sendPin Register low
DIRECT_MODE_INPUT(rReg, rBit); // receivePin to input (pullups are off)
DIRECT_MODE_OUTPUT(rReg, rBit); // receivePin to OUTPUT
DIRECT_WRITE_LOW(rReg, rBit); // pin is now LOW AND OUTPUT
DIRECT_WRITE_LOW(rReg, rBit); // turn off input pullup
DIRECT_MODE_OUTPUT(rReg, rBit); // receive Pin to OUTPUT
DIRECT_WRITE_LOW(rReg, rBit); // receive pin is now LOW AND OUTPUT
delayMicroseconds(10);
DIRECT_MODE_INPUT(rReg, rBit); // receivePin to input (pullups are off)
DIRECT_WRITE_HIGH(sReg, sBit); // sendPin High
DIRECT_MODE_INPUT(rReg, rBit); // receivePin to input (pullup is off)
DIRECT_WRITE_HIGH(sReg, sBit); // sendPin High
interrupts();

while ( !DIRECT_READ(rReg, rBit) && (total < CS_Timeout_Millis) ) { // while receive pin is LOW AND total is positive value
Expand All @@ -175,11 +174,10 @@ int CapacitiveSensor::SenseOneCycle(void)

// set receive pin HIGH briefly to charge up fully - because the while loop above will exit when pin is ~ 2.5V
noInterrupts();
DIRECT_WRITE_HIGH(rReg, rBit);
DIRECT_MODE_OUTPUT(rReg, rBit); // receivePin to OUTPUT - pin is now HIGH AND OUTPUT
DIRECT_WRITE_HIGH(rReg, rBit);
DIRECT_MODE_INPUT(rReg, rBit); // receivePin to INPUT (pullup is off)
DIRECT_WRITE_LOW(sReg, sBit); // sendPin LOW
DIRECT_MODE_OUTPUT(rReg, rBit); // receivePin to OUTPUT
DIRECT_WRITE_HIGH(rReg, rBit); // receive pin is now HIGH AND OUTPUT
DIRECT_MODE_INPUT(rReg, rBit); // receivePin to INPUT (pullup is off)
DIRECT_WRITE_LOW(sReg, sBit); // sendPin LOW
interrupts();

#ifdef FIVE_VOLT_TOLERANCE_WORKAROUND
Expand Down