Hi, Guys,
I have been told I can enable the Pull up resistors on the Arduino Mega by using c-Code.
does any one have a example of this I could use.
Thanks
Tristan
Internal Pull resistors for Arduino
Moderator: Benj
-
- Posts: 13
- Joined: Wed Aug 29, 2012 8:49 pm
- Has thanked: 3 times
- Contact:
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Internal Pull resistors for Arduino
Hello Tristan,
Right to enable the pull up resistor on an input pin you simply write a 1 to the appropriate bit in the port register.
eg a pull up on pin A0
DDRA = 0x00; //Convert PortA to Input
PORTA = 0x01; //Enable pullup on A0, Disable pullup on A1-A7
var = PINA; //Read the data on Port A
You can use the Flowcode input icon to convert the pin to an input, the pins should default to input mode on startup.
Right to enable the pull up resistor on an input pin you simply write a 1 to the appropriate bit in the port register.
eg a pull up on pin A0
DDRA = 0x00; //Convert PortA to Input
PORTA = 0x01; //Enable pullup on A0, Disable pullup on A1-A7
var = PINA; //Read the data on Port A
You can use the Flowcode input icon to convert the pin to an input, the pins should default to input mode on startup.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Posts: 13
- Joined: Wed Aug 29, 2012 8:49 pm
- Has thanked: 3 times
- Contact:
-
- Posts: 1333
- Joined: Tue Oct 06, 2009 9:39 am
- Has thanked: 1135 times
- Been thanked: 299 times
- Contact:
Re: Internal Pull resistors for Arduino
Hi Ben!
Maybe a stupid question, is this also possible in FC without using C, and if, what happend if I pull the input down (on hardware) Will it then be active low ,inverted.
Best regard
Jorgen
Maybe a stupid question, is this also possible in FC without using C, and if, what happend if I pull the input down (on hardware) Will it then be active low ,inverted.
Best regard
Jorgen
- Enamul
- Posts: 1772
- Joined: Mon Mar 05, 2012 11:34 pm
- Location: Nottingham, UK
- Has thanked: 271 times
- Been thanked: 814 times
- Contact:
Re: Internal Pull resistors for Arduino
Hi Jorgen,
Ben has suggested pull-up option which requires adding code in C code..But just two lines of code will be enough for this. As soft pull-up enables weak pull up in the PIC input, so if you pull down by 10K resistor for example; I think the pin will be still pull-up...
Ben has suggested pull-up option which requires adding code in C code..But just two lines of code will be enough for this. As soft pull-up enables weak pull up in the PIC input, so if you pull down by 10K resistor for example; I think the pin will be still pull-up...
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Internal Pull resistors for Arduino
Hello,
It looks like the pull up resistors on AVRs are between 20 and 50K.
Therefore at 5V the input pin will see the following.
Worst Case - (5 / (20 + 10)) * 10 = 1.66V
Best Case - (5 / (50 + 10)) * 10 = 0.83V
The input low voltage is specified as between -0.5V and 0.3 * Vcc. at 5V this is 1.5V so 10K might be a bit too high. Maybe try 4.7K instead?
Worst Case - (5 / (20 + 4.7)) * 4.7 = 0.95V
Best Case - (5 / (50 + 4.7)) * 4.7 = 0.43V
It looks like the pull up resistors on AVRs are between 20 and 50K.
Therefore at 5V the input pin will see the following.
Worst Case - (5 / (20 + 10)) * 10 = 1.66V
Best Case - (5 / (50 + 10)) * 10 = 0.83V
The input low voltage is specified as between -0.5V and 0.3 * Vcc. at 5V this is 1.5V so 10K might be a bit too high. Maybe try 4.7K instead?
Worst Case - (5 / (20 + 4.7)) * 4.7 = 0.95V
Best Case - (5 / (50 + 4.7)) * 4.7 = 0.43V
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
- Enamul
- Posts: 1772
- Joined: Mon Mar 05, 2012 11:34 pm
- Location: Nottingham, UK
- Has thanked: 271 times
- Been thanked: 814 times
- Contact:
Re: Internal Pull resistors for Arduino
Hi Ben,
Do you know what is the internal pull-up resistor value for PIC ics? I didn't find that from datasheet..may be my eyes skipped that.
Edit:A strong pullup means using small value resistor for pull up whereas a weak pullup means using high value resistor for pulling the signal to Vcc.
I got it now..
There's no direct spec for the resistance value. You can, though, calculate the effective resistance from the "Ipu" parameter.
For example, in the 18F USB chips, the port B pullup current is listed at 50 to 400 microamps. (This is with a Vdd value of 5 volts and the input pin grounded.) The current range corresponds to a resistance range of 12.5 to 100 Kohms.
Some datasheets list a 'typical' value of 250 microamps which corresponds to a 20 Kohm resistance.
Do you know what is the internal pull-up resistor value for PIC ics? I didn't find that from datasheet..may be my eyes skipped that.
Edit:A strong pullup means using small value resistor for pull up whereas a weak pullup means using high value resistor for pulling the signal to Vcc.
I got it now..
There's no direct spec for the resistance value. You can, though, calculate the effective resistance from the "Ipu" parameter.
For example, in the 18F USB chips, the port B pullup current is listed at 50 to 400 microamps. (This is with a Vdd value of 5 volts and the input pin grounded.) The current range corresponds to a resistance range of 12.5 to 100 Kohms.
Some datasheets list a 'typical' value of 250 microamps which corresponds to a 20 Kohm resistance.
-
- Posts: 1333
- Joined: Tue Oct 06, 2009 9:39 am
- Has thanked: 1135 times
- Been thanked: 299 times
- Contact:
Re: Internal Pull resistors for Arduino
Hello both of you!
Again, many thanks for your help and explanation. I understand that although it is possible to make an input high internally, so it will still be high impedance.
I will continue as I have always done, either to mount a pull down or pullup resistor on the unused inputs or in the program define them as outputs.
I'm trying to learn as much as possible and is therefore very curious.
Thank´s
Best regard
Jorgen
Again, many thanks for your help and explanation. I understand that although it is possible to make an input high internally, so it will still be high impedance.
I will continue as I have always done, either to mount a pull down or pullup resistor on the unused inputs or in the program define them as outputs.
I'm trying to learn as much as possible and is therefore very curious.
Thank´s
Best regard
Jorgen