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

A Real Newbie Q: LED Duty cycle?

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



Joined: 17 May 2005
Posts: 213

View user's profile Send private message

A Real Newbie Q: LED Duty cycle?
PostPosted: Thu Jul 07, 2005 8:53 am     Reply with quote

Hi

I have a real newbie question:
I would like to have an LED that shows that the circuit is on.
However, I would like to use as little current (power) as possible to do this e.g. by having a duty cycle (?). Can someone please suggest how an LED can show that the PIC is "on", while consuming as little current as possible?

If possible I would like to use the PIC itself to do this with no extra components. At the moment the PIC is executing a continous loop with INT_RB enabled.

Thank you in advance
arrow
rwyoung



Joined: 12 Nov 2003
Posts: 563
Location: Lawrence, KS USA

View user's profile Send private message Send e-mail

PostPosted: Thu Jul 07, 2005 9:12 am     Reply with quote

Use one of your timer interrupts to blink the LED. The blink rate needs to be high enough to seem constant on (persitance of vision). You can also fool around with the duty cycle to adjust the apparent brightness of the LED.

Or instead of setting up the period so the LED seems constant ON, you might consider blinking it. Think of it like a heartbeat. You can even alter the speed to indicate normal or error states.
_________________
Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month!
newguy



Joined: 24 Jun 2004
Posts: 1909

View user's profile Send private message

PostPosted: Thu Jul 07, 2005 10:00 am     Reply with quote

Just to expand on what was already said, if you blink the LED at a rate higher than about 100 Hz, it will look like it is continuously on. Just play with the duty cycle, starting at maybe 50%, and work down to about 1% or less. Stop where you feel comfortable with the brightness.
asmallri



Joined: 12 Aug 2004
Posts: 1635
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Thu Jul 07, 2005 10:23 am     Reply with quote

Use one of the newish high efficiency LEDs - these require less current for the same effective light output.

Varying the duty cycle will not produce you a better result (lower average current) than limiting the current through the LED by increasing the value of the series resistor. The resistor is simple to implement - no code required :-)

You play with duty cycle when you want to be able to dim a led under program control.
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Thu Jul 07, 2005 11:56 am     Reply with quote

Another way is doing a short blink every 2 sec (aprox) using interrupts, it will be enough
to show that the circuit is running and is alive.

Humberto
John P



Joined: 17 Sep 2003
Posts: 331

View user's profile Send private message

PostPosted: Thu Jul 07, 2005 5:32 pm     Reply with quote

What's the power supply voltage? If it's low, close to the LED's forward drop, then you're about as efficient as you can be already. If it's a 5V system, then you're losing power in the series resistor.

If that's the case and you really must minimize current flow, then you need a circuit involving an inductor--basically you'd be creating a switching voltage regulator; more like a current regulator. The idea would be output on, current builds up through inductor and LED. Output off, inductor keeps current flowing via a diode, Schottky type for best efficiency. You can improve on that if you replace the diode with a transistor controlled synchronously, but it ends up more complicated and needs an extra pin. Actually you might be able to do it with a transistor drive off a single pin, with the LED acting as the diode in the inductive circuit. No promises, but it would be fun to try.
asmallri



Joined: 12 Aug 2004
Posts: 1635
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Thu Jul 07, 2005 7:08 pm     Reply with quote

John P wrote:
What's the power supply voltage? If it's low, close to the LED's forward drop, then you're about as efficient as you can be already. If it's a 5V system, then you're losing power in the series resistor.

If that's the case and you really must minimize current flow, then you need a circuit involving an inductor--basically you'd be creating a switching voltage regulator; more like a current regulator. The idea would be output on, current builds up through inductor and LED. Output off, inductor keeps current flowing via a diode, Schottky type for best efficiency. You can improve on that if you replace the diode with a transistor controlled synchronously, but it ends up more complicated and needs an extra pin. Actually you might be able to do it with a transistor drive off a single pin, with the LED acting as the diode in the inductive circuit. No promises, but it would be fun to try.


If you wanted to try this approch you should use a FET instead of a traditional transitor otherwise you waste current driving the BE junction. Using a LED instead of the schottky diode is not likley to be very efficient and could lead to the failure of the transistor / FET as the LED response time will likely be to slow to protect these devices.

LEDs are a current driven device, not a voltage driven device. Attempting to operate a LED without a series resistor can (and likely will) lead to problems (note John P was not proposing to remove the resistor I just added this in case others made that assumption). The LED has a typical diode transfer function but the knee happens around 1.5volt as opposed to 0.7 volts. Also the knee is very much dependant on the characterists of the specific implementation just as the knee for a schottky diode is significantly different to that of a typical IN4148 silicon diode. If you apply to high a voltage then you will start conducting large current through the diode.
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
arrow



Joined: 17 May 2005
Posts: 213

View user's profile Send private message

PostPosted: Fri Jul 08, 2005 4:25 am     Reply with quote

Hi

Thank you all for your posts.
I like the flashing of the LED every 2 seconds idea.
However, I have a problem with interrupts.
I already have interrupts INT_RB- my sensors are on that interrupt, and I would not like to disturb things with another interrupt (unless it has no effect on the performance).
Can someone please tell me how I would implement a short flash with very little consequences?
In general will a delay_ms(100) effect my INT_RB?

Thank you and
Regards
arrow
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Fri Jul 08, 2005 6:46 am     Reply with quote

It should have little impact. But there is nothing stopping you from polling the interrupt flag bits in the main loop. Since you are only concerned with 2 seconds, the accuracy doesn't have to be that great so just poll the flag bit and if set, then execute some function.
arrow



Joined: 17 May 2005
Posts: 213

View user's profile Send private message

PostPosted: Fri Jul 08, 2005 7:01 am     Reply with quote

Hi Mark

Thank you for your post.

Which has a higher priority: INT_RB or INT_Timer2.
I would like INT_RB to have a higher priority- is there any way of setting this?

I am assuming that INT_RB will interrupt a "delay_ms(100)" command- is this right?

Also, if an INT_RB occurs while I am in INT_TIMER2 subroutine, will the INT_RB start after INT_TIMER2 is complete? (or will the INT_RB not execute at all in this case?)

Thank you
arrow
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Fri Jul 08, 2005 11:40 am     Reply with quote

I am assuming that INT_RB will interrupt a "delay_ms(100)" command- is this right?

Yes so long as you don't use a delay routine in an interrupt or a function called by an interrupt. The compiler will disable ints if you do.

Which has a higher priority: INT_RB or INT_Timer2.

They have the same on a PIC. You can use the priority statement to set the order for which the interrupt flags are checked.

Also, if an INT_RB occurs while I am in INT_TIMER2 subroutine, will the INT_RB start after INT_TIMER2 is complete?

Yes
prajeesh
Guest







controlling GSM modem
PostPosted: Mon Apr 17, 2006 4:44 am     Reply with quote

hi,

am trying to communicate with a GSM modem using rs232. am facing some problem while reading the response from the modem. i used #int_rda for triggering the read operation. am not able to read the response from the modem

can anyone help me in this

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