Switching time of internal pullup/down resistors on MK20DX family

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Switching time of internal pullup/down resistors on MK20DX family

Jump to solution
1,417 Views
jfilleau
Contributor II

Background:

This question specifically refers to the MK20DX family of MCUs. Also called Kinetis K20 I believe? Let me know if my terminology is off.

The datasheet for this family can be found here:
K20P64M72SF1

Some pins on this device can be configured as GPIO inputs with an optional internal pullup or pulldown resistor. I'd like to toggle between the pullup and pulldown resistors during normal system operation, but I need to know how long it takes from writing to the port configuration register until the internal pull resistor has successfully toggled.

My use case:

My GPIO pin is connected to a feedback pin on a linear actuator that is either HIGH or LOW when the actuator is at either of its limits -- "fully actuated" and "fully disactuated" for lack of better terms.

When the actuator is between the fully actuated and fully disactuated states, the feedback pin on this actuator is in a High-Z state. For safety and reliability requirements, I need to know when this actuator is neither fully actuated nor fully disactuated.

To test for this High-Z state, I want to toggle the pull resistors on the GPIO input.

If the input is HIGH (fully actuated), then the GPIO will read HIGH for both pull resistor configurations.

If the input is LOW (fully disactuated), then the GPIO will read LOW for both pull resistor configurations.

If the input is High-Z (neither), then the GPIO will read LOW for the pulldown resistor configuration and HIGH for the pullup resistor configuration.

This is summarized in the following table:

InputGPIO Read when PullupGPIO Read when PulldownResult
HIGHHIGHHIGHConstant HIGH, therefore HIGH
LOWLOWLOWConstant LOW, therefore LOW
High-ZHIGHLOWNot Constant, therefore High-Z

After toggling the pull resistor, I need to know how long to wait until a change should occur, if a change will occur. This expected time can be calculated as:

t_detect = t_write + t_toggle + t_rc

where

t_detect is the total time from writing to the port configuration register until the change is detectable on the GPIO,

t_write is the time it takes to write to the port configuration register (this is known),

t_toggle is the time it takes for the present pull resistor to be turned off and the opposite pull resistor to be turned on (this is what I need to know), and

t_rc is the time it takes for the signal on the GPIO pin based on the RC constant of this circuit branch (this is calculable).

I'm writing some code to do this measurement, but I'd like to know if anyone has done this before.

Cheers,

John

1 Solution
1,286 Views
myke_predko
Senior Contributor III

Hey jfilleau@areai.com‌,

Just thinking about your comment about whether or not the DAC is available for this and you don't need it - a DAC is a terrible thing to waste on trivial functions.  

Here is what I would consider a better approach - using a second voltage divider to provide the check voltage to see when the actuator gets to it's destination position or is in the High Z state:

Actuator Input 2.jpg

This case uses two I/O pins of the Kinetis, one for the comparator negative input and one as an Open Driver.  The operation is similar to what I outlined above:

StateOpen Drain OuputComparator Negative VoltageComparator output
High to LowClosed/Grounded Output1/3Vdd"1" when Actuator is High or High Z, "0" when at Low
Low to HighOpen/Floating Output3/5Vdd"0" when Actuator is Low or High Z, "1" when High

Personally, I would consider this to be a somewhat more efficient approach although it uses two additional IO pins (I don't know if you're IO limited or not) - to change the measuring approach, you're just flipping a pin output.  

Fun stuff to play with.  

Good luck,

myke

View solution in original post

5 Replies
1,286 Views
myke_predko
Senior Contributor III

HI John,

Interesting problem and I would solve it a different way.  

Rather than use the pull up "resistors" in the Kinetis, could I suggest that you wire a voltage divider to the actuator input and then put it into one of the Kinetis' comparators:

Actuator Input_jpeg.jpg

This way if the Actuator is high or low, the nominal voltage divider output will be overdriven and if there is a High-Z condition, you get the nominal voltage output.  To keep things simple, I would use the same values for the resistor.  To detect the states:

StateVoltage ReferenceComparator Output
High to Low1V (assume 3.3V Vdd)"1" when Actuator is High or High Z, "0" when at Low
Low to High2V (assume 3.3V Vdd)"0" when Actuator is Low or High Z, "1" when High

As a bonus, you can generate an interrupt from the comparator to indicate when the output has reached the high or low state.  

Personally, I would be nervous about using the internal pull up functions in the Kinetis for this type of operation as they're not generally not resistors (I don't know for sure when it comes to Kinetis but for other parts I've worked with, they generally implement the pin pull up/pull down functions as low current sources/sinks).  

Good luck,

myke

1,286 Views
jfilleau
Contributor II

Mike, I love this idea. I have to see if the internal 6-bit DAC is available for my application (the MCU is supporting several peripherals). Your suggestion looks like the intended tool for the job instead of me trying to use a monkey wrench as a hammer in my original idea.

I'm still going to measure the switching time of the internal weak pulls (not resistors - thank you) and post that here when finished in case anyone needs it for a reason in the future.

Cheers.

0 Kudos
1,287 Views
myke_predko
Senior Contributor III

Hey jfilleau@areai.com‌,

Just thinking about your comment about whether or not the DAC is available for this and you don't need it - a DAC is a terrible thing to waste on trivial functions.  

Here is what I would consider a better approach - using a second voltage divider to provide the check voltage to see when the actuator gets to it's destination position or is in the High Z state:

Actuator Input 2.jpg

This case uses two I/O pins of the Kinetis, one for the comparator negative input and one as an Open Driver.  The operation is similar to what I outlined above:

StateOpen Drain OuputComparator Negative VoltageComparator output
High to LowClosed/Grounded Output1/3Vdd"1" when Actuator is High or High Z, "0" when at Low
Low to HighOpen/Floating Output3/5Vdd"0" when Actuator is Low or High Z, "1" when High

Personally, I would consider this to be a somewhat more efficient approach although it uses two additional IO pins (I don't know if you're IO limited or not) - to change the measuring approach, you're just flipping a pin output.  

Fun stuff to play with.  

Good luck,

myke

1,286 Views
jfilleau
Contributor II

You're a wizard. Where do I send your consultation fee?

The DAC's not presently being used, but I agree that it's too valuable to dedicate. I think I have enough pins. +1 for this.

1,286 Views
myke_predko
Senior Contributor III

Hi jfilleau@areai.com‌,

No consultation fee is necessary - just your firstborn male.  

Actually this was the solution to a problem I solved years ago in which I had to determine if a device was attached to the MCU.  I was still working with PICmicros in which the DAC was dedicated to the comparator so the original way of doing it in the post above was the most optimal - the PICmicros are definitely IO limited.  

As I said, it's fun to think through these issues.  

Good luck and let us know how you make out,

myke

0 Kudos