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 in PIC12F615

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



Joined: 30 Jan 2008
Posts: 197

View user's profile Send private message

PWM in PIC12F615
PostPosted: Fri Nov 22, 2019 6:50 pm     Reply with quote

Hi, I am trying to implement a PWM in a pic12F615, with a frequency of 1Khz, but I am not able to obtain the PWM correctly. The duty cycle of the wave does not vary from 1 to 100% and oscillates. I can only several up to 15% of the duty cycle.


But if I use the same code in a pic16f887 if it works correctly!!

Here is my code:
Code:
#include <12F615.h>
#device ADC=10
#fuses INTRC_IO, NOWDT, PROTECT,NOPUT 
#use delay(clock=4MHz)

int16 duty=0;
int Timer2=249;
int Poscaler=1; 
 
void main() {
 
   setup_timer_2(t2_div_by_4,Timer2,Poscaler);  //Configuracion de Timer 2 para establecer frec. PWM a 1kHz
   setup_ccp1(ccp_pwm);  //Configurar modulo CCP1 en modo PWM

   setup_adc_ports(all_analog);  //Configurar ADC
   setup_adc(adc_clock_internal);
   set_adc_channel(0);

   while(TRUE)  {
 
        delay_us(100);       
        duty=read_adc();
        set_pwm1_duty(duty);
   }
}


Some of you can tell me what is my mistake?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Nov 22, 2019 9:43 pm     Reply with quote

The loop delay is too short. I assume you're turning a trimpot with your
hand. Change it to 100 ms.
Quote:

while(TRUE) {

delay_us(100);
duty=read_adc();
set_pwm1_duty(duty);
}
temtronic



Joined: 01 Jul 2010
Posts: 9243
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Nov 23, 2019 5:21 am     Reply with quote

also...
this..
Quote:
setup_adc(adc_clock_internal);
is wrong.
With a clock speed of 4MHz, Fosc/8 or Fosc/16 are valid. 'Internal' is for very slow PICs, sleeping.
Check datasheet, Chapter 9, Table 9-1, page 69 for 'how and why'.

I assume some 'Wizard' helped you ?

Jay
pilar



Joined: 30 Jan 2008
Posts: 197

View user's profile Send private message

PostPosted: Sat Nov 23, 2019 7:18 am     Reply with quote

Hi, PCM programmer and temtronic, that was it, thank you for your help.
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