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

TouchButton::setPinValue(1) results in a pin voltage lower than Vin #346

Open
microbit-carlos opened this issue Jun 28, 2023 · 6 comments
Open
Assignees
Labels
Milestone

Comments

@microbit-carlos
Copy link
Collaborator

microbit-carlos commented Jun 28, 2023

To replicate on USB power:

  • Flash this programme to a micro:bit
  • Press button A, this sets P16 high
  • Measure the edge connector P16 voltage, should be ~3.3V ✅
  • Press button B and wait for the display to clear
    • Now pin16 has been configured as a TouchButton
  • Press button A again, this sets the P16 TouchButton to digital high
  • Measure the edge connector P16 voltage, it is now around ~2.2V ❌

MICROBIT.hex.zip

#include "MicroBit.h"

MicroBit uBit;

int main() {
    uBit.init();

    while (!uBit.buttonB.isPressed()) {
        if (uBit.buttonA.isPressed()) {
            uBit.display.print("A");
            uBit.io.P16.setDigitalValue(1);
            // Voltage at this point in P16 is around ~3.3V
        }
        uBit.sleep(250);
    }

    TouchButton *pin16Touch = new TouchButton(uBit.io.P16, uBit.touchSensor, CAPTOUCH_DEFAULT_CALIBRATION);

    uBit.sleep(1000);
    uBit.display.clear();
    while (true) {
        if (uBit.buttonA.isPressed()) {
            uBit.display.print("A");
            pin16Touch->setPinValue(1);
            // Voltage at this point in P16 is around ~2.2V
        } else if (uBit.buttonB.isPressed()) {
            uBit.display.print("B");
            pin16Touch->setPinValue(0);
        }
        uBit.sleep(250);
    }
}
@microbit-carlos microbit-carlos changed the title TouchSensor::setPinValue() on a pin results in a voltage lower than Vin TouchSensor::setPinValue(1) results in a pin voltage lower than Vin Jun 28, 2023
@microbit-carlos microbit-carlos changed the title TouchSensor::setPinValue(1) results in a pin voltage lower than Vin TouchButton::setPinValue(1) results in a pin voltage lower than Vin Jun 28, 2023
@finneyj finneyj self-assigned this Jun 29, 2023
@microbit-carlos microbit-carlos added this to the v0.2.57 milestone Jun 29, 2023
@JohnVidler
Copy link
Collaborator

JohnVidler commented Jul 19, 2023

S'cuse the bad photo, but having tested this on P2 (for ease of connection to the scope), I see this waveform when touch mode is enabled and setValue(1) is called - this looks like the peripherals are fighting each other:
image

The PWMing effect of this would account for the lower voltage you're seeing, I guess @microbit-carlos

Edit I just noticed that the average the scope reports is 2.27v, which is right where you see it...

@microbit-carlos
Copy link
Collaborator Author

Yeah, that would explain the voltage value.

Btw, how is capacitance touch done on the digital pins with CODAL? Isn't setting the pin high and then measuring how long it takes to go low? Do you get the same waveform when setValue() is not called and is checking "isTouched" in a loop?

@microbit-carlos microbit-carlos modified the milestones: v0.2.57, v0.2.58 Jul 25, 2023
@finneyj
Copy link
Contributor

finneyj commented Aug 2, 2023

Now fixed according to my VW Passat GTE scope, as per #345

passat-scope

@microbit-carlos
Copy link
Collaborator Author

microbit-carlos commented Aug 3, 2023

But Joe, we were testing pins not the g-force events! 🤣

I've given this a quick test with the latest commits in all codal repos:

$ python build.py -s

***/Users/microbit-carlos/workspace/mbef/codal/microbit-v2-samples/libraries/codal-core
Branch: master, Nearest Tag: streamracefix-v0 (32cc87c3298a49663c3b3b7b1881ec7aeb3d73a5)
## master...origin/master

