View previous topic :: View next topic |
Author |
Message |
flint
Joined: 05 Jun 2010 Posts: 24 Location: Nigeria
|
Led blink! |
Posted: Sat Dec 31, 2011 10:07 am |
|
|
Hi everyone, please i know this sound silly, but i really need to know. i tried a simple code to blink a led it works in simulation, but doesn't work in reality.
compiler version is 4.032
Code: |
#include <18F2550.h>
#device ADC=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
#FUSES HS //High speed Osc (> 4mhz)
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOBROWNOUT //Reset when brownout detected
#FUSES PUT //No Power Up Timer
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT //Program memory not write protected
#FUSES NOWRTD //Data EEPROM not write protected
#FUSES NOWRTB //Boot block not write protected
#FUSES NOWRTC //configuration not registers write protected
#FUSES NOCPD //No EE protection
#FUSES NOCPB //No Boot Block code protection
#FUSES NOEBTR //Memory not protected from table reads
#FUSES NOEBTRB //Boot block not protected from table reads
#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C0,rcv=PIN_C1,bits=8)
#define led pin_c0
#define time 500
void main()
{
while(true)
{
output_high(led);
delay_ms(time);
output_low(led);
delay_ms(time);
}
} |
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19545
|
|
Posted: Sat Dec 31, 2011 10:19 am |
|
|
Usually means something really basic.
Oscillator not running.
MCLR not pulled up.
Power connections not actually getting to the chip.
Current limiting resistor on the LED not large enough.
Best Wishes |
|
|
flint
Joined: 05 Jun 2010 Posts: 24 Location: Nigeria
|
|
Posted: Sat Dec 31, 2011 10:31 am |
|
|
Ttelmah wrote: | Usually means something really basic.
Oscillator not running.
MCLR not pulled up.
Power connections not actually getting to the chip.
Current limiting resistor on the LED not large enough.
Best Wishes |
Every other thing(MCLR, vdd, resistor checked with a multimeter) except the oscillator, how do i check if its OK. I also observed that if i delete some fuses, it will blink, but not at the programmed rate. any idea? Here's another code that blinks but not at the programmed rate(much mor slower than 500ms) wat am doin wrong??
Code: |
#include <18F2550.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
#FUSES HS //High speed Osc (> 4mhz)
#FUSES NOPROTECT //Code not protected from reading
#FUSES BROWNOUT //Reset when brownout detected
#FUSES BORV20 //Brownout reset at 2.0V
#FUSES NOPUT //No Power Up Timer
#FUSES NOCPD //No EE protection
#FUSES STVREN //Stack full/underflow will cause reset
#FUSES NODEBUG //No Debug mode for ICD
#FUSES LVP //Low Voltage Programming on B3(PIC16) or B5(PIC18)
#FUSES NOWRT //Program memory not write protected
#FUSES NOWRTD //Data EEPROM not write protected
#FUSES IESO //Internal External Switch Over mode enabled
#FUSES FCMEN //Fail-safe clock monitor enabled
#FUSES PBADEN //PORTB pins are configured as analog input channels on RESET
#FUSES NOWRTC //configuration not registers write protected
#FUSES NOWRTB //Boot block not write protected
#FUSES NOEBTR //Memory not protected from table reads
#FUSES NOEBTRB //Boot block not protected from table reads
#FUSES NOCPB //No Boot Block code protection
#FUSES MCLR //Master Clear pin enabled
#FUSES LPT1OSC //Timer1 configured for low-power operation
//#FUSES XINST //Extended set extension and Indexed Addressing mode enabled
#FUSES PLL12 //Divide By 12(48MHz oscillator input)
#FUSES CPUDIV4 //System Clock by 4
#FUSES USBDIV //USB clock source comes from PLL divide by 2
#FUSES VREGEN //USB voltage regulator enabled
#use delay(clock=4000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
//NOTE: IF I ENABLE THIS FUSE IT WONT EVEN BLINK--#FUSES XINST
void main()
{
// BLINKS AT A MUCH MORE SLOWER RATE THAN WHAT I PROGRAMMED!
//BUT WORKS FINE IN SIMULATION
while(1)
{
output_toggle(PIN_A0);
delay_ms(500);
}
} |
thanks
Last edited by flint on Sat Dec 31, 2011 11:39 am; edited 1 time in total |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9245 Location: Greensville,Ontario
|
|
Posted: Sat Dec 31, 2011 10:53 am |
|
|
ahhh.....when you 'built(F10)' the program was the 'build option' set to release or the default of 'debug' ? |
|
|
flint
Joined: 05 Jun 2010 Posts: 24 Location: Nigeria
|
|
Posted: Sat Dec 31, 2011 11:08 am |
|
|
temtronic wrote: | ahhh.....when you 'built(F10)' the program was the 'build option' set to release or the default of 'debug' ? |
how do you mean, please expatiate. i used the "Build All", (F9) option on the ''Compile" tool bar.
Best regards. |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
) |
Posted: Sat Dec 31, 2011 11:31 am |
|
|
Try a simpler program. This has been confirmed to work on the
internal oscillator and blinks the LED at 1HZ. Note that I moved the
LED to Pin C1 to avoid other peripherals and keep the program simple.
Code: |
#include <18F2550.h>
#FUSES WDT //Watch Dog Timer
#FUSES PUT //Power Up Timer
#FUSES NODEBUG //No Debug mode for ICD
#FUSES MCLR //Master Clear
#FUSES INTRC_IO // INTRC_IO pin enabled
#use delay(clock=8000000)
void main()
{
while(1)
{
output_toggle(PIN_C1);
delay_ms(500);
}
}
|
If the above code does not work correctly in hardware you have a
hardware problem. (forget simulation!). if you suspect a problem
with the LED, disconnect it and use a meter to check pin_C1
In your latest code you set USE DELAY to 4MHZ then enabled the
HS fuse. Are you trying to use the internal or external oscillator?
What speed are you actually after? _________________ Google and Forum Search are some of your best tools!!!! |
|
|
flint
Joined: 05 Jun 2010 Posts: 24 Location: Nigeria
|
Re: ) |
Posted: Sat Dec 31, 2011 11:58 am |
|
|
dyeatman wrote: | Try a simpler program. This has been confirmed to work on the
internal oscillator and blinks the LED at 1HZ. Note that I moved the
LED to Pin C1 to avoid other peripherals and keep the program simple.
Code: |
#include <18F2550.h>
#FUSES WDT //Watch Dog Timer
#FUSES PUT //Power Up Timer
#FUSES NODEBUG //No Debug mode for ICD
#FUSES MCLR //Master Clear
#FUSES INTRC_IO // INTRC_IO pin enabled
#use delay(clock=8000000)
void main()
{
while(1)
{
output_toggle(PIN_C1);
delay_ms(500);
}
}
|
If the above code does not work correctly in hardware you have a
hardware problem. (forget simulation!). if you suspect a problem
with the LED, disconnect it and use a meter to check pin_C1
In your latest code you set USE DELAY to 4MHZ then enabled the
HS fuse. Are you trying to use the internal or external oscillator?
What speed are you actually after? |
YEAH!!! your code works well. Please i have some questions:
1. how did you calculate 1Hz,
2. I would like to use an external oscillator, because this program is just a fragment of what I intend to do.
3. the code i have works, but at a slower rate, slower than what I programmed(500ms). I used #delay(20,000,000), and a crystal oscillator of 20MHz(in stock), with two 22pF capacitors. any help would be appreciated.
Many thanks |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
|
Posted: Sat Dec 31, 2011 12:51 pm |
|
|
This code causes the LED to be on for 500ms then off for 500ms = 1 cycle per second or 1HZ
To try the 20MHZ crystal, change INTRC_IO to HS and connect your
crystal. Make sure to keep the connections to the PIC as short as
possible. If the LED does not blink you have a crystal problem. If it
blinks at a slower rate then try changing USE DELAY down in 1MHZ
increments until the LED is back to 1HZ and that will tell you what
actual speed you are running.
BTW, the datasheet recommends 15pf with a 20MHZ crystal. _________________ Google and Forum Search are some of your best tools!!!! |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Sat Dec 31, 2011 1:04 pm |
|
|
Note, version 4.032 is very old and is known to have many bugs. The v4 compiler became usable around version 4.075. |
|
|
flint
Joined: 05 Jun 2010 Posts: 24 Location: Nigeria
|
|
Posted: Sat Dec 31, 2011 9:34 pm |
|
|
dyeatman wrote: | This code causes the LED to be on for 500ms then off for 500ms = 1 cycle per second or 1HZ
To try the 20MHZ crystal, change INTRC_IO to HS and connect your
crystal. Make sure to keep the connections to the PIC as short as
possible. If the LED does not blink you have a crystal problem. If it
blinks at a slower rate then try changing USE DELAY down in 1MHZ
increments until the LED is back to 1HZ and that will tell you what
actual speed you are running.
BTW, the datasheet recommends 15pf with a 20MHZ crystal.
|
When I changed "INTRC_IO" HS, it did not blink at all, but if i use the code below, it blinks at a rate of 7secs:69mSecs instead of 500ms. I also tried reducing the freq by 1MHz as you suggested, but yielded no change, also, if i removed the oscillator it still blinks at the same slow rate. Please, look at it critical.
Code: |
#include <18F2550.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
#FUSES HS //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOBROWNOUT //No brownout reset
#FUSES BORV20 //Brownout reset at 2.0V
#FUSES NOPUT //No Power Up Timer
#FUSES NOCPD //No EE protection
#FUSES STVREN //Stack full/underflow will cause reset
#FUSES NODEBUG //No Debug mode for ICD
#FUSES LVP //Low Voltage Programming on B3(PIC16) or B5(PIC18)
#FUSES NOWRT //Program memory not write protected
#FUSES NOWRTD //Data EEPROM not write protected
#FUSES IESO //Internal External Switch Over mode enabled
#FUSES FCMEN //Fail-safe clock monitor enabled
#FUSES PBADEN //PORTB pins are configured as analog input channels on RESET
#FUSES NOWRTC //configuration not registers write protected
#FUSES NOWRTB //Boot block not write protected
#FUSES NOEBTR //Memory not protected from table reads
#FUSES NOEBTRB //Boot block not protected from table reads
#FUSES NOCPB //No Boot Block code protection
#FUSES MCLR //Master Clear pin enabled
#FUSES LPT1OSC //Timer1 configured for low-power operation
#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES PLL1 //No PLL PreScaler
#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
void main()
{
while(1)
{
output_toggle(PIN_C1);
delay_ms(500);
}
}
|
Happy New Year! |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
|
Posted: Sun Jan 01, 2012 8:11 am |
|
|
Why did you go back to your own code? You had something that
works. As I said before, change the ONE line I told you then:
Quote: | Make sure to keep the connections to the PIC as short as
possible. If the LED does not blink you have a crystal problem. |
Using my code, changing USE DELAY should have an effect on
the blink rate. If it doesn't something is really strange. If there is a
huge difference in the blink speed, cut the USE DELAY value in half to
start and see how close you are. _________________ Google and Forum Search are some of your best tools!!!! |
|
|
Douglas Kennedy
Joined: 07 Sep 2003 Posts: 755 Location: Florida
|
|
Posted: Sun Jan 01, 2012 8:36 am |
|
|
The LVP fuse is selected...if you are truly using LVP then OK. LVP is known for its issues if selected and you don't use low voltage programming. Use NOLVP instead. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19545
|
|
Posted: Sun Jan 01, 2012 9:14 am |
|
|
Your main crystal oscillator is not running.
When you select 'HS', the code therefore does not run.
It works with the fuses you post, but at a silly speed, because 'FCMEN', is enabled. This is the 'fail safe clock monitor'. If the oscillator you have selected does not work, it switches you to the 'emergency' oscillator Which as configured here is 1MHz, so everything runs about 20* slower than it should...
You have a hardware fault with your fuse connections. Crystal, parallel cut type between pins 9, and 10. Two capacitors (typically about 30pF), from pin 9 to ground, and pin 10 to ground. Short wires only, and be careful to keep other signals away from this area. Typical errors that would stop it working, capacitors much too large.
Best Wishes |
|
|
flint
Joined: 05 Jun 2010 Posts: 24 Location: Nigeria
|
|
Posted: Thu Jan 12, 2012 7:44 pm |
|
|
Ttelmah wrote: | Your main crystal oscillator is not running.
When you select 'HS', the code therefore does not run.
It works with the fuses you post, but at a silly speed, because 'FCMEN', is enabled. This is the 'fail safe clock monitor'. If the oscillator you have selected does not work, it switches you to the 'emergency' oscillator Which as configured here is 1MHz, so everything runs about 20* slower than it should...
You have a hardware fault with your fuse connections. Crystal, parallel cut type between pins 9, and 10. Two capacitors (typically about 30pF), from pin 9 to ground, and pin 10 to ground. Short wires only, and be careful to keep other signals away from this area. Typical errors that would stop it working, capacitors much too large.
Best Wishes |
Thanks guys, you are appreciated,....i made a silly mistake by using a wrong capacitor at the oscillator, instead of 22pF( the stock i had, had no label, so i couldn't get their rating)....Everything is working properly.
Best regards |
|
|
|