View previous topic :: View next topic |
Author |
Message |
darkrush
Joined: 29 Sep 2011 Posts: 18 Location: Colombia
|
PIC16F1934 Port problem |
Posted: Mon Apr 16, 2012 9:06 am |
|
|
Hi everyone, I'm using a PIC16F1934 with CCS 4.120.
I have a program that reads some inputs and depending on it sends something via RS232.
The issue is that it seems that it always reads pins as 0, I have tested the hardware and even if the input is 1 (4.89v) it reads it as 0, I have tried some port configurations with no luck.
However only RB6,RB7, RC1 and RA7 works.
I used standard_io and fixed_io with the same result.
Here is a little test code:
Code: |
#include <16F1934.h>
#device adc = 10
#FUSES NOWDT //No Watch Dog Timer
#FUSES INTRC_IO //Ineternal oscillator IO available
#FUSES PROTECT //Code protected from reading
#FUSES NOPUT //Power Up Timer
#FUSES NOCPD //No EE protection
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOLVP //Low Voltage Programming on B3(PIC16) or B5(PIC18)
#FUSES NOWRT //Program memory not write protected
#FUSES NOMCLR
#use delay(clock=8000000)
#use rs232(uart1,baud=9600) //xmit=PIN_C6,rcv=PIN_C7
#use fast_io(A)
#use fast_io(B)
#use fast_io(C)
#use fast_io(D)
#use fast_io(E)
#define C11 PIN_D4
#define C12 PIN_D6
#define C13 PIN_B0
#define C14 PIN_B2
#define C21 PIN_B4
#define C22 PIN_B5
#define C23 PIN_B6
#define C24 PIN_B7
#define EN485 PIN_C5
#byte OSCCON = getenv("SFR:OSCCON")
void main(void){
int i;
//setup_oscillator(OSC_PLL_OFF);
OSCCON = 0x73;//01110011 - 0x73
/*
Port 76543210
A 11111111
B 11111111
C 10011111
D 11111111
E 11111111
*/
set_tris_a(0xFF);
set_tris_b(0xFF);
set_tris_c(0x9F);
set_tris_d(0xFF);
set_tris_e(0xFF);
output_high(EN485);
delay_ms(50);
while(1){
for(i=0;i<24;i++)
{
switch(i)
{
case 0:
if(!input(C11))
printf("$00;");
delay_ms(500);
break;
case 1:
if(!input(C12))
printf("$01;");
delay_ms(500);
break;
case 2:
if(!input(C13))
printf("$02;");
delay_ms(500);
break;
case 3:
if(!input(C14))
printf("$03;");
delay_ms(500);
break;
case 4:
if(!input(C21))
printf("$04;");
delay_ms(500);
break;
case 5:
if(!input(C22))
printf("$05;");
delay_ms(500);
break;
case 6:
if(!input(C23))
printf("$06;");
delay_ms(500);
break;
case 7:
if(!input(C24))
printf("$07;");
delay_ms(500);
break;
}
delay_ms(500);
}
}
}
|
Hope you can help.
Xavier |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Apr 16, 2012 10:35 am |
|
|
Quote: | However only RB6,RB7, RC1 and RA7 works.
|
Post a list of the pins that don't work as inputs. |
|
|
darkrush
Joined: 29 Sep 2011 Posts: 18 Location: Colombia
|
|
Posted: Mon Apr 16, 2012 11:00 am |
|
|
Hi PCM programmer, I'm using a total of 24 inputs (including those that works), these don't work:
RA0
RA1
RA2
RA3
RA5
RA6
RB0
RB1
RB2
RB3
RB4
RB5
RC0
RD4
RD5
RD6
RD7
RE0
RE1
RE2
As I said before, only RB6, RB7, RC1 and RA7 works.
Xavier |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Mon Apr 16, 2012 11:41 am |
|
|
add ERRORS to your RS232 declaration
you could use a default in the switch statement , as you do not have 24 choices , do you? or perhaps a smaller loop count ??
say perhaps
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Apr 16, 2012 12:34 pm |
|
|
I can't work on this until later in the afternoon. I have to do some work
for the company right now. But the typical case why you can't read
inputs at a high level is:
1. They are programmed as analog inputs.
2. They are programmed for some other function (such as LCD pins).
3. They are floating inputs. There is no pull-up or other high level signal.
4. The input voltage is not above the required Vih voltage threshold.
5. Some external circuit is holding the pins at a low level.
Some of these could be caused by compiler bugs. I'll check that later.
What board are you using ? If bought the board, then post the
manufacturer and part number of the board. If you added external
circuits on those pins, then describe the circuits. |
|
|
darkrush
Joined: 29 Sep 2011 Posts: 18 Location: Colombia
|
|
Posted: Mon Apr 16, 2012 1:55 pm |
|
|
@asmboy I cut the code and forgot to change the loop count, is just a test code.
@PCM Programmer
as you suggested I added these lines:
Code: |
setup_comparator(NC_NC_NC_NC);
setup_vref(VREF_OFF);
setup_dac(DAC_OFF);
setup_lcd(LCD_DISABLED);
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF);
|
Most of the pins work now, I don't know which ones don't work (around 5), I'm checking the hardware now and post back the pins.
Is there any other line to add?
thank you for your help
Xavier |
|
|
darkrush
Joined: 29 Sep 2011 Posts: 18 Location: Colombia
|
|
Posted: Mon Apr 16, 2012 3:39 pm |
|
|
Hi again,
I double (triple) checked the hardware, a board I designed (I tested 4 boards), and tested every pin directly in the PIC to avoid external circuitry.
Also:
-I used the same signal with every pin.
-I checked for floating inputs.
Only RB3, RC0 and RA6 don't work.
any idea why those pin are not working?
I'm going to do more test, and also recheck those pins on hardware.
thank you again for your help.
Xavier |
|
|
jeremiah
Joined: 20 Jul 2010 Posts: 1354
|
|
Posted: Mon Apr 16, 2012 4:12 pm |
|
|
A couple of the FUSES affect RA6. I would take a look at those and make sure you are setting those in ways you want. RC0 and RB3 both have PWM outs, which are different than just the CCP pins. RC0 also provides the external T1 input. Make sure all of that is configured how you want. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Apr 16, 2012 5:28 pm |
|
|
Add this routine and call it at the start of main():
Code: |
void make_all_pins_digital(void)
{
#byte ANSELA = getenv("SFR:ANSELA")
#byte ANSELB = getenv("SFR:ANSELB")
#byte ANSELD = getenv("SFR:ANSELD")
#byte ANSELE = getenv("SFR:ANSELE")
ANSELA = 0;
ANSELB = 0;
ANSELD = 0;
ANSELE = 0;
}
//============================
void main()
{
make_all_pins_digital();
.
.
.
}
|
|
|
|
darkrush
Joined: 29 Sep 2011 Posts: 18 Location: Colombia
|
|
Posted: Tue Apr 17, 2012 10:14 am |
|
|
I did a couple of tests with no luck
I removed the lines I added before:
Code: |
setup_comparator(NC_NC_NC_NC);
setup_vref(VREF_OFF);
setup_dac(DAC_OFF);
setup_lcd(LCD_DISABLED);
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF);
|
and added
Code: |
make_all_pins_digital();
|
The result was the same, RA6, RB3 and RC0 don't work.
I also combined the above for the same result.
By the suggestion of jeremiah I added:
Code: |
#FUSES NOCLKOUT
setup_wdt(WDT_OFF);
setup_timer_1(T1_DISABLED|T1_DIV_BY_1);
setup_timer_2(T2_DISABLED,0,1);
setup_timer_4(T4_DISABLED|T4_DIV_BY_1,0,1);
setup_timer_6(T6_DISABLED|T6_DIV_BY_1,0,1);
setup_ccp1(CCP_OFF);
setup_ccp2(CCP_OFF);
setup_ccp3(CCP_OFF);
setup_ccp4(CCP_OFF);
WPUB = 0; //no pull-ups
|
Still the same result, with all the combinations possible.
I checked the hardware again (3 boards) and they are correctly wired.
@jeremiah what other FUSES affect RA6 to work as I/O input that I missed?
thank you so much for your help
Xavier |
|
|
jeremiah
Joined: 20 Jul 2010 Posts: 1354
|
|
Posted: Tue Apr 17, 2012 10:53 am |
|
|
I don't know what CCS fuse corresponds to this, but on page 64 of the data sheet, configuration word 2 has a VCAP setting that affects RA6
Also, something of interest, at least two of the pins, A6 and C0 are right next to each other in some packages for that PIC. I would double check to make sure there isn't a soldering issue with those (maybe a bridging or something). |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Tue Apr 17, 2012 10:58 am |
|
|
Pin C0 and B3 are both affected by the state of the APFCON register 0x11D.
By DEFAULT these should NOT be a problem - but since C0 and B3 are configured for non DIO ops by this register it might be worth trying to trace it out in the LST file.
Ditto LCDCON which can affect A6. |
|
|
darkrush
Joined: 29 Sep 2011 Posts: 18 Location: Colombia
|
|
Posted: Wed Apr 18, 2012 10:13 am |
|
|
I found the mistake!
Thank you jeremiah for pointing out about the package, I have a TQFP package and I was looking at the QFN version pinout (miraculously it worked), so those 3 pins are NC pins in the TQFP package.
Thank you everyone for your help, all pins now work perfectly and also I learned a lot
Xavier |
|
|
|