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

18F4550 can't reach 50khz pwm

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



Joined: 29 Feb 2020
Posts: 1

View user's profile Send private message

18F4550 can't reach 50khz pwm
PostPosted: Sat Feb 29, 2020 1:02 pm     Reply with quote

Hello,

I am new to pic and have a problem with getting 50khz pwm. When i set values to 50khz which is setup_timer_2(T2_DIV_BY_1, 9, 1) in 2mhz oscillator frequency,
proteus cant show on oscillator.
Then I am trying to increase oscillator frequency to get 16khz.
When I try to increase it gives me errors like option invalid Internal Osc Freq Wrong and Undefiened identifier OSC_16MHZ.
What values do I set to get a 50khz pwm ?

CCS C version:5.015




Code:
#include <18F4550.h>
#device ADC = 10
#fuses NOMCLR INTRC_IO
#use delay(clock = 16M)

unsigned long int deger;
void main(){
   setup_psp(PSP_DISABLED);
   setup_timer_1(T1_DISABLED);
   setup_CCP2(CCP_OFF);
   
  setup_oscillator(OSC_16MHZ);         
  setup_adc(ADC_CLOCK_DIV_8);           
  setup_adc_ports(ALL_ANALOG); 
  set_adc_channel (12);
                   
  setup_timer_2(T2_DIV_BY_1, 255, 1);
  setup_ccp1(CCP_PWM);
  delay_ms(100);   
 
  set_tris_b(0x01);
  set_tris_c(0x00);
  while(1){
   
                                         
    deger = read_adc();                     
    set_pwm1_duty(deger);                   
    delay_ms(1);                         
   }
}
Ttelmah



Joined: 11 Mar 2010
Posts: 19375

View user's profile Send private message

PostPosted: Sat Feb 29, 2020 1:11 pm     Reply with quote

This is a read the data sheet one. The 18F4550, does not have a 16MHz
internal oscillator. Just 8MHz.

You can generate a 50KHz PWM from 8MHz:

setup_timer_2(T2_DIV_BY_1, 39, 1;

Will give 50KHz.

The settying you show:

setup_timer_2(T2_DIV_BY_1, 9, 1);

Will give 50kHz from 2MHz.

Your duty cycle value is allowed to go to the PR2 value ((the 9 or 39) +1) *4. No more.
temtronic



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

View user's profile Send private message

PostPosted: Sat Feb 29, 2020 2:26 pm     Reply with quote

also..
if you ever decide to use the PIC in the 'real World', be SURE to read which clock configurations work with the internal USB peripheral !!!!
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