CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

In 18F4520 output_high(PIN_B2); instruction is being ignored
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
jlucas



Joined: 08 May 2011
Posts: 41
Location: Carthage, MO

View user's profile Send private message Visit poster's website

In 18F4520 output_high(PIN_B2); instruction is being ignored
PostPosted: Sun Nov 27, 2011 4:46 pm     Reply with quote

I've been stuck on this for over a week now.

Pin_B2 on an 18F4520 is an output connected directly to input Pin_B4 on a 16F685. All it does is go high or low to signal the other chip. It works in one section of the code, but in another section, the instruction for it to go high is simply being ignored.

If I put the following at the beginning of the code, I can check the pin with a volt meter, and watch it go high and low.
Code:
output_high(Pin_B2);
delay_ms(1000);
output_low(Pin_B2);
delay_ms(1000);
output_high(Pin_B2);
delay_ms(1000);
output_low(Pin_B2);

The pin also works fine in one part of the actual code. However, later in the code, when I try to send the pin high, it simply ignores the instruction.

I have some unused pins that I can connect LEDs to, and when I put instructions to send them high immediately before or after the instruction for Pin_B2 to go high, I get this:

Code:
output_high(Pin_A1);   // Red LED goes high
output_high(Pin_A2);   // Green LED goes high
output_high(Pin_B2);   // Pin_B2 does not go high
output_high(Pin_E0);   // Yellow LED goes high


I can put these instructions in a different order, but the result is the same: Pin_B2 will not go high.

What could possibly make a pin that works fine in one part of the code not work at all in another Question
_________________
Always remember, things are never so bad that they can't get worse.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Nov 27, 2011 4:56 pm     Reply with quote

Quote:
output_high(Pin_A1); // Red LED goes high
output_high(Pin_A2); // Green LED goes high
output_high(Pin_B2); // Pin_B2 does not go high
output_high(Pin_E0); // Yellow LED goes high

Make this code snippet into a small test program, complete with #include,
#fuses, #use delay(), main(), etc. Verify that it compiles OK, and then
verify that it fails.

Post a description of the external circuits on all the pins listed above.
If there is as series resistor with the LEDs, post the value of the series
resistor.

See if you can make it fail with Pin B2 disconnected from any external
circuit. That would be the best example for us.

And make sure to post your compiler version.
jlucas



Joined: 08 May 2011
Posts: 41
Location: Carthage, MO

View user's profile Send private message Visit poster's website

PostPosted: Sun Nov 27, 2011 9:57 pm     Reply with quote

If I put that section of code into the Init() routine near the beginning of the program, it works just fine. It's only later in the program that if fails.

The LEDs on A1, A2, and E0 all work fine. I only put them there to show that this section of code is executing, and that these other pins work when B2 doesn't.

There are no external resistors or other components on any of these pins. A1, A2, and E0 go directly to the LEDs and then to ground. B2, the troublemaker, goes directly to B4 on the 16F685.

I can't physically isolate B2 without damaging a rather expensive board, and even if I could repair it, I couldn't sell it later. I'd like to avoid that if possible.

The fuses, etc. are as follows:
Code:
#include "18F4520.h"
#device icd=true
#include "MATH.H"
#reserve 0x007E:0x007F
#reserve 0x00F4:0x00FF
#reserve 0x017E:0x017F
#reserve 0x01F4:0x01FF
#fuses HS,NOPROTECT,BROWNOUT,NOWDT,WDT32768,PUT,NOCPD,STVREN,NOLVP,BORV27,NOWRT,NOIESO,FCMEN,NOPBADEN,CCP2C1,NOWRTC,NOWRTB,NOEBTR,NOEBTRB,NOCPB,NOLPT1OSC,MCLR,NOXINST
#use delay(clock=20000000)
#use rs232(baud=57600, xmit=PIN_A5, rcv=PIN_C0, timeout=10, stream=ac)
#use rs232(baud=9600, xmit=PIN_B0, stream=mc)

I just updated the compiler to v. 4.124, and I'm running MPLAB v. 8.56.
Any suggestions would be greaty appreciated. Wink
_________________
Always remember, things are never so bad that they can't get worse.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Nov 27, 2011 10:48 pm     Reply with quote

Code:
A1, A2, and E0 go directly to the LEDs and then to ground

What is the Vdd voltage of the PIC ?

Do these LEDs have built-in series resistors ?

Can you post the manufacturer and part numbers of the LEDs ?
jlucas



