Page 1 of 1

Weak pull-ups

Posted: Sat Nov 26, 2011 7:29 pm
by echase
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.

Re: Weak pull-ups

Posted: Sat Nov 26, 2011 8:05 pm
by medelec35
Hi echase,
echase wrote:Am trying to implement weak pull-ups on 2 outputs of a 16F690
Weak pull-ups are only available on the inputs and not o/p's. Or is that a typo?

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
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

Re: Weak pull-ups

Posted: Sat Nov 26, 2011 8:53 pm
by Spanish_dude
I think the clear_bit function from v4 is clr_bit in v3.

If that doesn't work you can try this :

Code: Select all

option_reg = option_reg & ~(1 << 7);
Nicolas

Re: Weak pull-ups

Posted: Sat Nov 26, 2011 9:04 pm
by medelec35
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:

Code: Select all

clear_bit(option_reg , 7);// Enable weak pull-ups
wpua = 0b00000101; //  WPU on RA2 and RA0
wpub = 0b10000000; //  WPU on RB7
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

Re: Weak pull-ups

Posted: Mon Nov 28, 2011 2:33 pm
by echase
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.

Re: Weak pull-ups

Posted: Mon Nov 28, 2011 3:46 pm
by medelec35
echase wrote:Will

option_reg.NOT_RABPU=0;
wpua.WPUA1=1;
wpua.WPUA2=1;

work with your revised 690 files?
Not sure, I would be able to test until later today.
echase 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
I’m afraid when you enable weak pull-ups, the default is on. Since the function is enable all pull-ups
So if you want none of portb enabled then you can just do:

Code: Select all

 wpub = 0b00000000; 
Or

Code: Select all

wpub = 0x0;
However the weak pull-up is only active if the pins are set to i/p.
If pin is an o/p then weak pull-up on that pin will be disabled.

Martin

Re: Weak pull-ups

Posted: Mon Nov 28, 2011 4:50 pm
by medelec35
Update:
Just tried:

Code: Select all

option_reg.NOT_RABPU=0;
wpua.WPUA1=1;
wpua.WPUA2=1;
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

Re: Weak pull-ups

Posted: Mon Nov 28, 2011 11:25 pm
by echase
Seems to work, thanks.

Re: Weak pull-ups

Posted: Tue Nov 29, 2011 12:20 am
by medelec35
Your welcome.

Glad WPU is working for you.

Thanks for letting us know.

Martin