PDA

View Full Version : 16f88 problems



mikey11
- 13th August 2009, 23:40
Greetings,

I've written a program for the 16f88 which is behaving strangely in the circuit.

I have an initial loop which waits for a button press, the button press leaves the loop, then evaluates two other pins for high or low status (a two position switch is forcing one of the pins high, and the other low).

Depending on the status the program proceeds to a ten second timed section, or a ten minute timed section.


The behaviour is this: When power is initially applied, the pic jumps past the first wait. Even when I add a two second pause before entering the loop to evaluate the first button press.

It evaluates the two pins, and proceeds to the timed section. It is evaluating the two pins properly, and the timed sections run flawlessly.

When the timed section are complete, it goes back to the loop waiting for the start button.

Then the device operates properly.
Why would it skip the wait for button press loop on the first execution?

I have tied MCLR to vdd with a 10k resistor. I have a 10uF electrolytic smoothing out the supply which is from an lm7805 supplied by a high capacity 12v source. I have a 100nf cap between vdd and ground right at the pins.

The behaviour hasn't changed at all with these extra components in place.

I have some questions; If you state ansel = 0 does that mean the analog pins are now digital? I would like this to be the case.

I've heard that defining MCLR as an input is a mistake because you can't reprogram the pic properly thereafter. This could be the case. On the same token, I've heard that MCLR can't act as an output. So I don't know what I should do with this.

I'm using the internal oscillator.

Any Ideas? I am totally stumped, and it's for a product I'd like to demo for a group ASAP.

Mike

mackrackit
- 14th August 2009, 00:09
Can we see your code?

mikey11
- 14th August 2009, 01:38
Unfortunately I don't have it with me. When I get home I will put it up.

I'm curious if there are any events during startup which could influence my code to jump past the first loop that is waiting for the buttonpress.

Also my question about ansel = 0 and whether that makes the analog pins digital still stands.

Also the fixes I tried with power supply, and the questions about the MCLR pin are still bothering me.

As I say, I don't actually think it's the code that is the problem. I feel it's more of an odd hardware issue with the 16f88. I realize this is a pbp forum, but other people have had trouble with the 16f88 that are similar to mine, and I thought some people here may have already faced this one down.

My code size is small enough for the chip as well. Something like 500 words.

mackrackit
- 14th August 2009, 03:27
I do not have the data sheet in front of me but I do not think ansel=0 is the way to go.
Check the data sheet and read this.
http://www.picbasic.co.uk/forum/showthread.php?t=561

MCLR is not a problem when made an input. The only concern is tothe external parts if any being able to handle the higher voltage. A well placed diode will normally solve any problems.

Archangel
- 14th August 2009, 17:04
I'm curious if there are any events during startup which could influence my code to jump past the first loop that is waiting for the buttonpress.

Hi Mikey11,
The buttonpress . . . does it go high or low when pressed? What is its power off status? Any chance your PIC is seeing a buttonpress condition there ? Can you accept a delay at startup before initialising your TRIS registers ?

languer
- 14th August 2009, 21:10
You still need to post the code. It truly sounds like you have something not properly initialized. If nothing else the code will show which pins are in use and what functions those pins share.

Make sure you have CMCON = 7, as well as ANSEL = 0.

mackrackit
- 14th August 2009, 21:23
As I say, I don't actually think it's the code that is the problem. I feel it's more of an odd hardware issue with the 16f88.
So why should the OP post the code? We were told that is not the problem.

languer
- 14th August 2009, 23:44
Oh let's see...

If the code does not properly initialize the HW, the HW does not behave as expected. Such is the lifecycle of embedded programming. But I see, that was you point from the beginning ...
I do not have the data sheet in front of me but I do not think ansel=0 is the way to go.Check the data sheet and read this. http://www.picbasic.co.uk/forum/showthread.php?t=561

:)

Oh well, hopefully he takes the advice. Its all given in good faith (and free).

mikey11
- 19th August 2009, 20:36
hi guys, sorry about the wait. I work over 1000km away from my home, and don't get many opportunities to be there at the moment.

Here is the code up to and including the first loop where it waits for a button press.

<code>

Include "modedefs.bas"
CMCON=7 'allows you to use pins as digital rather than analog
ADCON1 = %00000111 ' Disable A/D converter
ANSEL=0 'allows you to use pins as digital rather than analog
@ DEVICE PIC16F88, INTRC_OSC_NOCLKOUT, MCLR_OFF, WDT_OFF, LVP_OFF, PWRT_ON, PROTECT_OFF, BOD_OFF
DEFINE OSC 8
OSCCON = %01110000 ' INTRC = 8MHz



'declare inputs and outputs appropriately
TRISA = %00111100 ' a.5 is INPUT only
TRISB = %11100100


'define variables
mscounter var word
secondcounter var word
minutecounter var word
loopvar var word

'INPUTS First Name them by pin
rwire var portb.2
bwire var portb.1
mswitch var portb.0
playmode var porta.2
testmode var porta.3
startbutton var portb.5
'eventually the mode switch it will be a three position switch, and a.4 will be another input.

'OUTPUTS, Name them
solenoid var portb.3
modeled var porta.1
flashingled var porta.0
buzzer var portb.4



