View previous topic :: View next topic |
Author |
Message |
just280
Joined: 17 Apr 2012 Posts: 3 Location: UK
|
PIC18F24K42 PIN RA7 not functioning as an input |
Posted: Wed Dec 08, 2021 4:41 am |
|
|
I'm porting some known functioning code across from a PIC18F2420 to a PIC18F24K42 because of the chip shortage currently going on. The devices should be pin for pin compatible and apart from a few differences in setting the device up there shouldn't be any real issues. For the life of me though I cannot get pin RA7 to function as an input. I have tried three different boards to rule out any assembly issues and scoped the pin to check voltage levels. All I have on the pin is a button, 5v to gnd voltage shift and I poll the input every 100mS. I have other buttons on other pins including RA6 which work fine.
Am I missing something in the fuses?
Code: |
#include <18F24K42.h>
#device adc=10
#FUSES WDT //No Watch Dog Timer
#FUSES WDT256 //Watch Dog Timer uses 1:256 Postscale
#FUSES RSTOSC_HFINTRC_64MHZ //Internal RC Osc, no CLKOUT
#FUSES NOFCMEN //Fail-safe clock monitor enabled
#FUSES NOEXTOSC
#FUSES NOCLKOUT
#FUSES NOZCDDIS
#FUSES NODEBUG
#FUSES NOPRLOCK1WAY
#FUSES PUT_16MS //Power-Up Timer set to 16ms
#FUSES BROWNOUT //Reset when brownout detected
#FUSES BORV27 //Brownout reset at 2.7V
#FUSES NOMCLR //Master Clear pin used for I/O
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES CKS
#FUSES NOPPS1WAY
#FUSES NOSTVREN
#FUSES BBSIZ512
#use delay(internal=8000000,RESTART_WDT)
#use I2C(master,sda=PIN_C4,scl=PIN_C3,force_sw)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,errors,stop=1) |
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9246 Location: Greensville,Ontario
|
|
Posted: Wed Dec 08, 2021 6:35 am |
|
|
While I don't use that PIC , I did download the datasheet.
Possible reasons are not disabling analog on that pin, or any other peripheral function.
That PIC has 'PPS', so maybe the default use/direction is wrong ?
Fuses alone don't control the entire PIC, you should post your test program. Someone who uses that PIC can probably see what is wrong.
Jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Wed Dec 08, 2021 7:49 am |
|
|
What compiler version?.
Will then check with your fuses and see what is actually being set by them.
Could be a fuse error.
Also as Jay says, triple check all your pin_select statements, and the
analog setup. |
|
|
just280
Joined: 17 Apr 2012 Posts: 3 Location: UK
|
|
Posted: Wed Dec 08, 2021 7:57 am |
|
|
Thanks for the reply Jay.
I had analogs disabled but will look into PPS.
Some more of my code below if it helps, it's a cut down version but it gives you an idea of what I'm doing. I have the buttons connected in a 3x4 matrix and normally call 'scan_keys' every 100mS.
Code: |
int8 scan_keys()
{
int8 scan_value;
scan_value=100;
output_high(pin_a5);
output_low(pin_a2);
output_low(pin_a3);
output_low(pin_a4);
if(input(pin_e3)) scan_value=7;
if(input(pin_a6)) scan_value=8;
if(input(pin_a7)) scan_value=9;
output_low(pin_a5);
output_high(pin_a2);
output_low(pin_a3);
output_low(pin_a4);
if(input(pin_e3)) scan_value=4;
if(input(pin_a6)) scan_value=5;
if(input(pin_a7)) scan_value=6;
output_low(pin_a5);
output_low(pin_a2);
output_high(pin_a3);
output_low(pin_a4);
if(input(pin_e3)) scan_value=1;
if(input(pin_a6)) scan_value=2;
if(input(pin_a7)) scan_value=3;
output_low(pin_a5);
output_low(pin_a2);
output_low(pin_a3);
output_high(pin_a4);
if(input(pin_e3)) scan_value=10;
if(input(pin_a6)) scan_value=0;
if(input(pin_a7)) scan_value=11;
if(input(pin_e3) && input(pin_a7)) scan_value=12;
if(input(pin_a6) && input(pin_a7)) scan_value=13;
return scan_value;
}
void main()
{
setup_adc_ports(ADC_OFF);
setup_spi(SPI_DISABLED);
setup_wdt(WDT_ON);
setup_timer_0(T0_OFF);
//setup_timer_0(RTCC_INTERNAL|RTCC_DIV_8|RTCC_8_BIT); //1.0 ms overflow
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DIV_BY_32 | T2_CLK_INTERNAL,63,1); //1.0 ms overflow, 1.0 ms interrupt
setup_ccp1(CCP_OFF);
setup_comparator(NC_NC_NC_NC);
enable_interrupts(INT_TIMER2);
//enable_interrupts(INT_TIMER0);
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);
while(TRUE)
{
restart_wdt();
key_value=scan_keys();
} |
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9246 Location: Greensville,Ontario
|
|
Posted: Wed Dec 08, 2021 8:06 am |
|
|
well I see 3 things potentially wrong...
1) interrupt for timer2 enabled, no handler
2) interrupt for SIO enabled, no handler
3) wdt emabled, not needed |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Wed Dec 08, 2021 8:17 am |
|
|
Glaring problem.
You are mixing defined values between commands.
The ADC_OFF define, is for setup_adc, not setup_adc_ports.
The value the disable the input multiplexor for the ADC, is NO_ANALOGS.
Feeding ADC_OFF into the setup_adc_ports command, will actually enable
the ADC on the top bit.....
You don't actually need to disable the ADC, it is off by default.
setup_adc_ports(NO_ANALOGS);
Is the command to set all the pins to digital.
It is a classic huge 'caveat', to ensure that only the defines listed actually
'for' a specific command are used with that command..... |
|
|
just280
Joined: 17 Apr 2012 Posts: 3 Location: UK
|
|
Posted: Wed Dec 08, 2021 9:22 am |
|
|
Ttelmah you are spot on thank you!
I just remarked out the setup_adc_ports(ADC_OFF) and all is working. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Wed Dec 08, 2021 10:37 am |
|
|
Progress.
Glad you have it working. |
|
|
|