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

PWM function on PIC12F683

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



Joined: 04 May 2008
Posts: 260

View user's profile Send private message

PWM function on PIC12F683
PostPosted: Sat Jul 19, 2014 12:45 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Jul 19, 2014 1:57 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Jul 19, 2014 3:46 pm     Reply with quote

http://www.ccsinfo.com/forum/viewtopic.php?t=50069

Many more in addition to this. Use search.
_________________
Google and Forum Search are some of your best tools!!!!
filjoa



Joined: 04 May 2008
Posts: 260

View user's profile Send private message

PostPosted: Sat Jul 19, 2014 7:34 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Jul 19, 2014 7:44 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Jul 20, 2014 12:13 am     Reply with quote

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