View previous topic :: View next topic |
Author |
Message |
noisepic
Joined: 24 Jul 2005 Posts: 20
|
led blink problem? |
Posted: Mon May 15, 2006 9:56 am |
|
|
Code: |
#include<18F458.h>
#fuses NOWDT,HS,NOLVP,NOBROWNOUT,PUT,NOCPD,NOSTVREN,NODEBUG,NOWRT
#use delay(clock=8000000)
void main()
{
int16 temp;
int8 i;
for(i=1;i<10;i++)
{
output_high(PIN_D5);
delay_ms(300);
output_low(PIN_D5);
delay_ms(300);
}
} |
I want led on PIN_D5 blink with cycle of 300 ms. But they blink not in the same. and more than 10 times. I don't know why? How can i fixed this problem? |
|
|
sjbaxter
Joined: 26 Jan 2006 Posts: 141 Location: Cheshire, UK
|
|
Posted: Mon May 15, 2006 10:14 am |
|
|
You have no 'loop' at the end of 'main'. After the 10 flashes the PIC will go into sleep mode !!
try:
Code: | #include<18F458.h>
#fuses NOWDT,HS,NOLVP,NOBROWNOUT,PUT,NOCPD,NOSTVREN,NODEBUG,NOWRT
#use delay(clock=8000000)
void main()
{
while(1)
{
output_high(PIN_D5);
delay_ms(300);
output_low(PIN_D5);
delay_ms(300);
}
}
|
If you don't just want it to keep flashing, you need to tell us what it is SUPPOSED to do rather than telling us what it IS doing !!! We can see from the code what it WILL do.
The code is only 7 lines long ... you should be able to work this one out for yourself. _________________ Regards,
Simon. |
|
|
Ttelmah Guest
|
|
Posted: Mon May 15, 2006 10:19 am |
|
|
I'd 'suspect', that the most likely fault, is a hardware problem. How is the LED wired?. What current limiting resistor is used on the D5 connection?. How is the processor powered?. What supression components ar present?. How is MCLR connected?. Are both pairs of power and ground connections made?.
The code as posted, should blink the LED 9 times (not ten), and the period should be almost perfect (bar a couple of uSec for the actual loop), and then the code will stop (hitting the hidden sleep). However I'd suspect something silly, like a glitch on the power rail, when the LED turns on, so that the chip then resets, giving continuous flashes, but of a short duration.
Best Wishes |
|
|
sjbaxter
Joined: 26 Jan 2006 Posts: 141 Location: Cheshire, UK
|
|
Posted: Mon May 15, 2006 10:22 am |
|
|
You have asked this question before ....
Original Question
... I suspect you need to read the answer again !!! _________________ Regards,
Simon. |
|
|
noisepic
Joined: 24 Jul 2005 Posts: 20
|
|
Posted: Mon May 15, 2006 10:36 am |
|
|
Maybe something wrong in configuration bit. This is very simple code, i'm newbie use PIC18F458. I want a Led blink with cycle of 500ms. But i can;t see it blink.
Helpme pls, i don't have much time with simple ..things. |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Mon May 15, 2006 11:15 am |
|
|
You have no while(1) statement.
Code: |
#include<18F458.h>
#fuses NOWDT,HS,NOLVP,NOBROWNOUT,PUT,NOCPD,NOSTVREN,NODEBUG,NOWRT
#use delay(clock=8000000)
void main()
{
int16 temp;
int8 i;
for(i=0;i<10;i++)
{
output_high(PIN_D5);
delay_ms(300);
output_low(PIN_D5);
delay_ms(300);
}
while(1)
{
}
} |
|
|
|
noisepic
Joined: 24 Jul 2005 Posts: 20
|
|
Posted: Mon May 15, 2006 6:37 pm |
|
|
I have test some connection on my circuit board
+ MCLR --> OK
+ Both power supply-->OK
+ Resistor connected with LED 330 ohm
+ Crystal -> HS
When I measure PIN OSC1,OSC2( Pin13,14) there is no pulse or wave althought righ connection.
Have you ever met this problem!! |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Mon May 15, 2006 6:42 pm |
|
|
Measure the output of the LED. If it is blinking, then the crystal must be doing something. |
|
|
Richard Arroyo
Joined: 04 Apr 2006 Posts: 22 Location: Sebastopol, CA
|
|
Posted: Tue May 16, 2006 12:44 am |
|
|
Try setting the Tris regisiters otherwise the pins may remain in high impedance state if your compiler doesn't automatically set the Tris regisiters .
Code: |
#include<18F458.h>
#fuses NOWDT,HS,NOLVP,NOBROWNOUT,PUT,NOCPD,NOSTVREN,NODEBUG,NOWRT
#use delay(clock=8000000)
void main()
{
int16 temp; //<<-- Must be for something else
unsigned int8 i;
SET_TRIS_D(223); //11011111 RD5 as output <<-- see if this helps
for(i=0;i<20;i++)
{
output_toggle(PIN_D5);
delay_ms(300);
}
//The PIC will now sleep
} |
_________________ RAA |
|
|
noisepic
Joined: 24 Jul 2005 Posts: 20
|
|
Posted: Tue May 16, 2006 4:44 am |
|
|
oh!! TRISD . I have modified my code. it runs well.
thanks so much.
Richard Arroyo
The first your post is very very good!! |
|
|
|