Joined: 08 May 2011
Posts: 41
Location: Carthage, MO

View user's profile Send private message Visit poster's website

PostPosted: Sun Nov 27, 2011 11:50 pm     Reply with quote

Vdd is 5.08V.

The LEDs aren't the problem. They are only there for testing purposes, e.g., if (variable == n){output_high(Pin_A1);}else{output_low(Pin_A1);}. When I get everything to work, these 3 LEDs will be taken out, and all references to them in the code will be removed. Pin_B2 fails to go high regardless of whether the instructions for the test LEDs are present in that section of code.

I have even tried repeating the instruction several times with 10 ms delays between each iteration, but that doesn't work, either.
Code:
output_high(Pin_B1);
delay_ms(10);
output_high(Pin_B1);
delay_ms(10);
.
.
.

Of course, even if this had worked, it wouldn't have been a solution since I don't have time to waste waiting for this pin to go high.

I doubt that I have provided enough information here to figure out exactly what's going on without posting the entire code for both chips. I guess my question is, have you ever heard of anything that would cause a simple instruction like this to work in one part of the code and stop working in another?

Oh, and I forgot to add, this pin was working fine for nearly a year, and it only stopped working a few weeks ago. I have tried to backtrack to where I was before it quit on me with no luck.

Thanks again.
_________________
Always remember, things are never so bad that they can't get worse.
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Mon Nov 28, 2011 12:35 am     Reply with quote

Quote:
There are no external resistors or other components on any of these pins. A1, A2, and E0 go directly to the LEDs and then to ground.

If the pin high voltage is below 0.7*Vcc (typically, 0.5*Vcc are sufficient but not guaranted), bit set commands don't work
correctly at the affected pins. The other problem is, that operating the LED without series resistor brings up a risk of
permanently damaging the chip.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Nov 28, 2011 12:35 am     Reply with quote

Quote:

Pin_B2 on an 18F4520 is an output connected directly to input Pin_B4 on
a 16F685.

What could possibly make a pin that works fine in one part of the code
not work at all in another ?

It's connected to an external device, the 16F685. What if the 16F685
sets it's pin B4 to be a low level output at some point ? This could cause
the problem.

Quote:

I can't physically isolate B2 without damaging a rather expensive board.

Then program the 16F685 with a very simple program that sets Pin B4
as an input pin, and then it sits in a while(1); loop forever.
Code:

#include <16F685.H>
#fuses INTRC_IO, NOWDT, BROWNOUT, PUT
#use delay(clock=4M)

//==========================================
void main()
{
setup_adc_ports(NO_ANALOGS);
output_float(PIN_B4);

while(1);
}

The truth is you really don't need those two lines, since when the PIC
comes out of power-on-reset, the pin will be an input and the compiler
will set it as a digital i/o pin. But I put the two lines in there so you
could explicitly see the pin configuration.

Quote:

Oh, and I forgot to add, this pin was working fine for nearly a year, and it
only stopped working a few weeks ago. I have tried to backtrack to
where I was before it quit on me with no luck.

Well, something has changed. It could be:

1. The hardware. Boards, power supply, etc.
2. The programs in either PICs
3. The compiler versions used in either PIC.
4. Test procedures.
jlucas



Joined: 08 May 2011
Posts: 41
Location: Carthage, MO

View user's profile Send private message Visit poster's website

PostPosted: Mon Nov 28, 2011 1:42 am     Reply with quote

Unfortunately I can't get that test to work. There's a lot of interplay between the two chips before the code gets to the part that fails.

The 18F is connected to a data radio which receives 28 bytes of data in a short burst every second, and a lot of what happens depends on the input from that. I need the pin to go high when it's receiving data, so an abbreviated code in either chip can't duplicate the problem.

I can't be sure, but I doubt that the corresponding input pin on the 16F is causing the problem. The pin shows 0.00 V whether it's supposed to be high or low. The only way the input pin on the 16F could cause this would be if it had a dead short to ground. I don't think this is the case, since it works fine in another part of the code.

In the first case, when it does work, pin B2 in the 18F goes high in response to an input pin from the 16F going high. Then when that pin goes back to low, B2 on the 18F goes low.

In the second case, when it doesn't work, B2 on the 18F is supposed to go high when an if statement becomes true (based on the data being received). When that happens, two 1-bit variables are supposed to go from 1 to 0, and B2 is supposed to go high. The two variables are indeed going to 0, but B2 remains low. If I add a line to tell one the test LEDs to go high or low, the LED always works fine.

