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 CCS Technical Support

18F252 not passed LED test [Solved]

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
sridevi



Joined: 22 Apr 2014
Posts: 4
Location: Chennai

View user's profile Send private message

18F252 not passed LED test [Solved]
PostPosted: Sat Jul 26, 2014 12:27 am     Reply with quote

Hi,

I tried to do a LED blinking test using PIC18f252.

PIC18f252 with 8MHz crystal and 22pf capacitors. LED is connected to PORT A.1. Below is my coding.

Code:
#include <18F252.h>
#FUSES NOWDT
#FUSES HS
#FUSES NOBROWNOUT
#FUSES NOLVP
#use delay(clock=8000000)

void main()
{
SETUP_ADC_PORTS(NO_ANALOGS);
SET_TRIS_A(0);
OUTPUT_LOW(PIN_A1);

while(true)
  {
   OUTPUT_LOW(PIN_A1);
   delay_ms(1000);
   OUTPUT_HIGH(PIN_A1);
   delay_ms(1000);
  }
}

It is successfully compiled. When I run in real time, initially LED is ON as expected. After that it is not blinking.

Please help to resolve this issue. If I miss any statement, guide me.

Regards with advance thanks.
Ttelmah



Joined: 11 Mar 2010
Posts: 19545

View user's profile Send private message

PostPosted: Sat Jul 26, 2014 1:24 am     Reply with quote

Obvious thing, same problem as another poster only a couple of days ago here. MCLR not pulled up?.
The chip does also need both Vss connections, and a good decoupling capacitor close to the chip.

Then obvious tests on the actual voltage on Vdd.

Compiler version number?.
sridevi



Joined: 22 Apr 2014
Posts: 4
Location: Chennai

View user's profile Send private message

18F252 not passed LED test
PostPosted: Mon Jul 28, 2014 3:11 am     Reply with quote

MCLR pulled up via 10K resistor and Vss are properly grounded. 0.1 micro farad disc capacitor is used for decoupling and Vdd voltage is +4.98V.

CCS compiler version - PCWHD 4.140

Thanks.
Ttelmah



Joined: 11 Mar 2010
Posts: 19545

View user's profile Send private message

PostPosted: Mon Jul 28, 2014 4:15 am     Reply with quote

I'd be going over the board with a magnifying glass, looking for a whisker short, or a pad that is not making contact. Then do the same with a meter. Check for shorts between adjacent pads, and between pads and any track passing nearby. You almost certainly have a hardware problem. Could be an component being faulty (crystal etc.), or something silly, like you accidentally picked up 22nF capacitors, not 22pF. Given that these are basically identical in size when using small ceramics, it's easy to do.
When you program, make sure the programmer is set to write the fuses as well as the code, and that it does verify back correctly.
temtronic



Joined: 01 Jul 2010
Posts: 9245
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Jul 28, 2014 5:03 am     Reply with quote

another possibility is that if using MPLAB that you haven't changed the 'build configuration' from 'debug' to 'release'. This must be done before you compile(F10), then download code into the PIC.


hth
jay
sridevi



Joined: 22 Apr 2014
Posts: 4
Location: Chennai

View user's profile Send private message

18F252 not passed LED test
PostPosted: Mon Jul 28, 2014 10:27 pm     Reply with quote

Dear All,

The thing is, if I write the code in MicroC for the same hardware set up, it is working well. So, I suspect the issue is in software. Am I missed any port configuration.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jul 28, 2014 11:41 pm     Reply with quote

I made your program work with an 18F452. I plugged the PIC into a
PicDem2-Plus board (old style) and also plugged in an 8 MHz crystal.
The board has leds on pins B0-B3, so I installed a jumper wire from
pin A1 to pin B1. It runs. It blinks the LED. This test was done with
compiler vs. 4.140, the same as yours. I think you have a hardware
problem.

One question is, do you have a series resistor on the LED ? It's essential.
You can use anything from 220 to 1K ohms, and it should work. The
PicDem2-Plus board uses 470 ohms. Example of schematic:
Code:

pin      470 ohms      LED       
A1  -----/\/\/\/------->|----
                            |
                            |
                          -----  Ground 
                           ---
                            -
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Tue Jul 29, 2014 2:33 am     Reply with quote

He says his LED is initially on. With the output_low() first this suggests he has the LED connected to +5V like:
Code:
                            O  +5V
                            |
                            |
pin      470 ohms      LED  |
A1  -----/\/\/\/-------|<----


Which of the two circuits are you using?

I still didn't see a response to Temtronic's good remark about MPLAB. So again, are you using MPLAB?

Still, very strange. Not reaching the set_tris_a() function would mean the A1 pin is configured as a high impedance input and the LED would be off.
With the LED switching on it means we get to the set_tris_a() function and then the whole program should work fine as there are no other 'difficult' things after that.
This suggests a hardware problem or the program as posted is not what is used in the hardware (not having the second delay_ms() line is a classic).
Ttelmah



Joined: 11 Mar 2010
Posts: 19545

View user's profile Send private message

PostPosted: Tue Jul 29, 2014 2:41 am     Reply with quote

I'd suspect Temtronic's suggestion as the 'most likely'. If the chip in in debug mode, and there is nothing connected to the ICD pins, the chip will probably float to 'halt'...
sridevi



Joined: 22 Apr 2014
Posts: 4
Location: Chennai

View user's profile Send private message

18F252 not passed LED test
PostPosted: Tue Jul 29, 2014 4:01 am     Reply with quote

another possibility is that if using MPLAB that you haven't changed the 'build configuration' from 'debug' to 'release'. This must be done before you compile(F10), then download code into the PIC.

That is the thing happened. I change the build config to Release mode now. It is working.

Thanks to All.
temtronic



Joined: 01 Jul 2010
Posts: 9245
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Jul 29, 2014 5:44 am     Reply with quote

GREAT News !!! Please edit your subject line to include 'SOLVED' in it. That way others who read it will know it was solved and can bypass it if they want to.

You can change the default of the build configuration to 'release' if you want. The Microchip guys sent me a 'patch' to an earlier version as I never use 'debug' mode and it drove me nuts having to change it all the time.I've always 'debugged' in the real world.Cut code,burn the PIC, test and repeat as required.

cheers
Jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19545

View user's profile Send private message

PostPosted: Tue Jul 29, 2014 7:39 am     Reply with quote

As soon as the poster said the hardware was running with code from another compiler, I moved this from 'possible', to 'most likely', and (as you see), posted to say this.
It is one of those 'designed to catch you' annoyances....
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
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