View previous topic :: View next topic |
Author |
Message |
andys
Joined: 23 Oct 2006 Posts: 175
|
|
|
andys
Joined: 23 Oct 2006 Posts: 175
|
pwm problem |
Posted: Sun Apr 28, 2013 12:25 pm |
|
|
Anyone can give me any suggestions ? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19510
|
|
Posted: Sun Apr 28, 2013 1:28 pm |
|
|
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
|
pwm problem |
Posted: Sun Apr 28, 2013 5:32 pm |
|
|
I use dspic33fj128MC802 microcontroller.
For a 16 bits PWM what is the appropriate compiler version? |
|
|
andys
Joined: 23 Oct 2006 Posts: 175
|
pwm problem |
Posted: Mon Apr 29, 2013 1:11 am |
|
|
There isn't anyone who know what is the right compiler for 16 bits pic ??? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19510
|
|
Posted: Mon Apr 29, 2013 1:41 am |
|
|
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
|
pwm problem |
Posted: Tue Apr 30, 2013 2:42 am |
|
|
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
|
|
Posted: Tue Apr 30, 2013 3:11 am |
|
|
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
|
pwm problem |
Posted: Tue Apr 30, 2013 12:52 pm |
|
|
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
|
|
Posted: Tue Apr 30, 2013 2:29 pm |
|
|
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
|
pwm problem |
Posted: Tue Apr 30, 2013 5:04 pm |
|
|
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
|
|
Posted: Wed May 01, 2013 2:47 am |
|
|
Er. The line from the manual I posted....
"x is 1-8 and specifies which OC pin to use. "
OC1 = 1, OC2 = 2 etc.. |
|
|
|