Jump to content
  • 0

uc32 erratic/random input values. INPUT_PULLUP does not help


fourchette

Question

Hello,

I am working on a uc32 chipkit board adapting some existing arduino code.

somewhere in the code, i am using
 

#define pin_switch1 A8
//...
pinMode(pin_switch1,INPUT_PULLUP);
// ....
digitalRead(pin_switch1);

 

Hardware wise, i have a physical mecanical button can when pressed connects the pin to GND and when unpressed does not connect anything (open circuit)

At runtime, I observe that once the button is pressed, it works as expected. However, when buttun is unpressed (nothing connected to the pin), i observe erratic random values (0 or 1 alternatively). exactly the behavior what i would expect while using INPUT instead of INPUT_PULLUP in pinMode()

While reading the chipkit code manual, it states that not all pins have an internal pullup resistor (depends on boards) and i might have had bad luck by selecting A8:

INPUT

    This sets the pin to be a normal floating input. The state of the input can be read using digitalRead(). An input in this mode with no connection or an open circuit will read an undefined value.

INPUT_PULLUP

    Like INPUT this sets the pin to be in an input mode. However the internal pullup resistor (when available; not all boards have pullup resistors available on all pins) will be enabled. A pin in this mode with no connection will, when read with digitalRead(), return a HIGH value.

http://chipkit.net/wiki/index.php?title=API:PinMode

 

my questions

  1. Do you think my diagnostic is correct ?
  2. What pins have an internal pull-up resistor on uc32 ?
  3. Where in the manual can i know if a pin has or does not have an internal pull-up resistor ? (https://reference.digilentinc.com/_media/reference/microprocessor/uc32/uc32_rm.pdf)

 

Thanks

 

fourchette

 

 

 

 

Link to comment
Share on other sites

7 answers to this question

Recommended Posts

Hi Blanca,

thanks for your feedback. However, i am pretty much entirely unable to read those diagrams. Here's a perfect opportunity to learn something ^_^

 

in the manual i see : A0-A5 are digital pins 14-19, and A6-A11 are 20-25. And in the schematics you offered, i found what i beleive is port 22/A8, and it seems there is a 200 ohms resistor labeled R26 in there.

Can you confirm please ?

 

 

 

2017_07_12_10_55_50_chipKIT_uC32.sch_chipkit_uc32_sch.png

Link to comment
Share on other sites

Hello,

If you look below in the pinout table you will see that according to the schematic, A8 is assigned to pin 22.

That line in the manual is not accurate and I will have it checked. Thanks for noticing and sorry for the mistake.

Best regards,

Bianca

Capture.JPG

Link to comment
Share on other sites

I am confused.. Is there a 200 ohm resistor on A8 or not ? In other words, can i use on uc32 A8 with INPUT_PULLUP as i am used to do on arduino to check physical buttons with a very simple wiring such as https://www.arduino.cc/en/Tutorial/InputPullupSerial instead of the much complicated https://www.arduino.cc/en/Tutorial/Button that requires more routing and aa additional resistor par button ???

I have been doing this trick INPUT_PULLUP for years on arduino with no problem. i have switched to uc32 to get more computing power but i do not understand the behavior of uc32 INPUT_PULLUP

i need your some confirmation here

Link to comment
Share on other sites

Hello,

I try to bring here some more details.

Let's try to investigate the possible implementations of pull-up.

The schematic that Bianca linked shows clearly that no hardware pull-up was implemented on UC32 for the specified pin. The R26 is there not for hardware pull-up, it has some protection purpose. 

Still, the Microchip microcontrollers provide some internal (weak) pull-up capabilities on input pins. Please read about this here:  http://ww1.microchip.com/downloads/en/DeviceDoc/PIC32MX_Datasheet_v3_61143C.pdf

So, finally there is the question if setting the PinMode as you wrote (INPUT_PULLUP) will make use of the internal pull-up pin capability. I really don't know, it is for you to find out. What I tried was to make things a little more clear.

Of course, you have the possibility to set the microcontroller registers outside the PinMode function.

Link to comment
Share on other sites

Thanks Christian for the details.

To be honest, 632 pages of documentation is a bit too much. I did try digging around pages 360 about input captures, but let's face it : it's completely obscure to me, i get one word out of 5 in there.

But using the dead simple trick with INPUT_PULLUP documented there => https://www.arduino.cc/en/Tutorial/InputPullupSerial
it works on arduino; no questions asked. but what i see on uc32 is different:

  • when i press the button => it works
  • when i unpress the button => it's a mess. i get erratic kinda random values. (bear in mind that i do software debounce so it really isn't a bouncing issue).

this is the behavior i would expect using the INPUT instead of INPUT_PULLUP. I now understand that there is no internal pullup resistor on A8 on uc32 thanks. (and neither on A5 or 28 that i randomly pickup instead)

=> what pins have the internal pullup resistor in can use with INPUT_PULLUP on uc32? where in the 632 pages of documentation can i find it?

An addiitional observation that i find revelant here. For me the customer promise of uc32 is dead simple : hardware compatibility with existing arduino uno shieds + more cpu cycles + addidional pins. And one of the first feature i try with uc32 (input_pullup) does not work as expected. I am disappointed and clearly worried that due to that limitation most of my arduino uno shields will not work on uc32. I am not giving up on the product yet but it's a bit tough

 

 

Link to comment
Share on other sites

Hello,

The conclusion is that you can find internal (very weak) pull-up for the Change Notification pins. These pins have "CNx" in their list of functions.

The "12.0 I/O PORTS" section of the microcontroller datasheet  http://ww1.microchip.com/downloads/en/DeviceDoc/PIC32MX_Datasheet_v3_61143C.pdf

explains you more about this.

So, my advice is to start from the pinout table of the UC32 reference manual https://reference.digilentinc.com/_media/chipkit_uc32:chipkit_uc32_rm.pdf and identify the pins that have CNx in their list of functions.

For example the highlighted line in the attached image tells that the pin situated in J5 position 06 has CN capability.

 

uc32_refman.png

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...