View previous topic :: View next topic |
Author |
Message |
Delfinss
Joined: 05 Apr 2022 Posts: 21
|
PWM not working |
Posted: Thu May 26, 2022 8:27 am |
|
|
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
|
Re: PWM not working |
Posted: Thu May 26, 2022 12:13 pm |
|
|
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
|
|
Posted: Fri May 27, 2022 12:32 am |
|
|
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... |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri May 27, 2022 10:18 am |
|
|
Yes, that is what I did. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19550
|
|
Posted: Sun May 29, 2022 6:32 am |
|
|
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
|
|
Posted: Sun May 29, 2022 7:00 am |
|
|
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
|
PWM not working |
Posted: Tue May 31, 2022 8:25 am |
|
|
i'm a bit of a beginner
I take your warnings into account.
Happy new year temtronic |
|
|
|