View previous topic :: View next topic |
Author |
Message |
johnl
Joined: 30 Sep 2003 Posts: 120
|
PIC16F1823 I/O configuration problem |
Posted: Wed Apr 11, 2012 9:11 am |
|
|
Trying to set up one digital input (on C4) and the first 7 analog inputs, but pin A0 comes up outputting 0 volts and sinking a few mA. Also pin A3 shows 2.5 volts (Vdd/2) even though the weak pull-up is enabled. (The PU on C4 works correctly.)
Version 4.121 compiler
Code: |
#include <16f1823.h>
#device ADC=10
#fuses NOMCLR,NOWDT,NOPUT,INTRC_IO,NOBROWNOUT,NOLVP,NOIESO, NODEBUG
#use delay (clock=8000000)
#use standard_io(A)
#byte OPTION_REG = 0x95
#byte WPUC = 0x20E
#byte WPUA = 0x20C
#byte DACCONzero = 0x118
#byte TXSTA = 0x19E
void main()
{
setup_oscillator(OSC_8MHZ) ;
OPTION_REG = 0b00000000;
WPUC = 0b00010000; //pullup on pin C4
WPUA = 0b00001000; //pullup on pin A3
setup_comparator(NC_NC_NC_NC);
set_tris_c(0b00010111);
set_tris_a(0b11111);
setup_vref(VREF_ON |VREF_ADC_4v096 ) ;
setup_adc( ADC_CLOCK_INTERNAL );
setup_dac(DAC_OFF);
DACCONzero = 0; // disconnect DAC output from pin A0 (DACOE=0)
TXSTA = 0; // disable transmit (TXEN=0)
setup_adc_ports( sAN0|sAN1|sAN2|sAN3|sAN4|sAN5|sAN6 |VSS_VDD );
} |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Apr 11, 2012 2:13 pm |
|
|
Two of those pins are used by the ICD programmer. Pin A0 is for ICSP
data, and pin A3 is the \MCLR pin. Do you have an ICD connected to
the board ?
How are you measuring these voltages ? With an oscilloscope ? Or a
voltmeter ? |
|
|
johnl
Joined: 30 Sep 2003 Posts: 120
|
|
Posted: Wed Apr 11, 2012 2:17 pm |
|
|
I disconnected the ICD2 from the PIC before checking.
I am measuring with a scope and the levels are pure DC. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19497
|
|
Posted: Wed Apr 11, 2012 2:40 pm |
|
|
Have you recompiled in 'non debug' mode?. Though you show this in the code posted, if you are using MPLAB for example, _it_ has to be told to compile into 'release' mode, or it will still select DEBUG mode by default.
Best Wishes |
|
|
johnl
Joined: 30 Sep 2003 Posts: 120
|
|
Posted: Wed Apr 11, 2012 3:36 pm |
|
|
The problem was a bad connection on the PCB on the resistor between the analog source and the input pin. Testing on the resistor leads, it looked like the pin was drawing current, but that was a bad probe connection because of oxidized leads. I shouldn't use old parts for prototyping.
The problem of low voltage on A3 was also my fault. I had wired a Vpp clamp circuit up on the board and it was dragging down the pull-up resistor with a lower resistance.
BTW, debug/release mode makes no difference.
Thanks much. |
|
|
|