One clue that might be useful: It just occurred to me that B2 works when the chip is not receiving data from the radio module; it fails when it is receiving data. It's getting the data via the #use rs232...stream=ac statement above. Could this somehow be "distracting" it?

Anyway, it's about 1:30 a.m. here, so I'm going to turn in. Thanks again.
_________________
Always remember, things are never so bad that they can't get worse.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Nov 28, 2011 1:57 am     Reply with quote

1. Edit the 18F4520 code so that it never makes Pin B2 into an output pin.
Make sure it is always an input pin.

2. Tack a pull-up resistor on the pin.

3. Put an oscilloscope on the pin. It should be initially at a high level.

4. Run both programs.

5. Watch if the pin ever goes low. If it does, then the 16F685 is driving
it low.

This assumes there are no other circuits connected to the pin, and that
the 18F4520 code was completely checked, so it never touches pin B2.
jlucas



Joined: 08 May 2011
Posts: 41
Location: Carthage, MO

View user's profile Send private message Visit poster's website

PostPosted: Mon Nov 28, 2011 2:02 am     Reply with quote

Uh oh, it looks like I'm one post behind.
Quote:
Well, something has changed. It could be:

1. The hardware. Boards, power supply, etc.
2. The programs in either PICs
3. The compiler versions used in either PIC.
4. Test procedures.

1. The boards are the same. I have tried different units, but they all do the same thing, so I don't think there's any damage, They're designed to run on pretty crappy input power -- automotive 12-24V.
2. Oh, I've been changing the programming several times a day for a very long time, so that's definitely a possibility if not a probability.
3. I just updated the compiler, but that was after all this trouble started.
4. No change there.
Quote:
The other problem is, that operating the LED without series resistor brings up a risk of permanently damaging the chip.

Well, it looks like I've been getting away with that for some time now, but I'll be good and stick some resistors in there. Embarassed

Thanks again, guys. G'nite!
_________________
Always remember, things are never so bad that they can't get worse.
jlucas



Joined: 08 May 2011
Posts: 41
Location: Carthage, MO

View user's profile Send private message Visit poster's website

PostPosted: Mon Nov 28, 2011 2:04 am     Reply with quote

PCM programmer wrote:
1. Edit the 18F4520 code so that it never makes Pin B2 into an output pin.
Make sure it is always an input pin.

2. Tack a pull-up resistor on the pin.

3. Put an oscilloscope on the pin. It should be initially at a high level.

4. Run both programs.

5. Watch if the pin ever goes low. If it does, then the 16F685 is driving
it low.

This assumes there are no other circuits connected to the pin, and that
the 18F4520 code was completely checked, so it never touches pin B2.


This sounds like a plan. I'll give it a shot tomorrow. Thanks!
_________________
Always remember, things are never so bad that they can't get worse.
jlucas



Joined: 08 May 2011
Posts: 41
Location: Carthage, MO

View user's profile Send private message Visit poster's website

PostPosted: Mon Nov 28, 2011 5:04 pm     Reply with quote

PCM, I tried to run your test, but I couldn't figure out a way to get it to work. First, the output from Pin B2 is critical to making the system work. Without it, the program can't progress to the point where it was failing. Second, if I found a workaround for that, in order for the program to get to that point, I have to be out on the road and moving, so even if I could get it to work, I can't use my O-scope (it doesn't travel well), and the internal resistance on my multimeter is too low to measure the voltage on a pin with a 22k pullup resistor without the meter itself pulling the pin back down to near zero.

I did put some 330 ohm resistors on the LEDs. Unfortunately, that didn't fix anything. As a matter of fact, one critical feature that was working before has now stopped working.

That's been the story of this project for the past 2 years. Every single element of this system has worked at one time or another, but I have never been able to get everything working at once. Whenever I fix one problem, three other things will stop working, and it takes weeks to get back to where I was, i.e., just one last thing to fix, and it's done.

It looks like I have some work ahead of me just to get back to the point where the subject of this post may or may not become a problem again.

Thanks for all your help.
_________________
Always remember, things are never so bad that they can't get worse.
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Mon Nov 28, 2011 6:09 pm     Reply with quote

after watching your pain for a while -

i wonder:

do you have any pins that are "tris'd" to change from Input to output dynamically during program execution?
or is teh I/O state cosntant for every pin , ie: always an in or out?

