Weak pull-ups
Weak pull-ups
Am trying to implement weak pull-ups on 2 inputs of a 16F690 and am failing. Tried these as C Code block:-
option_reg.NOT_RABPU=0;
wpua.WPUA1=1;
wpua.WPUA2=1;
or
wpua.WPUA1=1;
wpua.WPUA2=1;
option_reg.NOT_RABPU=0;
or
option_reg.NOT_RABPU=0;
wpua=0x06;
The option_reg.NOT_RABPU=0; compiles correctly but all others give errors -somethnig wrong wth the C code it says. What am I doing wrong? Anything to do with some other lines on the A port being outputs instead of these 2 being inputs? I don’t switch any pin between in and out as it runs as they are always set to one or other. What is Flowcode doing behind the scenes e.g. in setting A/D inputs, although I use no Port A A/Ds. Anything to do with TRISA register?
I can enter it as ASM lines if it helps but no idea what the lines would be.
Rumour is that it defaults to pull up anyway so strictly I may not need the wpua.WPUA1=1 and wpua.WPUA2=1 lines.
option_reg.NOT_RABPU=0;
wpua.WPUA1=1;
wpua.WPUA2=1;
or
wpua.WPUA1=1;
wpua.WPUA2=1;
option_reg.NOT_RABPU=0;
or
option_reg.NOT_RABPU=0;
wpua=0x06;
The option_reg.NOT_RABPU=0; compiles correctly but all others give errors -somethnig wrong wth the C code it says. What am I doing wrong? Anything to do with some other lines on the A port being outputs instead of these 2 being inputs? I don’t switch any pin between in and out as it runs as they are always set to one or other. What is Flowcode doing behind the scenes e.g. in setting A/D inputs, although I use no Port A A/Ds. Anything to do with TRISA register?
I can enter it as ASM lines if it helps but no idea what the lines would be.
Rumour is that it defaults to pull up anyway so strictly I may not need the wpua.WPUA1=1 and wpua.WPUA2=1 lines.
Last edited by echase on Mon Nov 28, 2011 2:38 pm, edited 1 time in total.
-
- Matrix Staff
- Posts: 9520
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: Weak pull-ups
Hi echase,
Here is the easiest way to enable weak pullups on both port a and port b.
This is what I would use in a C code box:
Reason I would use binary is it's much easer to determine the correct value for the required port with out conversion .
E.g as you can see 00000101 = RA2 and RA0
Martin
Weak pull-ups are only available on the inputs and not o/p's. Or is that a typo?echase wrote:Am trying to implement weak pull-ups on 2 outputs of a 16F690
Here is the easiest way to enable weak pullups on both port a and port b.
This is what I would use in a C code box:
Code: Select all
clear_bit(option_reg , 7);// Enable weak pull-ups
wpua = 0b00000101; // WPU on RA2 and RA0
wpub = 0b10000000; // WPU on RB7
E.g as you can see 00000101 = RA2 and RA0
Martin
Martin
-
- Posts: 594
- Joined: Thu Sep 17, 2009 7:52 am
- Location: Belgium
- Has thanked: 63 times
- Been thanked: 102 times
- Contact:
Re: Weak pull-ups
I think the clear_bit function from v4 is clr_bit in v3.
If that doesn't work you can try this :
Nicolas
If that doesn't work you can try this :
Code: Select all
option_reg = option_reg & ~(1 << 7);
-
- Matrix Staff
- Posts: 9520
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: Weak pull-ups
I was correct with what I have posted above, except it will not compile because of bugs in 16F690.TDF and PIC16F690.h files.
I have updated them, so if you back up your current 16F690.TDF (located in \Matrix Multimedia\Flowcode V3\boostc\config) and PIC16F690.h ( located in \Matrix Multimedia\Flowcode V3\boostc\include) files, then replace with ones attached on this post, the WPU on both A and B should then then work.
If Flowcode is running then best to exit and restart after replacing the two files.
I have tested with:
It successfully compiled to hex with both of my FC3 and FC4
Note: None of the two files have not been approved by Matrix Multimedia
Martin
I have updated them, so if you back up your current 16F690.TDF (located in \Matrix Multimedia\Flowcode V3\boostc\config) and PIC16F690.h ( located in \Matrix Multimedia\Flowcode V3\boostc\include) files, then replace with ones attached on this post, the WPU on both A and B should then then work.
If Flowcode is running then best to exit and restart after replacing the two files.
I have tested with:
Code: Select all
clear_bit(option_reg , 7);// Enable weak pull-ups
wpua = 0b00000101; // WPU on RA2 and RA0
wpub = 0b10000000; // WPU on RB7
Note: None of the two files have not been approved by Matrix Multimedia
Martin
- Attachments
-
- Updated files.zip
- (6.07 KiB) Downloaded 350 times
Martin
Re: Weak pull-ups
Thanks, I meant inputs, edited original.
Will
option_reg.NOT_RABPU=0;
wpua.WPUA1=1;
wpua.WPUA2=1;
work with your revised 690 files?
You mentioned that your lines work on port A and B. Do I need to specifically include a command like wpub = 0b00000000; to turn them off on Port B as it might cause circuit problems with them all on.
Will
option_reg.NOT_RABPU=0;
wpua.WPUA1=1;
wpua.WPUA2=1;
work with your revised 690 files?
You mentioned that your lines work on port A and B. Do I need to specifically include a command like wpub = 0b00000000; to turn them off on Port B as it might cause circuit problems with them all on.
-
- Matrix Staff
- Posts: 9520
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: Weak pull-ups
Not sure, I would be able to test until later today.echase wrote:Will
option_reg.NOT_RABPU=0;
wpua.WPUA1=1;
wpua.WPUA2=1;
work with your revised 690 files?
I’m afraid when you enable weak pull-ups, the default is on. Since the function is enable all pull-upsechase wrote: You mentioned that your lines work on port A and B. Do I need to specifically include a command like wpub = 0b00000000; to turn them off on Port B as it might cause circuit problems with them all on
So if you want none of portb enabled then you can just do:
Code: Select all
wpub = 0b00000000;
Code: Select all
wpub = 0x0;
If pin is an o/p then weak pull-up on that pin will be disabled.
Martin
Martin
-
- Matrix Staff
- Posts: 9520
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: Weak pull-ups
Update:
Just tried:
With the two amended files.
Compiles OK and is working.
But you need to use 0 to turn WPU pins off. Otherwise wpua.WPUA1=1; will not change anything since its value is already 1 (all the WPU pins are set as 1 as stated in previous post)
Does not work without the files replaced.
Martin
Just tried:
Code: Select all
option_reg.NOT_RABPU=0;
wpua.WPUA1=1;
wpua.WPUA2=1;
Compiles OK and is working.
But you need to use 0 to turn WPU pins off. Otherwise wpua.WPUA1=1; will not change anything since its value is already 1 (all the WPU pins are set as 1 as stated in previous post)
Does not work without the files replaced.
Martin
Martin
-
- Matrix Staff
- Posts: 9520
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: Weak pull-ups
Your welcome.
Glad WPU is working for you.
Thanks for letting us know.
Martin
Glad WPU is working for you.
Thanks for letting us know.
Martin
Martin