PDA

View Full Version : Code works on 16F84A but not on 16F88?



pharaohamps
- 5th November 2009, 17:55
I'm working on a project using a 16F88 to read an input voltage and act when the signal drops below a certain threshold. I had the program working on a 16F84A using an RC network and the POT command to simulate the voltage input, but in order to actually build the project I needed an A to D converter.

I got a 16F88 and can program it okay using my LABX-3 and my ICD2, my code compiles and programs, but nothing is happening on my PIC.

To test things out, I have removed everything from the circuit except the basics - 5V supply, decoupling cap, 4 MHz xtal + 2x 22pF caps, 100k resistor from RB3 to ground, and a 470R resistor in series with an LED to ground from RB4. This is the same as the LABX-18, which is designed around the 16F88. As far as I can tell, the big differences in the two chips are the locations of the TX and RX pins connected to the MAX232. My MAX232 is out of circuit.

Here is my code:


ANSEL = 0
CMCON = 7

OUTPUT PORTB.4

blink: PORTB.4 = 1
PAUSE 500
PORTB.4 = 0
PAUSE 500
GOTO blink

END



My config bits are set to:
Oscillator = XT
Watchdog timer, Powerup timer = OFF
MCLR is on
BODETECT = off
LVP is off

everything else is off.

This code works fine on a 16F84A. Am I doing something wrong with the oscillator selection? I would think that I could just tell it to use the XT oscillator, right? Do I have to tell it that it has a 4MHz xtal?

Bruce
- 5th November 2009, 22:41
With MCLR ON, do you have a pull-up resistor on the MCLR pin?

pharaohamps
- 6th November 2009, 12:48
Yes, /MCLR is pulled high. I'm using a LABX-3 development board, designed for 18 pin PICs.

I'm certain that the problem is in the program, not the hardware. As I said earlier, the same program works on a 16F84A. Programming the 16F88 with a pre-made .hex file from another project works as well, but I can't see why my code won't work.

I've turned off the analog peripherals, ANSEL = 0, CMCON = 7, and I'm feeding the clock input pins with a 4MHz crystal plus 2x 22pF caps. If I set the oscillator type to be HS I can see the 4MHz oscillation on my scope. The chip is working, so why isn't my program?

I'm not an expert on the 16F88, far from it, so is there something I'm forgetting?

If I set the oscillator to HS, do I need to tell the PIC what speed the clock is? That would be OSCCON = $60, right? I've tried that and nothing seems to work.

Is there something wrong with how I'm setting up the port? I've tried setting it with TRISB as well, and that doesn't make my LED blink either. This is the absolute simplest program I can think of to test my setup and it's very frustrating that it works great on an '84A and not on an '88. Exact same code is working on the hardware with an '84A, so I think the hardware is OK. What's wrong with my code?

pharaohamps
- 6th November 2009, 15:17
Definitely getting somewhere. I have the PIC working, but it's blinking the wrong pin! As far as I can tell, it SHOULD be blinking RB4, pin 10, but it is actually blinking RB0, pin 6. It's also not blinking as fast as it should - it should change states every 5 ms, but it's changing about every 1 s. Is there some reason RB0 would hop up and down? It's the same on two different chips as well.


@ DEVICE PIC16F88, MCLR_ON, HS_OSC, WDT_OFF, LVP_OFF, BOD_OFF, PWRT_ON, PROTECT_OFF

ANSEL = 0
CMCON = 7

TRISB.4 = 0

LED var PORTB.4

blink: LED = 1
Pause 5
LED = 0
Pause 5
goto blink
End

This is encouraging but I've got a long way to go if I can't even get the 'F88 to blink the right port pin...

Bruce
- 6th November 2009, 15:48
With a 4MHz crystal you might want to change to XT_OSC so you're not over-driving
your crystal.

I don't have an X3 board to test it with, but this definitely works on a breadboard with
a 16F88, and blinks RB4.


@ DEVICE PIC16F88, XT_OSC, MCLR_ON, WDT_OFF, LVP_OFF, PROTECT_OFF

ANSEL = 0
CMCON = 7

OUTPUT PORTB.4

blink:
PORTB.4 = 1
PAUSE 500
PORTB.4 = 0
PAUSE 500
GOTO blink

END

pharaohamps
- 6th November 2009, 17:35
Bruce, thanks for the code, but it's still not working on my PIC.

I'm using PBP v. 2.47 with MPLAB v8.15a - are there any problems with this combo that I should know about? It seems kind of crazy to me that a PIC16F84A will work correctly with the same hardware and the same code (minus the @ DEVICE instructions.)

Bruce
- 6th November 2009, 17:49
PBP v2.47 should work fine with MPLAB v8.15a.

Are you 100% sure your ICD2 is programming config settings with what you expect?

Are you programming it to run in the ICD, or just using the ICD2 as a programmer?

Have you tried programming the PIC and dropping it on a breadboard?

Are you compiling from within MPLAB, or are you using MicroCode Studio to compile?

If you're using MicroCode Studio, and you're clicking the ICD Compile VS the standard
compile button, that would explain why it doesn't work. If you click the ICD Compile
button, and program the part, it only works when connected to a PC with the MCS ICD
software running.

pharaohamps
- 6th November 2009, 18:29
OK, I just found out that we had a copy of PBP 2.60 that had not yet been installed. I had to upgrade my install of MPLAB as well (to 8.40) but the code is now working with no changes.

Bruce, thanks very much for all your help.