perhaps you could identify all your I/O states - and add

#USE fastio(all)
and then explicitly Specify TRIS for your port pins
----------
ALSO
would it be a problem to post as much of the schematic as you are comfortable with so we can SEE for ourselves that all is
fine && dandy in circuit land?
you see you make me very nervous about the WHOLE when you talk about adding a 330 ohm resistor .
----------------
as to the potential link between your soft serial port - and the pin failure -
i am very VERY suspicious of an interaction between slightly bent circuitry
and the perceived code problem. a schematic of as much as possible would set my mind at ease as to what is REALLY wrong
--------------

and very lastly - you have tried ANTHER pic in the circuit right ?
( not just the same pic over and over ?)

i have had pics that were funky and a source of much mischief
in my history. Trying a fresh pic is always a good idea.
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Mon Nov 28, 2011 6:35 pm     Reply with quote

Quote:

Pin_B2 on an 18F4520 is an output connected directly to input Pin_B4 on a 16F685


can you insert a 5.1k resistor in series between the two pins
over a cut trace ??
then you can read the volts at both ends to SEE what is up.

just like PCM before me- i'm wondering if your "input pin" on the other pic might be an OUTPUT pin by accident after some execution time has passed.
as in you are barking up the wrong tree - code wise.


this is another way into the critical question that PCM asked you
and that you dodged previously. if you are unwilling to cut traces and
get to the heart of the matter - it is going to be harder to solve than it needs to be. Just last week i cut traces on a pilot PCB - that delivered sells for nearly $2k - and it did help me solve the problem.
done right - nobody but you will ever know

Very Happy
lastly if you have other leds that are lacking series I limit resistors--
this is a VERY VERY BAD THING!!

how do you know that the problem is not from those other leds being ON TOGETHER -and finally putting the PIC pin regulator into current limiting ?

i am not going to feel any confidence in the CAUSE OF YOUR PROBLEM TILL I SEE A SCHEMATIC .
jlucas



Joined: 08 May 2011
Posts: 41
Location: Carthage, MO

View user's profile Send private message Visit poster's website

PostPosted: Mon Nov 28, 2011 7:08 pm     Reply with quote

asmboy wrote:
after watching your pain for a while -

i wonder:

do you have any pins that are "tris'd" to change from Input to output dynamically during program execution?
or is teh I/O state cosntant for every pin , ie: always an in or out?

All pins are specified as inputs or outputs.
Code:
   SET_TRIS_A(0xD9);               // 1101 1001
   SET_TRIS_B(0xFA);               // 1111 1010
   SET_TRIS_C(0xFF);               // 1111 1111
   SET_TRIS_D(0xFF);               // 1111 1111
   SET_TRIS_E(0xFE);               // 1111 1110
   SETUP_ADC_PORTS(NO_ANALOGS);      // Set analog ports to digital

Quote:
perhaps you could identify all your I/O states - and add

#USE fastio(all)
and then explicitly Specify TRIS for your port pins

Okay, I'll give #use fast_io(all) a try.
Quote:
ALSO
would it be a problem to post as much of the schematic as you are comfortable with so we can SEE for ourselves that all is
fine && dandy in circuit land?
you see you make me very nervous about the WHOLE when you talk about adding a 330 ohm resistor .
----------------
as to the potential link between your soft serial port - and the pin failure -
i am very VERY suspicious of an interaction between slightly bent circuitry and the perceived code problem. a schematic of as much as possible would set my mind at ease as to what is REALLY wrong

You can get a schematic here:
http://www.lucastechnologies.com/Images/SCHEMATIC1_RX_V1.pdf (The url tags don't work. Right-click and open in new tab or window.)
I figure that if someone really wanted to, they could reverse-engineer this from the board. It's the firmware that makes it unique.

One change, the Dataradio module has been replaced with a Laird (formerly Aerocomm) AC4790 radio module. It only requires 4 wires: send, receive, power, and ground. The now-unused connections to header J3 are what I'm now using for test LEDs
Quote:
and very lastly - you have tried ANTHER pic in the circuit right ?
( not just the same pic over and over ?) i have had pics that were funky and a source of much mischief in my history. Trying a fresh pic is always a good idea.

I can't change out a chip on the board, but I can switch out an entire board. It's has never fixed anything, but that's never stopped me from trying it when nothing else seems to work.
_________________
Always remember, things are never so bad that they can't get worse.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group