View previous topic :: View next topic |
Author |
Message |
kda406
Joined: 17 Sep 2003 Posts: 97 Location: Atlanta, GA, USA
|
Odd Error: PWM output pin @0 already used for PWM1 [SOLVED] |
Posted: Tue Dec 04, 2018 1:48 pm |
|
|
Hi, I'm working with a PIC18F67K40 which uses PPS pins and I'm compiling with V5.078.
For this project I thought I'd try the #use pwm" functions along with pwm_set_duty_percent() for the first time. But there is an error I do not understand. The header has this:
Code: | ///// Variable Speed Fan /////
#pin_select CCP4OUT=PIN_G3
#use pwm(CCP4, TIMER=2, FREQUENCY=100, DUTY=50, STREAM=PWM_FAN)
///// Variable Speed Pump /////
#pin_select CCP5OUT=PIN_G4
#use pwm(CCP5, TIMER=5, FREQUENCY=100, DUTY=50, STREAM=PWM_PUMP) |
When I try to compile, I get the error:
Quote: | Error#99 Option invalid PWM output pin @0 already used for PWM1 |
This error points to the second #use line in the header file. I have selected two different pins, two different CCP ports, and two different timers. Any suggestions on what I have setup incorrectly here?
Thanks,
Kyle
Last edited by kda406 on Thu Dec 06, 2018 10:37 am; edited 5 times in total |
|
|
kda406
Joined: 17 Sep 2003 Posts: 97 Location: Atlanta, GA, USA
|
|
Posted: Tue Dec 04, 2018 2:02 pm |
|
|
I discovered a minor typo. The second #use pwm line should be timer 6, not timer 5.
Code: | #use pwm(CCP5, TIMER=6, FREQUENCY=100, DUTY=50, STREAM=PWM_PUMP) |
However, after fixing that, I still have the same error as the original post. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19549
|
|
Posted: Tue Dec 04, 2018 2:12 pm |
|
|
Look at page 229 in the data sheet.
On this chip, PPS doesn't have a 'free hand' to remap peripherals. CCP1 &
CCP2 can only be mapped to ports C & E. |
|
|
gaugeguy
Joined: 05 Apr 2011 Posts: 303
|
|
Posted: Tue Dec 04, 2018 2:21 pm |
|
|
I wonder if it might be an error to bring up with CCS. CCP4 & CCP5 can be mapped to ports E and G and the default for CCP4 is RG3 and for CCP5 is RG4 |
|
|
kda406
Joined: 17 Sep 2003 Posts: 97 Location: Atlanta, GA, USA
|
|
Posted: Tue Dec 04, 2018 2:22 pm |
|
|
I'm using CCP4 & CCP5 which are on on ports E & G. I've called out port G pins. |
|
|
dluu13
Joined: 28 Sep 2018 Posts: 395 Location: Toronto, ON
|
|
Posted: Tue Dec 04, 2018 2:31 pm |
|
|
What happens if you try to only turn on one CCP module at a time? |
|
|
kda406
Joined: 17 Sep 2003 Posts: 97 Location: Atlanta, GA, USA
|
|
Posted: Tue Dec 04, 2018 2:33 pm |
|
|
Great question! If I remark out either one, the other works - Build Successful. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19549
|
|
Posted: Tue Dec 04, 2018 2:40 pm |
|
|
I must admit it does sound like a compiler issue.
You could try setting up the PWM's not using #use, and using the 'inline' pin_select command, and see if this gets round the problem.
Though the compiler should combine all #PIN_SELECT lines into one set of settings, it is worth seeing if disabling the PPS1WAY fuse might affect things.
The 'heading', makes me think the compiler believes he is setting PWM1, and therefore complains about the port being used..... |
|
|
kda406
Joined: 17 Sep 2003 Posts: 97 Location: Atlanta, GA, USA
|
|
Posted: Wed Dec 05, 2018 11:00 am |
|
|
I already had PPS1WAY disabled. I upgraded to the latest (v5.081) and the problem persists. I will report the problem to CCS.
Thanks,
Kyle |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19549
|
|
Posted: Wed Dec 05, 2018 11:19 am |
|
|
It actually does it on the second #use PWM, even without a pin select at all.
I suspect it is a fault in the #use PWM. If I get time I was going to try setting
up the PWM without using the #use, and see if it still gives an issue. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19549
|
|
Posted: Wed Dec 05, 2018 2:55 pm |
|
|
Can confirm, it does build correctly, if you use the setup_timer, and setup_ccp, rather than #use PWM.
Obviously you don't get an automatic scaling to give 0-100 out, but the #PIN_SELECT's all work, and the PWM seems to setup right. On MPLAB sim, they both give outputs. |
|
|
kda406
Joined: 17 Sep 2003 Posts: 97 Location: Atlanta, GA, USA
|
|
Posted: Wed Dec 05, 2018 2:59 pm |
|
|
I can confirm that. Using the setup_ccpX() and setup_timer_X() method seems to compile and work.
I sent in the report to CCS about #use pwm, but have not heard back from them. |
|
|
kda406
Joined: 17 Sep 2003 Posts: 97 Location: Atlanta, GA, USA
|
|
Posted: Thu Dec 06, 2018 10:35 am |
|
|
CCS sent me a working solution. Code: | #use pwm(CCP4, output=PIN_G3, TIMER=2, FREQUENCY=100, DUTY=50, STREAM=PWM_FAN)
#use pwm(CCP5, output=PIN_G4, TIMER=6, FREQUENCY=100, DUTY=50, STREAM=PWM_PUMP) |
It compiles and seems to work for the two PWM outputs on the two PPS assigned CCP channels.
They were not very verbose, but it appears the originally posted code was correct, and they mentioned adding a fix in an upcoming release. For now, we can just use this very similar code.
Thanks for the help folks!!!!!
-Kyle |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19549
|
|
Posted: Thu Dec 06, 2018 2:16 pm |
|
|
Yes, it did look to be an internal issue with the command.
At least you are running now... |
|
|
|