Strange RC2 LED behavior on EASYPIC4 board

General discussion on mikroPascal.
Post Reply
Author
Message
Rotary_Ed
Posts: 756
Joined: 26 Dec 2004 23:10
Location: Matthews, NC, USA
Contact:

Strange RC2 LED behavior on EASYPIC4 board

#1 Post by Rotary_Ed » 06 Jan 2007 18:27

I set up a simple program to alternately turn on and off the PORTC LEDs on my EASYPIC4 board with a 18F4620 chip 8 Mhz

I found that all the PORTC LEDs would alternate ON and OFF as expected with the exception of LED RC2. It remains off. I checked the LED using the push button and the LED lights when the button is depressed. I also put a scope on pin RC2 and there is NO alternating state.

I then decided to use the new ICD function of the board (GREAT!). This is what I found the code doing on the chip.

First the code:

Code: Select all

program USARTSCOPE;

begin
     //uses 18F4620 at 8 Mhz

      TRISC := %00000000;   //All pins output
      PORTC := $FF;   //Turn all LEDs ON
      Repeat
            PORTC := NOT PORTC;    //Inverse Condition of LEDs
      Until 1 = 2;
          
end.
The ICD debuggers shows the following on three registers:

after TRISC := %00000000;

TIRSC = 0000 0000 //this is as expected
PORTC = 1000 0000
after PORTC := $FF line debugger shows

PORTC = 1100 0000//Apparently garbage
WREG = 1111 1111 //loading FF into working Register before sending it to portC

After PORTC := NOT PORTC;
*****************************************

PORTC = 1111 1011//Here is why my LED RC2 is not lighting!!! For some reason the WREG does not transfer 1111 1111 which would light all LEDs but instead sends 1111 1011

Wreg := 1111 1111//still shows FF in working register - so why didn't it transfer correctly to PORTC??????


******************************************

On the second time through the repeat loop PORTC := NOT PORTC correctly gives

PORTC = 0000 0000

However, each time when the PORTC := NOT PORTC should give a
PORC = 1111 1111, it instead incorrectly gives 1111 1011 and RC2 LED never lights.

So the ICD debugger clearly show that RC2 LED does not light because it never gets its bit set, but the question is why does this not happen.

I switched the chip for a different 18F4620 in case there was a problem with the first chip - but I get the same results.

Any illumination would be appreciated
Rotary_Ed
Matthews, NC USA
Rv-6A N494BW Rotary Powered

FRM
Posts: 381
Joined: 20 May 2005 18:58
Location: UK

#2 Post by FRM » 06 Jan 2007 19:56

Ed, I don't know the 18F4620 individually well well enough to be much use, suffice to say that RC2 has ECCP1 compare/PWM functionality multiplexed onto the pin so it may be wise to try to set relevant reg's and guarantee the port pin functions are well and truly disabled to avoid any peripheral overrides. Other than that there may be a code problem here.

janni
Posts: 5373
Joined: 18 Feb 2006 13:17
Contact:

#3 Post by janni » 06 Jan 2007 20:02

Cannot help you with the way the debugger works, but instead of

Code: Select all

PORTC := NOT PORTC;
use

Code: Select all

LATC := NOT LATC;
to avoid reading the actual state of PORTC inputs.

The negation is realized through COMF assembly instruction which performs 'read, modify, write' operation. When you use output latches (LATC), the same operation will not read the state of the inputs.

This may not help if there is something wrong with the board or some peripheral override occurs (RC2 is used by ECCP1 - make sure it's off), but at least it's done correctly.

Rotary_Ed
Posts: 756
Joined: 26 Dec 2004 23:10
Location: Matthews, NC, USA
Contact:

RC2 Strange Behavior

#4 Post by Rotary_Ed » 06 Jan 2007 20:24

Thanks Janni and FRM,

Janni I tried your suggestion (good practice for me to follow from now on), but it had not effect. RC2 still refused to blink.

FRM, Good point, I'll read up on the ECCP2 function in the specs and see if they may have it default configured to analog of some such thing.

Thanks again folks
Rotary_Ed
Matthews, NC USA
Rv-6A N494BW Rotary Powered

Rotary_Ed
Posts: 756
Joined: 26 Dec 2004 23:10
Location: Matthews, NC, USA
Contact:

No EASYPIC4 Board Problem, 2 bad Chips= USART/RC2 problems

#5 Post by Rotary_Ed » 06 Jan 2007 21:32

Well, I verified that:
1. RC2 was not grounded
2. RC2 was connected to the RC2 LED
3. RC2 LED was indeed functional.

I read up on the ECCP and there is a function for PW that may use the RC2 pin as P1A. I tried several different configurations to see if that made a difference - no joy.

So, I replaced the 18F4620 with a second 18F4620 - Eurka. The RC2 LED now blinked. However, the RC6 pin would now NOT blink! What was this - could I have two bad chips? Naahhh! Well, I stuck the orginal chip that came with the board back in (16F877A) and all LED functioned as expected.

It is clear that the two 18F4620 chips which have been used in two previous Mikro boards must have had some wear and tear. I have no clue as to why pin RC2 on on chip (well, maybe - I do quite a bit of CCP1/CCP2 playing) The RC6 pin not working may well have been the reason for my orginal USART problem that seemed to mysteriously disappear. I must have swap in the chip with the bad RC2 pin but good RC6 pin onto the board and got the USART functional.

So thanks again FRM and Janni for your suggestions - the problem is solved and there is no problem with the board regarding those two area.
Rotary_Ed
Matthews, NC USA
Rv-6A N494BW Rotary Powered

FRM
Posts: 381
Joined: 20 May 2005 18:58
Location: UK

#6 Post by FRM » 06 Jan 2007 22:10

Well it's fortunate you found that problem - could've been a red-herring for some time. Not so fortunate is having two chips with the function sensitive faults as they were!

I'm not sure how those odds work out... :wink:

Glad things are ok now Ed.

Rotary_Ed
Posts: 756
Joined: 26 Dec 2004 23:10
Location: Matthews, NC, USA
Contact:

Thanks

#7 Post by Rotary_Ed » 06 Jan 2007 22:19

I make a lot of use of the development board to drive/receive/interface with my project boards which use both CCP and USART - so apparently a momentary out of spec voltage or current probably did the pins in.

But, you are right - had I not had the two chips to compare and then the original (undamaged chip) to show that my suspicions were correct, I could have been pulling my hair for a long time :lol:

I appreciate you suggesting looking into the ECCP specs because there is a P1A function on the RC2 pin that can/will apparently overide any previous state in order to deliver PWM. Will need to remain aware of that!

Now all I have to do is wait for my new chips to come in :D

Thanks again
Rotary_Ed
Matthews, NC USA
Rv-6A N494BW Rotary Powered

Berry Papay
Posts: 1
Joined: 23 May 2012 09:31

Re: Strange RC2 LED behavior on EASYPIC4 board

#8 Post by Berry Papay » 23 May 2012 09:38

I appreciate you suggesting looking into the ECCP specs because there is a P1A function on the RC2 pin that can/will apparently overide any previous state in order to deliver PWM. Will need to remain aware of that! :D






--------------------------
led strip lighting
high density led strip
12v led light bars

Post Reply

Return to “mikroPascal General”