PDA

View Full Version : 16F883/886 Help



plyrathrt
- 17th August 2008, 21:15
Ok, so I am doing some tests (light some LED's) with this microcontroller before making my application with it. The problem I am having is that using RA4, RA3, RB0, and RB1 as inputs, and everything else as outputs. RB4, and RB5 specifically (haven't tested the others) have issues. When I press the button for one of the inputs, it pulses the LED's fine on the development board (EasyPIC4) and stops when I release the button as it's written this way in the code. When I move this to the breadboard, there seems to be a small leakage of current when I release the button to stop the pulsing.

I am beginning to think it's a problem with the interupts but the datasheet states they are disabled on reset. Below is the beginning of my code.

'INITIALIZE
@ DEVICE INTRC_OSC_NOCLKOUT, MCLR_OFF, WDT_OFF, BOD_OFF, PWRT_ON
PORTA = %00000000
PORTB = %00000000
PORTC = %00000000
ANSEL=0
ANSELH=0
ADCON0=0
CM1CON0=0
CM2CON0=0
VRCON = 0
TRISA = %11111111
TRISB = %11111111
TRISC = %00000000

I initalize the ports first because in the mid-range MCU reference manual it states
Note: It is recommended that when initializing the port, the data latch (PORT register)
should be initialized first, and then the data direction (TRIS register). This will eliminate
a possible pin glitch, since the PORT data latch values power up in a random
state.

Any thoughts?

skimask
- 17th August 2008, 21:59
When I move this to the breadboard, there seems to be a small leakage of current when I release the button to stop the pulsing.

I am beginning to think it's a problem with the interupts but the datasheet states they are disabled on reset. Below is the beginning of my code.
Yes, datasheet says interrupts are disabled on reset...
How about cap's across Vdd/Vss? And maybe a few other sprinkled around between your PIC and the power supply? How stout is your power supply?

plyrathrt
- 17th August 2008, 22:06
3V. The datasheet shows a minimal 2v.

plyrathrt
- 17th August 2008, 23:20
Ok, I have found that it is leaking voltage somehow when the pin is told to go low. I tried reversing the pin state to a input instead of lowing it, but it will not flash the LED at all when i do that. So basicly high LED : PAUSEUS 60000 : REVERSE LED will not make it flash.

Anything I am missing that would cause me no to be able to change the state of that pin?

plyrathrt
- 17th August 2008, 23:39
Ok, if this thing pisses me off any more, I have the option to move to a 18F2221 or 18F4321.

How to I put RA0,RA1,RA2,RA3, RB0,RB1, and RB3 as inputs?

The rest need to be outputs and go HIGH but a couple may need to be flipped to inputs for one reason or another. All inputs and outputs must be digital.

The 18F is a huge pic that I have absolutely no experience with (and I am only intermediate with 16F and 12F series).

Archangel
- 18th August 2008, 00:44
How to I put RA0,RA1,RA2,RA3, RB0,RB1, and RB3 as inputs?



RA 7 6 5 4 3 2 1 0
see bits below


TrisA =%00001111 ' RA 0:3 as inputs RA 4:7 as outputs in binary
OR
TrisA = $0F ' same thing in HEX
or
TrisA = 15 ' same thing in DECIMAL
TrisB = %00001011 ' PortB 0,1,3 as inputs



I like binary because it is easy to see at a glance, 1s are inputs, 0s are outputs
Edit: Doh!, Port calls hi / low status of output, TRIS register determines Input/Output

plyrathrt
- 18th August 2008, 01:06
Setting Tris registers isn't the problem. It's making sure that the inputs are "digital" and the outputs are setup right.

18F's use the ADCON0, ADCON1 to select pins as digital but it doesn't seem to be working for me.

I am more concerned with getting the 16F883 working properly because atleast that series I am decent with.

As you can see, I like binary too. Way easier to understand atleast for me.

Archangel
- 18th August 2008, 06:17
Ok, so I am doing some tests (light some LED's) with this microcontroller before making my application with it. The problem I am having is that using RA4, RA3, RB0, and RB1 as inputs, and everything else as outputs. RB4, and RB5 specifically (haven't tested the others) have issues. When I press the button for one of the inputs, it pulses the LED's fine on the development board (EasyPIC4) and stops when I release the button as it's written this way in the code. <font color=red>When I move this to the breadboard, there seems to be a small leakage of current when I release the button to stop the pulsing.
</font color>

By Breadboard, do you mean the white boards which you simply push in the components ?
If so, is it an old one ? I have had several of these which were corroded inside causing high resistance and open circuit issues, as well as excessive loading on OSC pins. This might explain why it works on EasyPIC, but not the breadboard. You should be using pullups or pull down resistors as appropriate according to your code.

plyrathrt
- 18th August 2008, 07:54
It's only about a year old. It's also not a cheap one. I seem to be able to get the 883 working correctly now. The problem it was having was the A/D converter. That's also why it wouldn't work highing a pin and then reversing it. Using the same code, I can't get the 886 to function properly though. Very strange because they are almost identicle and use the same datasheet.

I also managed to get the 18F4321 up just in case I run in to anymore trouble with the 883..

Archangel
- 18th August 2008, 08:54
Hello,
try adding
ADCON1 = 0
CCP1CON=0 ' shutdown capture compare
CCP2CON=0 ' modules
SSPCON =0 ' Disables syncronous serial port
SSPCON2=0