|
|
View previous topic :: View next topic |
Author |
Message |
cvargcal
Joined: 17 Feb 2015 Posts: 134
|
How do it blink LED by PWM |
Posted: Wed Jun 08, 2016 10:46 pm |
|
|
Hi, I want make a simple blink LED but by pwm.
for example this:
Code: | #include <16f887.h>
#device adc = 10
#use delay (clock=4000000)
#include <lcd.c>
#define LED PIN_B5
void blink_led(PIN,int8 time_up,int8 time_down );
void main(){
while(1)
{
blink_led(PIN,33,600 );
}
} |
But I find the way directly in hardware... not by someone function. Because I want implement to RTOS.
if I do by this function, when change of task, the blink led not work good (because its making other task)... I find my project look just as this device that has many led but every led is independent of what makes the processor and not see the change task. (at least for human eye) |
|
|
40inD
Joined: 30 Jul 2007 Posts: 112 Location: Moscow, Russia
|
|
Posted: Thu Jun 09, 2016 12:23 am |
|
|
how much leds?
i think you should use external pwm controllers with several independent outputs with some serial interface. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19537
|
|
Posted: Thu Jun 09, 2016 1:09 am |
|
|
Lets get something straight. You can't 'blink' an LED with PWM. PWM is much too fast. You can dim an LED with PWM, but not make it blink.
You can potentially blink it with an RTOS, but you then have to understand that the RTOS is _co-operative_. It only works if every function always makes sure that it gets out quickly, and never 'waits' for anything (co-operates...). It is exactly like the multi-tasking in old W95, where if a task hung or delayed too much, then the other tasks would not get serviced. This is the complexity of writing tasks for the RTOS. If (for instance), one needs to wait for a keyboard,then it has to be written, so it simply checks the keyboard, and if nothing is ready, immediately exits. Similarly if there is some complex calculation, then this may need to be split into smaller pieces, and just one part done at each pass. If your RTOS speed is changing when you are doing things, then it implies that one or more of your functions is not properly written.
That being said, probably the only way to do what you want is to use a separate timer interrupt, and have this have counters for the LED's and turn them on/off based on the values of these. Not PWM.... |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Thu Jun 09, 2016 6:10 am |
|
|
If you run the PIC with an external R-C oscillator at about 750hz - you can use PWM - but you can't do anything useful with the "free cycles"..... |
|
|
cvargcal
Joined: 17 Feb 2015 Posts: 134
|
|
Posted: Thu Jun 09, 2016 8:00 am |
|
|
Ttelmah wrote: | Lets get something straight. You can't 'blink' an LED with PWM. PWM is much too fast. You can dim an LED with PWM, but not make it blink.
You can potentially blink it with an RTOS, but you then have to understand that the RTOS is _co-operative_. It only works if every function always makes sure that it gets out quickly, and never 'waits' for anything (co-operates...). It is exactly like the multi-tasking in old W95, where if a task hung or delayed too much, then the other tasks would not get serviced. This is the complexity of writing tasks for the RTOS. If (for instance), one needs to wait for a keyboard,then it has to be written, so it simply checks the keyboard, and if nothing is ready, immediately exits. Similarly if there is some complex calculation, then this may need to be split into smaller pieces, and just one part done at each pass. If your RTOS speed is changing when you are doing things, then it implies that one or more of your functions is not properly written.
That being said, probably the only way to do what you want is to use a separate timer interrupt, and have this have counters for the LED's and turn them on/off based on the values of these. Not PWM.... |
Thank you so much, Now I undertand more a little about RTOS.
and what happen if the task take many timer? for example.
Code: |
#use rtos(timer=0,minor_cycle=100ms) // ConfiguraciĆ³n del RTOS
//***** task#: Get GPS *************
#task(rate=900ms,max=100ms)
//***** task#:read CMD ***
#task(rate=800ms,max=10ms)
//***** task#: alert in *****
#task(rate=700ms,max=10ms)
//***** task#: config GPRS ****
#task(rate=600ms,max=100ms)
//***** task#: Report TCP***********
#task(rate=200ms,max=10ms)
//***** taks#: PWM ****************
#task(rate=100ms,max=100ms) |
for example what happen if the task GPRS take 10 seg?
my program work good with this configuration, but I want know more about RTOS
in task PWM I wanted put the blink led, actually I am using this line blink_led(PIN,33,600 ); in the task. |
|
|
|
|
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
|