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
castek



Joined: 12 Jul 2012
Posts: 14

View user's profile Send private message

PWM problem with pic16F1503
PostPosted: Fri Jul 13, 2012 6:38 am     Reply with quote

Hello everyone!

I'm trying to setup pwm1 on pic16F1503 but I don't have success.

I try to setup_ccp1(CCP_PWM) as I saw in forums, but compiler does not recognize that function. It seems way to do it has changed:

I saw inside pic16f1503.h file functions for pwm are
Code:

////////////////////////////////////////////////////////////////// PWM
// PWM Functions: SETUP_PWMx, SET_PWMx_DUTY
// Constants used for SETUP_PWMx() are:
#define PWM_ENABLED      0x80
#define PWM_DISABLED     0
#define PWM_OUTPUT       0x40
#define PWM_ACTIVE_LOW   0x10
#define PWM_ACTIVE_HIGH  0

#bit PWM1OUT=getenv("BIT:PWM1OUT")
#bit PWM2OUT=getenv("BIT:PWM2OUT")
#bit PWM3OUT=getenv("BIT:PWM3OUT")
#bit PWM4OUT=getenv("BIT:PWM4OUT")

But I dont know how to use this....

Can anyone help me??
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Fri Jul 13, 2012 6:55 am     Reply with quote

for your PIC

SETUP_PWMx() is the right function as you saw on the .h File.

and the constants you can use are:

PWM_ENABLED
PWM_DISABLED
PWM_OUTPUT
PWM_ACTIVE_LOW
PWM_ACTIVE_HIGH
.
.
.

soooo... you can do things like: SETUP_PWMx(PWM_ENABLED);


Same as "setup_ccp1(CCP_PWM)" but with the appropiate names for your PIC.

What is your compiler version?
_________________
CCS PCM 5.078 & CCS PCH 5.093
asmboy



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

View user's profile Send private message AIM Address

PostPosted: Fri Jul 13, 2012 10:51 am     Reply with quote

solid support - even on 4.134 for 16f15xx still has a way to go.

unless you need some other unique feature of that chip
an older pic may be a better choice.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jul 13, 2012 10:56 am     Reply with quote

Quote:
but compiler does not recognize that function.

Always post your compiler version. The amount of support for a new PIC
is dependent upon the compiler version.
castek



Joined: 12 Jul 2012
Posts: 14

View user's profile Send private message

PostPosted: Fri Jul 13, 2012 11:39 am     Reply with quote

Thanks for you help!!!

My compiler version is 4.133.

I like new pics because they are cheap and more powerful than older ones.

Are there anyway to run pwm on my new pic16F1503??

Which code have I got to use???

Best Rgds.
asmboy



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

View user's profile Send private message AIM Address

PostPosted: Fri Jul 13, 2012 11:56 am     Reply with quote

I would become familiar with these registers in section 22 of the data sheet:

Quote:

• PR2
• T2CON
• PWMxDCH
• PWMxDCL
• PWMxCON


as in, #DEFINE them, and a also a few significant bits ( #BIT )
and then direct manipulate those registers to get PWM functions.

That hinges on any FUSES you need being set correctly by the compiler too.

That is another whole can of wiggly worms if you are not used to doing such.
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: 19546

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: 19546

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