View previous topic :: View next topic |
Author |
Message |
davidb_csi
Joined: 16 Jul 2014 Posts: 7
|
PIC18F14K22 RA0-RA3 not working |
Posted: Wed Jul 23, 2014 11:24 am |
|
|
I have all inputs of port A as digital inputs from switches. RA0 is a Ramp Up switch, RA1 is Ramp Down. RA2 and 3 are jumpers for calibration, RA4 and RA5 are from a rotary switch which selects a milliamp output range.
RA4 and RA5 are working. However, I can't get RA0- RA3 to do anything. I have two lines to try and disable the analog functionality of these pins (setup_adc(ADC_OFF); and setup_adc_ports(NO_ANALOGS); I have a fuse #fuses NOMCLR to get rid of the Master Clear pin so I can use it for I/O. I defined the pins, but nothing works. I am using Timer0 for a loop counter interrupt counter 100 counts per second for a one-second loop. I've checked the lines with a voltmeter going into RA0 and RA1 from my pushbutton switches and they are being held low through a pull-down resistor (10K) and when pressed, the lines go to 3.3v. Everything is running on 3.3v. I'm confused. I'm sure I'm missing something simple, but I don't see it. I have not set up the TRISA port because it looks to be configured correctly on power up going by the documentation. All other pins on all other ports are working. These are the only four I'm having trouble with. Any ideas?
here is what I have at the start of MAIN()...
Code: |
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_timer_0(T0_DIV_2|T0_DIV_4);//timer overflow in 131ms
setup_wdt(WDT_ON);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_timer_3(T3_DISABLED);
setup_comparator(NC_NC_NC_NC);
enable_interrupts(INT_TIMER0);
enable_interrupts(GLOBAL);
setup_oscillator(OSC_8MHZ|OSC_INTRC|OSC_PLL_OFF); |
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9241 Location: Greensville,Ontario
|
|
Posted: Wed Jul 23, 2014 1:09 pm |
|
|
stuff I'd do....
1) get rid of the WDT, NOT needed until product is going out the door(if ever)...
2) cut/test the '1 Hz LED ' program,confirming it'll run at 3V and board/PIC is good
3) get rid of timers until simple I/O works(if pin high, turn on LED test)
4) disable ALL interrupts,again until simple I/O test works.
5) normally I tie inputs high, use switches to ground inputs
gotta start with the basics, confirming at every step.
hth
jay |
|
|
davidb_csi
Joined: 16 Jul 2014 Posts: 7
|
|
Posted: Wed Jul 23, 2014 1:29 pm |
|
|
Jay,
Thanks for the reply.
1. I know the PIC is good. I have several of them. Use them on another product. The program is running. I have an LCD display and a 16-bit A/D converter working along with 9 other digital inputs from a rotary switch that are all working (Rc0 - Rc6, Ra4 and Ra5). They are connected the same way, with resistors tied to ground and switching to 3.3v. That is basically my entire circuit except for the two pushbuttons and two jumpers that are not functioning on Ra0-Ra3.
2. On my other product that uses this same PIC, I use RA0-RA2 for three analog inputs. That product has been working for a long time. I am also thinking of trying its setup to see if those inputs will work as analog inputs. I could use them that way if I have to.
3. I will also check my PCB artwork one more time. This should not be this hard for a simple project.
4. I don't have an LED on the board that I can use for a test. I will have to rig one up.
5. Right now, the program that is running simply examines the switches on the rotary switch and if it has changed positions it changes to the correct display and current output. I was going to use the Up/Dwn pushbuttons to ramp Up/Dwn from those set positions. I might also disable the rotary switch subroutine and only use the two pushbuttons to set a couple of outputs if pressed just in case my other routine is somehow overriding the pushbuttons. |
|
|
davidb_csi
Joined: 16 Jul 2014 Posts: 7
|
|
Posted: Wed Jul 23, 2014 1:31 pm |
|
|
Sorry, my compiler version is PCWHD 5.026. |
|
|
Markdem
Joined: 24 Jun 2005 Posts: 206
|
|
Posted: Wed Jul 23, 2014 5:24 pm |
|
|
PIN_A3 is also MCLR. To use it as IO you will need to have the NOMCLR fuse set. As you have not posted your fuses, I am not sure if this is the issue.
Other thing I would do is get rid of setup_comparator(NC_NC_NC_NC);. I know it make no sense as you are basically turning it off but I have had a simular problem in the past.
Have Fun |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9241 Location: Greensville,Ontario
|
|
Posted: Wed Jul 23, 2014 6:03 pm |
|
|
I just downloaded the datasheet and those pins have pullups on them. Any chance that they are enabled( maybe a default setting)? If so with your 'pull down' resistors it could result in 'odd' things happening.
I've always used pullups for switches with small C on the contacts for a bit of debounce.
hth
jay |
|
|
davidb_csi
Joined: 16 Jul 2014 Posts: 7
|
problem solved |
Posted: Thu Jul 24, 2014 2:45 pm |
|
|
Well, I knew it would be simple when I found it. I had already disabled the comparator like Markdem suggested. I had used this PIC in the past and so I started with that original configuration. However on that original configuration I had used the first three RA0 - RA2 as analog inputs so I had to delete all the configurations for that setup. I backed up and simplified my code even though I didn't think my interrupt or Timer0 setup was affecting anything. I got it working without any interrupts or timers and by only writing a small test code for those switches that I was having trouble with. I kept the LCD display routine in so I could display values when I pressed buttons. It worked! However, I still was not sure exactly what was causing my problem so I started adding in routines I had commented out. I added the Timer0 and Interrupt back in and they still worked. Then I added in one other subroutine that I suspected was causing the problem. It also adjusts the same variable that my pushbuttons are. With it back in place, the buttons quit working (apparently). I hate to admit my error but I will just to finish this post properly and I have to thank everyone for their suggestions. Backing up and going a step at a time got me to find my mistake. My other subroutine controls a rotary switch that selects a value depending on its position. My intention was to only update the value ( output to my D/A chip) from that rotary switch when it changes position or on power-up. I found that it was updating on changing position, but I had a flag that I set on power-up to update the value from the rotary switch and after it gets cleared it only looks at the switch when it changes position. I forgot to clear the %#! flag so that it was continually writing over my changes that the pushbuttons were trying to make. It took me a while to find it since I do not have a port on my board to connect anything for online debugging. It was a good exercise in troubleshooting code though! |
|
|
|