View previous topic :: View next topic |
Author |
Message |
Ömer Faruk
Joined: 15 Nov 2018 Posts: 42 Location: Çanakkale
|
Weak pullups problem in 18f46k80 |
Posted: Mon Dec 17, 2018 4:32 am |
|
|
Hello dear friends. I am having a problem about setting weak pullups on port b. Although I set the right code only two pins have weak pullups, pin_b0 and pin_b5. What is the possible problem ? İ need your help.
Code: |
port_b_pullups(pin_b0);
port_b_pullups(pin_b1);
port_b_pullups(pin_b3);
port_b_pullups(pin_b4);
port_b_pullups(pin_b5);
port_b_pullups(pin_b6);
port_b_pullups(pin_b7);
set_tris_b(0xFF);
|
here the related parts of my code. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9226 Location: Greensville,Ontario
|
|
Posted: Mon Dec 17, 2018 6:05 am |
|
|
I don't use that PIC but in general...
some possible things that can be the cause
1) defective PIC
2) bad PCB layout
3) bridged traces
4) compiler error
5) wrong header file
6) not disabling peripherals attacehed to pins
7) incorrect startup duw to marginal PSU
8) loading on pin due to external devices
9) if PIC has PPS, that needs to be looked at very carefully
re: #6. some PICs for some compiler versions default to analog and comaparator peripherals, so you need to disable to use as I/O pins
I'm sure there are other reasons... |
|
|
empty
Joined: 13 Jan 2018 Posts: 15
|
|
Posted: Mon Dec 17, 2018 6:29 am |
|
|
Doing port_b_pullups(pin_b7); has no meaning!
As written in the device header file 18F46K80.h:
port_b_pullups(int8 upmask);
Replacing 'upmask' by 'pin_b7' is the same as doing this:
port_b_pullups(31759);
upmask can vary from 0x00 to 0xFF which decides which pin pull-up is enabled or not, for example enable only RB1 weak pull-up:
port_b_pullups(0x02);
so enabling all PORTB pin pull-ups should be;
port_b_pullups(0xFF);
It's the same as writing to WPUB (WEAK PULL-UP PORTB ENABLE REGISTER) or PORTB. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19515
|
|
Posted: Mon Dec 17, 2018 6:47 am |
|
|
and to do 'B7', would need:
port_b_pullups(0b10000000);
//Just turn on B7 pullup |
|
|
Ömer Faruk
Joined: 15 Nov 2018 Posts: 42 Location: Çanakkale
|
|
Posted: Mon Dec 17, 2018 10:11 am |
|
|
empty wrote: | Doing port_b_pullups(pin_b7); has no meaning!
As written in the device header file 18F46K80.h:
port_b_pullups(int8 upmask);
Replacing 'upmask' by 'pin_b7' is the same as doing this:
port_b_pullups(31759);
upmask can vary from 0x00 to 0xFF which decides which pin pull-up is enabled or not, for example enable only RB1 weak pull-up:
port_b_pullups(0x02);
so enabling all PORTB pin pull-ups should be;
port_b_pullups(0xFF);
It's the same as writing to WPUB (WEAK PULL-UP PORTB ENABLE REGISTER) or PORTB. |
İ find out what is wrong, thank you very much . But why the compiler doesn't give an error when i write int16 instead of int8 ? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19515
|
|
Posted: Mon Dec 17, 2018 12:56 pm |
|
|
Of course not.
In C, the language will always automatically cast types.
If you use an incorrect type, the language automatically converts. This is
a very powerful feature of the language, but requires _you_ to verify
that what you are passing is what is expected.... |
|
|
|