View previous topic :: View next topic |
Author |
Message |
cbarberis
Joined: 01 Oct 2003 Posts: 172 Location: Punta Gorda, Florida USA
|
Input that does not want to work as an input???? |
Posted: Sat Mar 01, 2014 3:56 pm |
|
|
Hi all,
I am working with a device that I never used before (PIC24F08KL401) but it seemed to be a good fit for my specific application. I have already run into a few mysteries with this part
First the AN4 analog input would never work, but the data sheet surely indicates it should (for the SOIC 20 pin device) I have already talked to the Microchip FAE's and they are also
looking into that and I found a way around that issue. But that particular issue is not why I am posting this "HELP ME I AM LOST" I am perplexed by the fact that I am declaring a pin (RA4) as
an input and trying to look at the logic level going into the pin. Basically this pin sees a 10K pulled up to Vdd (3.3V) which is tied to an open drain on a Max1551 (battery charge device)
so when the MAX1551 is charging this point is low from the active open drain and when the device is not charging it is obviously high. So basically we can say we have a 10K resistor tied to
Vdd and going to the input of RA4 on the PIC. If we look at this point it is always high (we will exclude the action of the MAX1551)
What I am seeing is that the PIC is always reading a"0" or low input at this point, even though this pin is at Vdd. The first thing that comes to mind is the proper set-up of the I/O pin
and as far as I can tell, the TRISA register is correct and the ANSA register is also set-up correctly. However, when ever my debugger stops at the selected breakpoint I can read the PORTA
as 0x0000 where I should be seeing a 0x0004. I have tried replacing the device but that is not the problem and it appears that I am overlooking something, it seems to me that this pin is being affected by another internal
peripheral module that may be causing this conflict. According to the data sheet this pin has the following functions associated: PEGC3, SCLKI, CN0 and RA4
I am sure this is probably something absurd that I cannot see, but I have included the parts of my code that would be functional with this pin test that I am doing below
ANY SUGESTIONS WOULD BE GREATLY APPRECIATED
Code: |
/***************** Main Header file *********************/
#include <24F08KL401.h>
#device ADC=10
#FUSES NOWDT, NOBROWNOUT, NOPUT, OSCIO, DEBUG ///SOSC_DIGITAL
#device ICD = TRUE
#use delay(internal=8000000)
#USE PWM(OUTPUT=PIN_A6, TIMER=2, FREQUENCY=31250, BITS=7)
#define SHOCKPULSE PIN_B8
#define RED_LED PIN_B12
#define GRN_LED PIN_B13
#define BATCHRG !input(pin_A4) ///the pin we are using for input sense
#define LOWBATLVL 577
#define MTRVIBRT PIN_B9
#define PULSE PIN_A2
#define FSENSE 0
#define MODEIN 1
#define BATLEVL 9 //4
#define BTEST PIN_A3
#define BTESTINTERVAL 36000 /// ~1 min
#define FIVESECINTERVAL 3000 // ~ 5 sec
|
Code: |
/****************** Main source file ***********************/
#include <DWexp2.h>
void Init(void){
set_tris_a(0x0053); // 0x0017
set_tris_b(0x8087); //to include AN9
//#ifdef debug
setup_wdt(WDT_OFF);
// #endif
// #ifdef Normal_Run
//setup_wdt(WDT_ON);
//#endif
SETUP_SPI(SPI_DISABLED);
output_high(GRN_LED);
output_high(RED_LED);
output_low(BTEST);
output_low(MTRVIBRT);
output_low(SHOCKPULSE);
output_low(PULSE);
setup_adc_ports(sAN0 |sAN1 |sAN9 | VSS_VDD);
setup_adc(ADC_CLOCK_DIV_4 | ADC_TAD_MUL_4);
setup_timer1(T1_INTERNAL |T1_DIV_BY_256,0xF519); //divide by 256 and then count up to 62745 ~ 4 second interrupt
set_pwm1_duty(64); // sets pwm for voltage doubler
}
void main()
{
Init();
/////// this is my simple test on the RA4 pin
while(1){
if(BATCHRG)
{ output_low(RED_LED); //////Selected breakpoint always stops here,when using a debugger meaning BATCHRG = 0 (always zero)
delay_ms(1000);}
else
output_high(RED_LED); }
} |
|
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9178 Location: Greensville,Ontario
|
|
Posted: Sat Mar 01, 2014 4:06 pm |
|
|
first thing I'd do is pull the PIC and MAX chip and confirm with a meter that the pin is 'active' and not grounded.
I know you need nerves of steel and a big magnifying glass but basic troubleshooting 101 says to check the PCB for shorts,bad etches, etc.
Maybe that pin is really not connected ?
hth
jay |
|
![](templates/subSilver/images/spacer.gif) |
cbarberis
Joined: 01 Oct 2003 Posts: 172 Location: Punta Gorda, Florida USA
|
|
Posted: Sat Mar 01, 2014 4:25 pm |
|
|
Thank you temtronic,
But I have already done that, ohm it out and replaced the PIC with the same results. If you put a scope onto pin RA4 it is working correctly it is toggled high and low by the other device, what I am saying is that even if this pin is electrically high the PIC is always reading a low. So I have confirmed that this pin is set up as an input and it is not dragging the signal low. |
|
![](templates/subSilver/images/spacer.gif) |
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Sat Mar 01, 2014 9:09 pm |
|
|
how about with
#USE fastio
and the appropriate set_tris
??? |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
![](templates/subSilver/images/spacer.gif) |
cbarberis
Joined: 01 Oct 2003 Posts: 172 Location: Punta Gorda, Florida USA
|
|
Posted: Sun Mar 02, 2014 8:47 am |
|
|
Thank you for your suggestions, specifically the one commented by PCMprogrammer regarding the SOSC_DIGITAL being commented out, for sure I thought that was the case, but it appears that even with that fuse statement I still have a problem. I now see that pin RA4 is always high when using the fuse statement SOSC_DIGITAL (before it was low) when reading the portA register no matter what that input is doing.
I have noticed that the RA4 pin also shares a function with CN0 and there is an interesting note on the data sheet and I'm not sure if this is the cause to my problem:
**************************************************
On any pin, only the pull-up resistor or the pull-down
resistor should be enabled, but not both of them. If the
push button or the keypad is connected to VDD, enable
the pull-down, or if they are connected to VSS, enable
the pull-up resistors. The pull-ups are enabled separately
using the CNPU1 and CNPU2 registers, which
contain the control bits for each of the CN pins.
Setting any of the control bits enables the weak
pull-ups for the corresponding pins. The pull-downs are
enabled separately, using the CNPD1 and CNPD2
registers, which contain the control bits for each of the
CN pins. Setting any of the control bits enables the
weak pull-downs for the corresponding pins.
When the internal pull-up is selected, the pin uses VDD
as the pull-up source voltage. When the internal
pull-down is selected, the pins are pulled down to VSS
by an internal resistor. Make sure that there is no external
pull-up source/pull-down sink when the internal
pull-ups/pull-downs are enabled
*************************************************** |
|
![](templates/subSilver/images/spacer.gif) |
cbarberis
Joined: 01 Oct 2003 Posts: 172 Location: Punta Gorda, Florida USA
|
|
Posted: Sun Mar 02, 2014 11:04 am |
|
|
I think I found the nasty problem and I have sent this note to my local FAE from Microchip.
I am really struggling with this PIC24F08KL401 I am using the SOIC 20 pin package and it appears that the problem is related to errors on the latest data sheet. The first problem I had was that I could not get AN4 to work as a analog input to CH4 of the ADC, then no matter what I did I also could NOT get RA4 digital input to work correctly and I think I found the reason to this when I went to try on a development board the same part in the 20 pin PDIP (according to the data sheet they share the same pins on the 20 pin device) it turns out all my problems go away when I use the pin out for the PDIP package but things do not work if we wire it up according to the pin diagram to the SOIC 20 pin package shown on page 4 of the latest data sheet.
The problem is: I have AN4 wired to pin#10 and RA4 wired to pin#6
It turns out that in the plastic dip and also on the SOIC 20 device, AN4 is pin#6 and RA4 is pin#10
I have now re-wired the SOIC 20 device as indicated above and it now appears to work normally. I have also read the ERRATA sheet and I think it left me more confused as it does not clearly explain the same. |
|
![](templates/subSilver/images/spacer.gif) |
gpsmikey
Joined: 16 Nov 2010 Posts: 588 Location: Kirkland, WA
|
|
Posted: Sun Mar 02, 2014 1:56 pm |
|
|
Now that is handy !! I hate it when it turns out you were following the directions and the directions were wrong !!
mikey _________________ mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3 |
|
![](templates/subSilver/images/spacer.gif) |
|