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

Issue pwm_set_frequency() :(

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



Joined: 05 Feb 2009
Posts: 10

View user's profile Send private message

Issue pwm_set_frequency() :(
PostPosted: Thu Aug 01, 2013 7:42 am     Reply with quote

Hi friends
This program not work to any frequency, if use: pwm_set_frequency()???
Code:

#include <18f252.h>
#use delay(crystal= 20000000)
#fuses hs, nowdt,ccp2c1

#use pwm(ccp1,timer=2, output=pin_c2, frequency=10000)


void config_pwm(void)
{
   pwm_on();
   pwm_set_frequency(5000);        //here problem, not work :(
   pwm_set_duty_percent(700UL);
}

void main()
{
   config_pwm();
   
   
   while(true)
   {
      output_high(pin_b0);
      delay_ms(200);
      output_low(pin_b0);
      delay_ms(100);
   }
}


Any idea?
Thanks
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Aug 02, 2013 12:26 am     Reply with quote

I've been playing with it, based on your program, with vs. 5.010.
I have come to the conclusion that this function does not work:
Code:
pwm_set_frequency()

With a 20MHz crystal I always get 1.22 KHz for the frequency, no matter
what parameter I put into that function. You can set the frequency in the
original #use pwm() statement. That works. But you can't change it later
because pwm_set_frequency() is buggy.
Ttelmah



Joined: 11 Mar 2010
Posts: 19510

View user's profile Send private message

PostPosted: Fri Aug 02, 2013 12:42 am     Reply with quote

and (of course) remember that you can set the frequency using a setup_timer_2 line at any point, but you have to do the calculations...

It is always going to be a 'dubious' function, since the actual frequencies that can be achieved are limited, and changing this will alter the PWM resolution. Seems a case of the compiler trying to be a bit 'too smart'. Except possibly on chips with the 12bit PWM's, where more accurate frequencies are possible.

Best Wishes
Ralf2



Joined: 05 Feb 2009
Posts: 10

View user's profile Send private message

PostPosted: Fri Aug 02, 2013 6:17 am     Reply with quote

PCM programmer wrote:
I've been playing with it, based on your program, with vs. 5.010.
I have come to the conclusion that this function does not work:
Code:
pwm_set_frequency()

With a 20MHz crystal I always get 1.22 KHz for the frequency, no matter
what parameter I put into that function. You can set the frequency in the
original #use pwm() statement. That works. But you can't change it later
because pwm_set_frequency() is buggy.



With a 20MHz crystal I always get 1.22 KHz for the frequency, no matter
what parameter I put into that function. --> YES, so is Confused

You can set the frequency in the
original #use pwm() statement. That works. But you can't change it later
because pwm_set_frequency() is BUGGY. -->YES, so is Confused

Thanks PCM programmer, you're right

and (of course) remember that you can set the frequency using a setup_timer_2 line at any point, but you have to do the calculations...

So is Ttelmah, Thanks


Last edited by Ralf2 on Fri Aug 02, 2013 8:54 am; edited 3 times in total
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Fri Aug 02, 2013 6:25 am     Reply with quote

if you want arbitrary frequency, or one hz ( even fractional hz) resolution
then the NCO module of the 16f15xx parts
can't be beat.
it is very easy to adapt over a great range of Fosc
and many decades of 1 hz of resolution too
and gives terrific accuracy with a power of two crystal.

see:

http://www.ccsinfo.com/forum/viewtopic.php?t=50121
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