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 support@ccsinfo.com

PWM not work on 12f683

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



Joined: 17 Jul 2010
Posts: 3

View user's profile Send private message

PWM not work on 12f683
PostPosted: Sat Jul 17, 2010 3:33 am     Reply with quote

Hi I wrote this code to generate a frequency of 1MHz with a 12f683 using an external 20MHz quartz ... why not working? here's the code:
Code:
#include <12F683.h>
#device adc=8

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES HS                       //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES NOCPD                    //No EE protection
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOMCLR                   //Master Clear pin used for I/O
#FUSES NOPUT                    //No Power Up Timer
#FUSES NOBROWNOUT               //No brownout reset
#FUSES IESO                     //Internal External Switch Over mode enabled
#FUSES FCMEN                    //Fail-safe clock monitor enabled

#use delay(clock=20000000)


void main()
{

   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_CLOCK_DIV_2);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DIV_BY_1,3,1);
   setup_ccp1(CCP_PWM);
   set_pwm1_duty(0);
   setup_comparator(NC_NC);
   setup_vref(FALSE);

while (1)
   {
            delay_cycles(1);
   }

}


Last edited by Antony77 on Sat Jul 17, 2010 6:24 am; edited 1 time in total
Ttelmah



Joined: 11 Mar 2010
Posts: 19254

View user's profile Send private message

PostPosted: Sat Jul 17, 2010 6:18 am     Reply with quote

setup_timer_2(T2_DIV_BY_1,4,1); //Gives clock/(4*5)
Set_pwm1_duty(10L); //Need the 'L' to give 10 counts of the master clock


At the moment, you have no 'on' period, so no output....
Antony77



Joined: 17 Jul 2010
Posts: 3

View user's profile Send private message

PostPosted: Sat Jul 17, 2010 6:21 am     Reply with quote

Oh I forgot to set the duty at 50%...What value should I use for 50%?
Why L? and why "setup_timer_2(T2_DIV_BY_1,4,1); //Gives clock/(4*5)" ?
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