View previous topic :: View next topic |
Author |
Message |
filjoa
Joined: 04 May 2008 Posts: 260
|
PWM function on PIC12F683 |
Posted: Sat Jul 19, 2014 12:45 pm |
|
|
Hi
Is possible make an PWM function manually to this PIC?
I need control 4LEDs in diferent sequences.
Now I stay use INTERRUPTs to select button.
Code: |
#include <12F683.h>
#FUSES NOWDT, INTRC_IO, NOCPD, NOPROTECT, NOMCLR, PUT, NOBROWNOUT, NOIESO, NOFCMEN
#use delay(clock=8000000)
#define LED1 PIN_A0
#define LED2 PIN_A1
#define LED3 PIN_A4
#define LED4 PIN_A5
// ### GLOBALS
int8 seq = 1;
#int_ra
void int_isr(void)
{
seq++;
delay_ms(100);
if (seq>4)
{
seq=1;
}
}
void seq1 (void)
{
output_high(LED1);
delay_ms(1000);
output_high(LED2);
delay_ms(1000);
output_high(LED3);
delay_ms(1000);
output_high(LED4);
delay_ms(1000);
output_low(LED1);
delay_ms(1000);
output_low(LED2);
delay_ms(1000);
output_low(LED3);
delay_ms(1000);
output_low(LED4);
delay_ms(1000);
}
void seq2 (void)
{
output_high(LED1);
delay_ms(1000);
output_high(LED2);
delay_ms(1000);
output_high(LED3);
delay_ms(1000);
output_high(LED4);
delay_ms(1000);
output_low(LED4);
delay_ms(1000);
output_low(LED3);
delay_ms(1000);
output_low(LED2);
delay_ms(1000);
output_low(LED1);
delay_ms(1000);
}
void seq3 (void)
{
output_high(LED1);
output_high(LED4);
delay_ms(1000);
output_high(LED2);
output_high(LED3);
delay_ms(1000);
output_low(LED1);
output_low(LED4);
delay_ms(1000);
output_low(LED2);
output_low(LED3);
delay_ms(1000);
}
void seq4 (void)
{
// ######### PWM FUNCTION #########
}
void main()
{
enable_interrupts(GLOBAL);
enable_interrupts(INT_RA2);
while(TRUE)
{
if (seq==1) seq1();
if (seq==2) seq2();
if (seq==3) seq3();
if (seq==4) seq4();
}
}
|
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Sat Jul 19, 2014 1:57 pm |
|
|
yes, you can easily get 4 LEDs to be controlled by PWM using 'manual' means. If you search this forum, there's probably code here or in the 'code library'. Use LED PWM in the search and select 'all terms' to help narrow down the results.
hth
jay |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
|
|
filjoa
Joined: 04 May 2008 Posts: 260
|
|
Posted: Sat Jul 19, 2014 7:34 pm |
|
|
Hi
thanks... I try make search but without success...
when I refer "manual" is, make an PWM only with software, some function or library where I can control duty cycle of the wave on I/O pin. In my case PIN_A0, PIN_A1, PIN_A4, PIN_A5, because in PIN_A2 I have my button.
some idea?
best regards |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
|
Posted: Sat Jul 19, 2014 7:44 pm |
|
|
You apparently didn't look at the link I provided.
S/W PM is exactly what they were doing for 4 PWM channels.
The title even says Software PWM!
You have to study the code. I don't think anyone here
is going to do the learning for you.
There are at least 8 other items I found using search
with the words "software PWM" _________________ Google and Forum Search are some of your best tools!!!! |
|
|
nailuy
Joined: 21 Sep 2010 Posts: 159
|
|
Posted: Sun Jul 20, 2014 12:13 am |
|
|
You are begin a beginning, you have no idea how to build a program,
"delay" you can't use this for pwm, cpu is blocking in this words.
Try something else as 4-quadrant electric engine and performs a function in Excel or Libre Office Calc turning points ever made in graphic overlay 4 functions offset by 90 degrees and ready for the controller program.
Also use lower or max 8 bits, 5 is okay for eye can be tricked, you can use lower OSC for 5 instead of 16 or 32 bits.
Don't forget because you make "manually" you need 2 programs to run simultaneously on single core. One 4 LEDs illuminate and second generates variables for PWM and third program for button.
You can loose time with function "delay".
If these ideas are fine for you get it to work, if not try to find on this forum more ideas and lose in their worlds.
Sometimes to create is more easy, then to copy others. Nailuy. |
|
|
|