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

Led blink!

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



Joined: 05 Jun 2010
Posts: 24
Location: Nigeria

View user's profile Send private message

Led blink!
PostPosted: Sat Dec 31, 2011 10:07 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Dec 31, 2011 10:19 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Dec 31, 2011 10:31 am     Reply with quote

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: 9244
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Dec 31, 2011 10:53 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Dec 31, 2011 11:08 am     Reply with quote

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

View user's profile Send private message

)
PostPosted: Sat Dec 31, 2011 11:31 am     Reply with quote

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

View user's profile Send private message

Re: )
PostPosted: Sat Dec 31, 2011 11:58 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Dec 31, 2011 12:51 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Dec 31, 2011 1:04 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Dec 31, 2011 9:34 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Jan 01, 2012 8:11 am     Reply with quote

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

View user's profile Send private message AIM Address

PostPosted: Sun Jan 01, 2012 8:36 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Jan 01, 2012 9:14 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Jan 12, 2012 7:44 pm     Reply with quote

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
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