***/Users/microbit-carlos/workspace/mbef/codal/microbit-v2-samples/libraries/codal-nrf52
Branch: master, Nearest Tag: ~none~ (2dbf5aa214c7432c0b1b8a19e92a3f9a4fc4b9da)
## master...origin/master

***/Users/microbit-carlos/workspace/mbef/codal/microbit-v2-samples/libraries/codal-microbit-nrf5sdk
Branch: master, Nearest Tag: ~none~ (ef4662e13875a7b03e7296d7ac24a2b4d231f323)
## master...origin/master

***/Users/microbit-carlos/workspace/mbef/codal/microbit-v2-samples/libraries/codal-microbit-v2
Branch: , Nearest Tag: v0.2.57 (018864dddb64ebf4e2cfbf13cbba1998e8b55d62)
## HEAD (no branch)

***/Users/microbit-carlos/workspace/mbef/codal/microbit-v2-samples
Branch: master, Nearest Tag: v0.2.11 (82691961f838e997593759538cca7f3999c3704d)
## master...origin/master
 M codal.json
 M source/main.cpp

018864d
lancaster-university/codal-nrf52@2dbf5aa
lancaster-university/codal-core@32cc87c

And with a simple test programme like this, I'm still seeing ~2.2-2.6V in pin16 and the face logo with a multimeter:

#include "MicroBit.h"

MicroBit uBit;

int main() {
    uBit.init();

    TouchButton *pin16Touch = new TouchButton(uBit.io.P16, uBit.touchSensor, CAPTOUCH_DEFAULT_CALIBRATION);

    pin16Touch->setPinValue(1);
    uBit.logo.setPinValue(1);

    while (true) {
        uBit.sleep(1000);
    }
}

@microbit-carlos
Copy link
Collaborator Author

microbit-carlos commented Aug 3, 2023

Okay, with this other test I can confirm that using uBit.io.xxxx.setDigitalValue(1); with a pin used in a TouchButton does work. But using the TouchButton:: setPinValue() does not.

With this programme:

  • On startup (TouchButton::setPinValue()) measure pin 16 and pin logo: voltages around 2.2-2.6V ❌
  • Press button A (NRF52Pin::setDigitalValue()), measure pin 16 and pin logo: 3.3V ✅
#include "MicroBit.h"

MicroBit uBit;

int main() {
    uBit.init();

    TouchButton *pin16Touch = new TouchButton(uBit.io.P16, uBit.touchSensor, CAPTOUCH_DEFAULT_CALIBRATION);

    pin16Touch->setPinValue(1);
    uBit.logo.setPinValue(1);

    while (true) {
        if (uBit.buttonA.isPressed()) {
             uBit.io.logo.setDigitalValue(1);
             uBit.io.P16.setDigitalValue(1);
             uBit.display.print("A");
        } 
        uBit.sleep(200);
    }
}

@microbit-carlos
Copy link
Collaborator Author

Ah, that'll likely be because TouchButton::setPinValue() locks the pin before running pin.setDigitalValue():

https://github.com/lancaster-university/codal-core/blob/32cc87c3298a49663c3b3b7b1881ec7aeb3d73a5/source/drivers/TouchButton.cpp#L133-L138

void TouchButton::setPinValue(int v)
{
    setPinLock(true);
    _pin.setDigitalValue(v);
    setPinLock(false);
}

@microbit-carlos microbit-carlos modified the milestones: v0.2.58, v0.2.59 Aug 8, 2023
@microbit-carlos microbit-carlos added p2 and removed p0 labels Aug 8, 2023
@microbit-carlos microbit-carlos modified the milestones: v0.2.60, v0.2.61, v0.2.62 Sep 15, 2023
@microbit-carlos microbit-carlos modified the milestones: v0.2.64, v0.2.65 Nov 3, 2023
@microbit-carlos microbit-carlos modified the milestones: v0.2.65, v0.2.66 Nov 14, 2023
@microbit-carlos microbit-carlos modified the milestones: v0.2.68, v0.2.69 May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants