|
|
View previous topic :: View next topic |
Author |
Message |
canavaroski90
Joined: 09 May 2011 Posts: 9
|
PWM Confusing |
Posted: Wed May 25, 2011 4:03 am |
|
|
Hi CCS forums.
Nowadays I'm working on a gas detection project. I'm trying to change leds blinking frequency according to the value which I've get from ADC. For example, if ADC value is below then 5, then led's going to blink at 1Hz otherwise led's going to blink at 5Hz.
I've read lots of article about "PWM and low frequencies" and I saw that you can not use PWM hardware to generate too low frequencies (i.e 5Hz).
Mainly, I'm confusing about "POWER" and "FREQUENCY". Here's my question: If I want to change brightness level of led, I can use PWM. This is "POWER" line of PWM. However if I want to use flashing led in different speed, again, I can use PWM. And this is the "FREQUENCY" line of PWM. But how can I allocate two of them? How would I configure my program to allocate two of them?
Regards.
(Sorry for bad english ) _________________ Liberate your mind.. |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Wed May 25, 2011 6:58 am |
|
|
How about adding more confusion? You can even have three índependant parameters associated with a LED driver:
- a PWM duty cycle (or "POWER") to set a reduced intensity. The PWM frequency would be sufficient high to make the light appear continuous (> 100 Hz)
- an optional software blink frequency
- a blink duty cycle, ranging from short flash to symmetrical (50 %) blink |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19515
|
|
Posted: Wed May 25, 2011 7:13 am |
|
|
Forget about 'power'....
The PWM, does one thing. Generates a rectangular waveform, allowing you to specify a rate and 'pulse width'. Hence 'Pulse width modulation'.
Power is an 'outcome'. If you connect the a pulse with a width that is 25% of it's repetition rate, to a solid state switch, this switch will be 'on' 25% of the time, in many cases this gives an effective 25% 'power'. However with a lot of drivers it may not be as simple as this.
Now, you don't really appear to want PWM. Unless you want to change the brightness of the LED, it is not the tool for the job. Much simpler to have a system 'tick' running at some frequency like 50Hz, and just a counter switching the LED. Set the counter to 10, and the LED will flash at 5Hz, set it to 50, and the LED will flash at 1Hz.
If you want to change the intensity of the LED in it's flashes, then use a PWM for this, turning it on/off as needed, instead of just switching the LED, and adjusting it's mark/space ratio to give the required brightness.
Best Wishes |
|
|
canavaroski90
Joined: 09 May 2011 Posts: 9
|
|
Posted: Sat May 28, 2011 11:12 am |
|
|
Thanks for replies. Now I'm much clear about PWM and I want to ask another question.
I'm getting lots of variable values from 10 bit (16f877/A @4Mhz) ADC and I want to make this project very sensitive to gas. Because of this I'm only working on little ADC values (max 50). I've prepared 5 "if" code block for this, ADC between 0/10,10/20,20/30,30/40 and 40/50.
I want to configure my program as this:
ADC Value -- LED Flashing Frequency
0-10 1 Hz
10-20 5 Hz
20-30 10 Hz
30-40 15 Hz
40-50 Always on
If I use "delay_ms" function to get these values, simply to get 1 Hz I'm using these codes; Code: | pin_high
delay_500
pin_low
delay_500 |
For the high frequency there is no problem but when I try to use these code configuration at low frequencies, naturally my pic doesn't answer any changing on the gas rate until these delay functions finish. But I want to configure my program as 2 part. First part of controlling the ADC value, and second part is changing flashing speed of led according to these values. But these parts must be work separate and synchronous. For example, if the gas rate rises quickly while the ADC value below 10, my program musn't wait these delay functions. How could I make it happen?
Thanks, regards. _________________ Liberate your mind.. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat May 28, 2011 1:32 pm |
|
|
Quote: |
When I try to use these code configuration at low frequencies, naturally
my pic doesn't answer any changing on the gas rate until these delay
functions finish.
|
You could use interrupt-driven software PWM. Then you don't have to
wait for static delay functions to finish. The delays will be done in the
background with the RTCC (Timer0) interrupt. Example:
http://www.ccsinfo.com/forum/viewtopic.php?t=37807&start=3
To slow down the PWM rate in that example, you could increase the
RTCC_DIV_x divisor that is used in the setup_timer_0() line. Look in
the .h file for your PIC to see other available values for the divisor. |
|
|
canavaroski90
Joined: 09 May 2011 Posts: 9
|
|
Posted: Tue Jun 07, 2011 1:03 am |
|
|
Thanks for replies. I'm much more clear about pwm now. _________________ Liberate your mind.. |
|
|
|
|
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
|