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 not working

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



Joined: 05 Apr 2022
Posts: 21

View user's profile Send private message

PWM not working
PostPosted: Thu May 26, 2022 8:27 am     Reply with quote

Hello to everyone
use the compiler.5.007
PIC16f1509
I want to get different tones of buzzer with pwm. But I couldn't get it to work. Please help.
Code:

int16 Duty=255;

setup_timer_2(T2_DIV_BY_16,255,1);  //4,0 ms overflow, 4,0 ms interrupt

 //   setup_ccp1(CCP_PWM);   // undefined identifier .. setup_ccp1
   
     setup_pwm1(pin_c5);
 //   set_pwm1_duty(0);


while(true)
  {
   set_pwm1_duty(Duty);
  }

Since I don't know which one is more suitable for me, I tried a different method but it didn't work either.
Code:

#use PWM(OUTPUT=PIN_C5, FREQUENCY=32kHz, DUTY=50, STREAM=CH_1)

while(true)
  {
   pwm_on();
   delay_us(100);
   pwm_off();
   delay_us(100);
  }

PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: PWM not working
PostPosted: Thu May 26, 2022 12:13 pm     Reply with quote

Delfinss wrote:

// setup_ccp1(CCP_PWM); // undefined identifier .. setup_ccp1

Look at the 16F1509.h file. It doesn't list a setup_ccp1() function.
It lists:

setup_pwm1()
set_pwm1_duty()

This post has sample pwm code for the 16F15x series:
http://www.ccsinfo.com/forum/viewtopic.php?t=48643&start=6
Ttelmah



Joined: 11 Mar 2010
Posts: 19550

View user's profile Send private message

PostPosted: Fri May 27, 2022 12:32 am     Reply with quote

and, the 'reason' is that this chip does not have the CCP peripheral.
Instead it has a separate PWM module, whose setup is slightly different
from the normal CCP PWM.
If you open the device's 'header' file, and simply search for PWM, you
will find a nice section listing the functions (which PCM has given), and
if you then look at the manual for those functions you will get clues to how
to set these up - suspect this was what PCM_Programmer actually did
before the post he is pointing you to... Very Happy
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri May 27, 2022 10:18 am     Reply with quote

Yes, that is what I did.
Ttelmah



Joined: 11 Mar 2010
Posts: 19550

View user's profile Send private message

PostPosted: Sun May 29, 2022 6:32 am     Reply with quote

I think that is the way all of the more experienced programmers would
approach this.
temtronic



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

View user's profile Send private message

PostPosted: Sun May 29, 2022 7:00 am     Reply with quote

Since the Internet kinda did away with paper books and manuals, and allowed everyone to 'cut/paste/copy' programs, I'm betting most have never opened the device.header file, let alone read the 700+ pages a typical PIC datasheet now has.
I'm still 'impressed and confused' that newer PICs have more FUSES than actual Instructions !
I used to be pretty good at ASM ( preCCS ) but think that no one does that anymore.
Kinda miss papertape too......
sigh..
just turned 69 this week....
double sigh

Jay
Delfinss



Joined: 05 Apr 2022
Posts: 21

View user's profile Send private message

PWM not working
PostPosted: Tue May 31, 2022 8:25 am     Reply with quote

i'm a bit of a beginner
I take your warnings into account.
Happy new year temtronic
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