|
|
View previous topic :: View next topic |
Author |
Message |
pe1icq
Joined: 29 Aug 2005 Posts: 12
|
Problem activating pull-ups on 16F636 |
Posted: Sun Jun 01, 2008 7:03 am |
|
|
Hi,
I have a problem activating pull-ups on a 16F636.
For testing I have used the Microchip low-pin count board that comes with the PICkit2 Starter Kit and a PIC16F636. The compiler and version is PCW 4.060.
Code: |
#include <16F636.h>
#FUSES NOWDT //Watch Dog Timer
#FUSES INTRC
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOCPD //No EE protection
#FUSES NOMCLR //Master Clear pin used for I/O
#FUSES NOIESO //Internal External Switch Over mode disabled
#FUSES PUT //Power Up Timer
#FUSES NOFCMEN //Fail-safe clock monitor disabled
#FUSES NOWURE //Wake-up and continue
#FUSES NOBROWNOUT //No brownout reset
#use delay (clock=4,000,000)
void main()
{
int8 i;
setup_wdt(WDT_OFF);
setup_comparator(NC_NC_NC_NC);
set_tris_a( 0b00001111 ); //RA0, RA1, RA2, RA3 inputs
set_tris_c( 0b00000000 ); //all output
while (TRUE)
{
port_a_pullups (255);
i=input(PIN_A1);
output_c (i); // There are 4 LEDS on RC0 ... RC3
}
}
|
I have tried with and without #use fast_io(a) and also tried port_a_pullups (255,0).
But none of these worked.
The PIC reads PIN_A1 correctly when I hardwire it to +5V, but when the input floats it reads a 0. With the weak pull-up enabled it should read a 1.
What am I doing wrong?
TIA.
//Arno |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Sun Jun 01, 2008 9:13 am |
|
|
The compiler should have given an error message because your call to setup_port_a is incorrect for your chip. The PIC16F636 has both pull-up and pull-down resistors configurable on each pin and according to the manual you have to specify a bitmask for both: Quote: | port_a_pullups (value)
...
port_x_pullups (upmask, downmask)
Parameters:
value is TRUE or FALSE on most parts, some parts that allow pullups to be specified on individual pins permit an 8 bit int here, one bit for each port pin.
upmask for ports that permit pullups to be specified on a pin basis. This mask indicates what pins should have pullups activated. A 1 indicates the pullups is on.
downmask for ports that permit pulldowns to be specified on a pin basis. This mask indicates what pins should have pulldowns activated. A 1 indicates the pulldowns is on. |
I compiled the code with port_a_pullups(255,0) and this looks OK. |
|
|
pe1icq
Joined: 29 Aug 2005 Posts: 12
|
|
Posted: Sun Jun 01, 2008 9:30 am |
|
|
Thanks for trying.
My compiler does not give a warning nor an error message.
I actually had port_x_pullups (upmask, downmask) in my first attempt, and tried other formats when that didn't work.
These are the sections of the asm listings that PCW 4.060 produce.
Code: | .................... port_a_pullups (255);
0035: MOVLW FF
0036: MOVWF 15
0037: BCF 01.7
0038: CLRF 17 |
Code: | .................... port_a_pullups (255,0);
0035: MOVLW FF
0036: MOVWF 15
0037: BCF 01.7
0038: MOVWF 17 |
Both give the same code.
Values seem to be written to 15h, but a few lines before this some bank switching has been done already (0031: BSF 03.5).
Can you send me your compiler's asm listing?
Thanks
//Arno |
|
|
pe1icq
Joined: 29 Aug 2005 Posts: 12
|
|
Posted: Sun Jun 01, 2008 10:33 am |
|
|
I found the problem. And of course it was my own stupid mistake.
I thought that RA1 was floating on the PICkit2 demo board, but since I was powering the circuit via the PICkit2, the ICSPCLK line was still connected. Apparently the PICkit2 keeps that line loaded to ground. At least enough for the target PIC to see a constant low input.
What I actually tried to do, is determine three states one 2 input lines. (high, low, open). This way I can use 2 lines as an input selector with 9 possible combinations. The open state is detected by alternating using the weak pull-ups and pull-downs, and check if the inputs change.
In short, do 2 reads, exor them, and add the result to the first read.
//Arno |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|