View previous topic :: View next topic |
Author |
Message |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Jul 13, 2012 1:37 pm |
|
|
I don't have a 16F1503, but I have a 16F1507 and it's in the same PIC
family. I installed compiler vs. 4.133 and ran the following test program.
It works. The PIC outputs a pwm signal on pin C5, with a frequency of
4.0 KHz and a 50% duty cycle. Try this program and see if it works with
your PIC:
Code: |
#include <16F1507.H>
#fuses INTRC_IO, NOWDT, BROWNOUT, PUT, NOLVP
#use delay(clock=4M)
//=========================================
void main()
{
setup_pwm1(PWM_ENABLED | PWM_OUTPUT | PWM_ACTIVE_HIGH);
setup_timer_2(T2_DIV_BY_1, 249, 1);
set_pwm1_duty(500L);
while(1);
} |
|
|
|
castek
Joined: 12 Jul 2012 Posts: 14
|
|
Posted: Mon Jul 16, 2012 5:53 am |
|
|
It works!!!
Thanks a lot
CCS is GREAT |
|
|
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Mon Jul 16, 2012 8:01 am |
|
|
Hi,
Hmmm, the compiler was already capable of doing what you wanted, so
while CCS may indeed be great, in this case, I think the real praise should
go to the forum members that helped you, and in particular, to PCM
programmer!
John |
|
|
twidget
Joined: 21 Feb 2013 Posts: 32 Location: Orange County, California
|
|
Posted: Wed Mar 06, 2013 12:53 am |
|
|
Well I will say Thank you, I am working on a project with PIC16F1509 and the PWM was killing me! This thread helps a lot! Thank you PCM programmer. |
|
|
mrcdcscc
Joined: 02 Dec 2013 Posts: 1
|
|
Posted: Mon Dec 02, 2013 2:06 pm |
|
|
Dear PCM programmer,
God bless you! I was suffered by PWM on PIC16F1503 and your code helped me. Thank you very much for your code snippet.
I have one question: what does the letter L means beside the number 500 in the command set_pwm1_duty(500L) ? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19515
|
|
Posted: Mon Dec 02, 2013 3:38 pm |
|
|
Standard C....
'Long'. Not actually needed here (since '500' is automatically a 'long'), but the point is that if you changed the PWM value, and started to use values that could be a short (like 200), adding the 'L' makes sure the compiler will keep treating them as 'long'. CCS will by default 'switch operation' and treat a 'short' value fed to the PWM, as if it is 4* the size.....
A search here will find about this.
Best Wishes |
|
|
edi
Joined: 22 Dec 2003 Posts: 82
|
16F1938 PWM |
Posted: Thu Dec 26, 2013 3:08 pm |
|
|
I tried this code:
Quote: |
setup_ccp2(CCP_PWM | CCP_P2B_C0 | CCP_PWM_L_H);
setup_timer_2(T2_DIV_BY_16, 249, 1);
set_pwm2_duty(500L);
|
and expect to get the PWM on pin RC0
actually it goes out on pin RC1
Any idea? is it a compiler bug as I used "CCP_P2B_C0" ?
Compiler ver 4.140 |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19515
|
|
Posted: Thu Dec 26, 2013 3:20 pm |
|
|
Read the data sheet.....
Look at table 1.
What pins can CCP2 be routed to?. The name in the setup is confusing (with the '0'), but the signal can only route to B3, or C1...
Best Wishes |
|
|
edi
Joined: 22 Dec 2003 Posts: 82
|
|
Posted: Thu Dec 26, 2013 4:05 pm |
|
|
Thanks.
I looked in table 12-7 and it misleading...why it says CCP2/P2B RC0? |
|
|
|