'Now perform the initial wait until the start switch is pressed
modeled = 1
solenoid = 0
pause 2000
startloop:
flashingled = 1
pause 50
if startbutton = 1 then goto checkvalues
flashingled = 0
pause 50
if startbutton = 1 then goto checkvalues
goto startloop

</code>

As I've indicated before, the rest of the code works fine, and it eventually leads back to this first loop. On the first execution, it skips this loop, and proceeds to the next section of code. When the program completes it comes back to startloop and then everything runs fine. I just need it to engage this first loop the first time.

I do not have an absolutely clear understanding of the ANSEL and CMCON commands. I've read about them and think I'm using them right.

It's possible I shouldn't even be using the ADCON command. I don't know though.

If anyone has great ideas I'm still very much interested in sorting this out.

Cheers, Mike

mackrackit
- 20th August 2009, 01:41
ADCON1 is not used that way on this chip so get rid of that. If that does not solve the problem I would look at your hardware setup. Something giving a false signal . How is the solenoid connected ?

mikey11
- 20th August 2009, 06:09
I had thrown a 2 second pause in to allow for things to stabilize, then I read the post where the pause should be before the tris statement is made. I'll try that.

I will try removing adcon as well.

The solenoid is hooked up via an output from a digital pin. When the pin goes high it trips a 2N3904 which completes a circuit for a 12V relay which then fires the solenoid itself.

Both the solenoid and the relay have protection diodes in place.

The solenoid is running a regulated air system.

I did have this system working with a 16f819, but my computer crashed and I didn't have a backup (silly me). I can confirm that the general scheme I used components wise has worked completely in the past. The only thing that is substantially different is the pic, and I put more of the components on the circuit board.

removing adcon had no effect, and the pause prior to the tris statements didn't seem to do anything either.

Unfortunately I leave again, and won't have a chance to work on it again for a while. I think these initial statements are where the problem resides. Something transient to do with the interplay between configuration, and hardware just as power is applied.

Can anyone tell me about the difference between ADSEL and ANSEL? I have seen references to ADSEL and the 16f88 by people using other compilers than pbp.

-Mike

languer
- 21st August 2009, 08:08
So from the code and your statement it looks like either the first "if startbutton = 1 then goto checkvalues" is reading incorrectly; or perhaps the first "flashingled = 0" is not being executed.

Your initial settings look fine. You can remove the ADCON1 as this chip does not have this. I would perhaps have the order different (i.e. @device first), but I do not think it should make a difference.

How is the "startbutton" input connected? Is it sharing anything with the solenoid?

How is the "flashingled" connected?

If you disconnect the solenoid output, does the code runs as expected?

aratti
- 21st August 2009, 09:53
'declare inputs and outputs appropriately
PortA = 0
PortB = 0
TRISA = %00111100 ' a.5 is INPUT only
TRISB = %11100100

Try to set portA and B to zero before Tris
What value is your pulldown resistor?

Al.

mikey11
- 25th August 2009, 23:19
So from the code and your statement it looks like either the first "if startbutton = 1 then goto checkvalues" is reading incorrectly; or perhaps the first "flashingled = 0" is not being executed.

Your initial settings look fine. You can remove the ADCON1 as this chip does not have this. I would perhaps have the order different (i.e. @device first), but I do not think it should make a difference.

How is the "startbutton" input connected? Is it sharing anything with the solenoid?

How is the "flashingled" connected?

the button is such that a wire leads from +5v to the switch, then from the switch to the pin and to a resistor to ground.

The LED's are outputs from the pic that have a current limiting resistor of 1000 ohms.

If you disconnect the solenoid output, does the code runs as expected?

I have disconnected the solenoid output with no resolution of the problem.

mikey11
- 25th August 2009, 23:22
'declare inputs and outputs appropriately
PortA = 0
PortB = 0
TRISA = %00111100 ' a.5 is INPUT only
TRISB = %11100100

Try to set portA and B to zero before Tris
What value is your pulldown resistor?

Al.

the pulldown resistor is 1000 ohms.

I won't have the opportunity to try new code for a while, but I will try that when I get a chance.

Archangel
- 26th August 2009, 05:25
the pulldown resistor is 1000 ohms.

I won't have the opportunity to try new code for a while, but I will try that when I get a chance.I agree with Al, set port latches low before the tris register and make sure RBPU is disabled OPTION_REG.7 = 1

languer
- 26th August 2009, 08:07
The following may correct any R-W-M mismatch condition, but it is a little risky to write to the output latch (even if not an output) when it maybe directly connected to +5V (through the SW):
PortA = 0
PortB = 0
Would an initial read to the port, before the actual loop, do the same?

The RBPU should be disabled by default (unless PBP assigns it behind the scenes).

For these reasons I would have the port connected to +5V through a 10k resistor; and the switch would connect the port to GND (may be through 1k for protection).

The following post may give some ideas (not identical, but helps illustrate): http://www.picbasic.co.uk/forum/showthread.php?t=10516&highlight=weak+pull-up

languer
- 26th August 2009, 09:12
Forgot to say that should you do this:
For these reasons I would have the port connected to +5V through a 10k resistor; and the switch would connect the port to GND (may be through 1k for protection). You would change your code to read, "if startbutton = 0".