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

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



Joined: 23 Oct 2006
Posts: 175

View user's profile Send private message

pwm problem
PostPosted: Sat Apr 27, 2013 9:43 pm     Reply with quote

I tried to create a simple pwm code for a 16 bits pic.

When i compile it, at the lines:
Code:

set_compare_time(1, 0xF000);
setup_compare(1, COMPARE_SET_ON_MATCH | COMPARE_TIMER2);

i get the error :
Invalid parameters to built in function :: Invalid Pin

i also tries the solution at
http://www.ccsinfo.com/forum/viewtopic.php?t=50113&highlight=setupcompare++comparesetonmatch+comparetimer2

but without success.
I use PCD V4.093 compiler.

Is anyone who know how to fix it ?
andys



Joined: 23 Oct 2006
Posts: 175

View user's profile Send private message

pwm problem
PostPosted: Sun Apr 28, 2013 12:25 pm     Reply with quote

Anyone can give me any suggestions ?
Ttelmah



Joined: 11 Mar 2010
Posts: 19510

View user's profile Send private message

PostPosted: Sun Apr 28, 2013 1:28 pm     Reply with quote

What PIC?.
Seriously, 4.093, is early for working with these PIC's.
I'd suspect the error is that your chip has relocatable pins, in which case you need to use #PIN SELECT to setup the pin involved.

Best Wishes
andys



Joined: 23 Oct 2006
Posts: 175

View user's profile Send private message

pwm problem
PostPosted: Sun Apr 28, 2013 5:32 pm     Reply with quote

I use dspic33fj128MC802 microcontroller.

For a 16 bits PWM what is the appropriate compiler version?
andys



Joined: 23 Oct 2006
Posts: 175

View user's profile Send private message

pwm problem
PostPosted: Mon Apr 29, 2013 1:11 am     Reply with quote

There isn't anyone who know what is the right compiler for 16 bits pic ???
Ttelmah



Joined: 11 Mar 2010
Posts: 19510

View user's profile Send private message

PostPosted: Mon Apr 29, 2013 1:41 am     Reply with quote

The point is that V4, as a compiler, didn't even start to work properly till about 4.070. Getting parts like these more complex chips working 'evolved' over the next fifty or more compiler versions, and there are still some problems, but getting less. You need to be in the high 4.12x versions to have hope of 99% of things working. With your compiler, expect to have some significant problems with quite a few of the peripherals.

However I'd refer you to my original comment. The output compare module on this chip, does use relocatable pins, so you need to tell the compiler what pin to use before you can use the module #PIN_SELECT. Correct this, and it may well work. With this corrected, it does compile on 4.099 (closest I have), but a couple of the register values are set incorrectly.

You also talk about wanting a PWM, but the code you post is to just set the output on match. To setup the PWM, you'd want to use COMPARE_PWM, rather than COMPARE_SET_ON_MATCH.

Best Wishes
andys



Joined: 23 Oct 2006
Posts: 175

View user's profile Send private message

pwm problem
PostPosted: Tue Apr 30, 2013 2:42 am     Reply with quote

Ttelmah ,
I tried your suggestions (to use #PIN_SELECT for the pin) the changesess which i did are :


Code:

#PIN_SELECT OC1=PIN_B4
setup_compare(OC1, COMPARE_PWM | COMPARE_TIMER2);
set_pwm_duty(OC1,value * (int16)64);


But i receive the message :
Undefined identifier OC1

Have you got any other suggestions ??????
Ttelmah



Joined: 11 Mar 2010
Posts: 19510

View user's profile Send private message

PostPosted: Tue Apr 30, 2013 3:11 am     Reply with quote

You don't use OC1, in the setup compare....

OC1 is the pin name, not the channel number. I bet it is the setup_compare complaining, since it won't know anything about OC1.

Best Wishes
andys



Joined: 23 Oct 2006
Posts: 175

View user's profile Send private message

pwm problem
PostPosted: Tue Apr 30, 2013 12:52 pm     Reply with quote

Dear Ttelmah,

I try the following :
Code:

#PIN_SELECT OC1=PIN_B4
setup_compare(PIN_B4, COMPARE_PWM | COMPARE_TIMER2);
set_pwm_duty(PIN_B4,value * (int16)64);


and is compiling. (I will check later with the hardware if is working ok because i don't have the hardware with me)

But actually i really confuse.

If i use only :

setup_compare(PIN_B4, COMPARE_PWM | COMPARE_TIMER2);
set_pwm_duty(PIN_B4,value * (int16)64);

with out the #PIN_SELECT OC1=PIN_B4

i receive the error : Invalid Pin
but if i use the #PIN_SELECT OC1=PIN_B4 is compiling. I don't understand why.
Can you explain it to me ?
Ttelmah



Joined: 11 Mar 2010
Posts: 19510

View user's profile Send private message

PostPosted: Tue Apr 30, 2013 2:29 pm     Reply with quote

Have you actually tried reading the manual?....
Code:

Syntax:
  setup_compare(x, mode)
Parameters:
  mode is defined by the constants in the devices .h file
  x is 1-8 and specifies which OC pin to use.

Note, 1 to 8. Just a number. For OC1, you use 1.
You had this part right. All you needed to do was add the pin select. Instead of just doing this, you have whizzed off, and started adding garbage....
Same applies to the duty function.

PIN_B4 gets accepted, because it is just a define for a number. However it is the wrong number.
Code:

#PIN_SELECT OC1=PIN_B4

    setup_compare(1, COMPARE_PWM | COMPARE_TIMER2);
andys



Joined: 23 Oct 2006
Posts: 175

View user's profile Send private message

pwm problem
PostPosted: Tue Apr 30, 2013 5:04 pm     Reply with quote

Ttelmah thanks . the code now is working but you said

"Note, 1 to 8. Just a number. For OC1, you use 1. "

Where did you find this ????
I search at the manual and also at the header of the device but i didn't find it!
Ttelmah



Joined: 11 Mar 2010
Posts: 19510

View user's profile Send private message

PostPosted: Wed May 01, 2013 2:47 am     Reply with quote

Er. The line from the manual I posted....

"x is 1-8 and specifies which OC pin to use. "

OC1 = 1, OC2 = 2 etc..
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