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 problem with pic16F1503

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



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jul 13, 2012 1:37 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Jul 16, 2012 5:53 am     Reply with quote

It works!!!

Thanks a lot Very Happy
CCS is GREAT
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Mon Jul 16, 2012 8:01 am     Reply with quote

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

View user's profile Send private message Visit poster's website

PostPosted: Wed Mar 06, 2013 12:53 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Dec 02, 2013 2:06 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Dec 02, 2013 3:38 pm     Reply with quote

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

View user's profile Send private message

16F1938 PWM
PostPosted: Thu Dec 26, 2013 3:08 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Dec 26, 2013 3:20 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Dec 26, 2013 4:05 pm     Reply with quote

Thanks.
I looked in table 12-7 and it misleading...why it says CCP2/P2B RC0?
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