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

Redirecting CCP2 PWM to altenate pin on 18F6310

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



Joined: 03 Feb 2006
Posts: 13
Location: Minnesota

View user's profile Send private message

Redirecting CCP2 PWM to altenate pin on 18F6310
PostPosted: Sun Oct 29, 2006 9:38 am     Reply with quote

RC1 is the default pin for CCP2 and RE7 is the alternate pin. I can get the desired PWM signal to come out on RC1 but when attempting to redirect to RE7, it stops on RC1 (as expected) but never shows up on RE7.

The only code change I'm making to redirect the output is adding the "#fuses CCP2E7" directive. I've verified the Configuration Bits are being set properly.

In the Configuration Bits panel in MPLAB v7.30, the two options for CCP2 MUX are "RC1" and "RE7 in microcontroller mode". With this part being a 64-pin device, my understanding is that it is always in microcontroller mode. This is just a curious observation.

TRISE is configured for RE7 as an output. I can toggle it by writing to it directly.

Any ideas where to look next?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Oct 29, 2006 8:59 pm     Reply with quote

Post your version of the compiler. You can find this at the top of the .LST
file, which will be in your project directory.
FISH6942



Joined: 03 Feb 2006
Posts: 13
Location: Minnesota

View user's profile Send private message

PostPosted: Mon Oct 30, 2006 8:54 am     Reply with quote

PCM programmer wrote:
Post your version of the compiler. You can find this at the top of the .LST
file, which will be in your project directory.


CCS PCH C Compiler, Version 3.224

MPLAB V7.30
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Oct 30, 2006 1:59 pm     Reply with quote

Quote:
CCS PCH C Compiler, Version 3.224

I don't have that version, so I installed the closest one I have, which is
vs. 3.230. It has some problems with the CCP2 setup. I have marked
the lines that have a problem with "Bug":
Code:

........... setup_ccp2(CCP_PWM); 
001C:  MOVLW  B7
001E:  ANDWF  T3CON,F
0020:  BCF    TRISC.1    // Bug.   Should be TRISE.7   
0022:  BCF    LATC.1     // Bug.   Should be LATE.7
0024:  MOVLW  0C
0026:  MOVWF  CCP2CON


Here is the code from vs. 3.249. Notice that it correctly sets pin E7
as a low-level output.
Code:

...... setup_ccp2(CCP_PWM);
0018:  MOVLW  B7
001A:  ANDWF  T3CON,F
001C:  BCF    TRISE.7  // Correct
001E:  BCF    LATE.7   // Correct
0020:  MOVLW  0C
0022:  MOVWF  CCP2CON


I think you can fix this by adding the two lines shown in bold below:
Quote:

setup_ccp2(CCP_PWM);
output_float(PIN_C1);
output_low(PIN_E7);


This will put Pin C1 back to it's default power-on reset state of being an
input pin. It will set Pin E7 as a low-level output pin:
Code:

..... setup_ccp2(CCP_PWM); 
001C:  MOVLW  B7
001E:  ANDWF  T3CON,F
0020:  BCF    TRISC.1
0022:  BCF    LATC.1
0024:  MOVLW  0C
0026:  MOVWF  CCP2CON
.................... output_float(PIN_C1); 
0028:  BSF    TRISC.1
.................... output_low(PIN_E7); 
002A:  BCF    TRISE.7
002C:  BCF    LATE.7


There are some other problems. You should look closely at the Config
bits generated by your version of the compiler. It looks like your
version is putting the PIC into "extended microcontroller" mode.
That mode is only available in the 18F8310 and 18F8410. The byte
you need to look at is "CONFIG 3L". Your version sets it to 0x80,
and vs. 3.249 sets it to 0x83. Of course, I'm assuming that the version
I'm testing (vs. 3.230) is the same as your version (vs. 3.224).

Here are the Config bits generated by vs. 3.230:
Code:
Configuration Fuses:
   Word  1: 0106   XT NOIESO NOFCMEN RESERVED
   Word  2: 1E1E   BROWNOUT NOWDT BORV21 PUT WDT32768
   Word  3: 80C0   BW16 NOWAIT NOLPT1OSC MCLR CCP2E7 RESERVED
   Word  4: 0081   STVREN NODEBUG RESERVED NOXINST
   Word  5: 0001   NOPROTECT
   Word  6: 0000 
   Word  7: 0001   NOEBTR


Here is the result for vs. 3.249:
Code:

Configuration Fuses:
   Word  1: 0100   XT NOIESO NOFCMEN RESERVED
   Word  2: 1E1E   BROWNOUT NOWDT BORV21 PUT WDT32768
   Word  3: 80C3   BW16 NOWAIT NOLPT1OSC MCLR CCP2E7 RESERVED RESERVED
   Word  4: 0081   STVREN NODEBUG RESERVED NOXINST
   Word  5: 0001   NOPROTECT
   Word  6: 0000 
   Word  7: 0001   NOEBTR

If you have PCWH, you might want to use the Device Editor to try to
fix the fuses.
FISH6942



Joined: 03 Feb 2006
Posts: 13
Location: Minnesota

View user's profile Send private message

PostPosted: Tue Oct 31, 2006 12:29 pm     Reply with quote

PCM - I should have mentioned that I'm not using any built-in functions for controlling the PWM, I'm writing all the control registers directly (seems safer that way).

Your last suggestion regarding CONFIG 3L seems to be right on. We wrote a quick assy program to output the CCP2 PWM on RE7 and noticed that the output hex file from that project specifically wrote these two bits high - 0x83 - (standard microcontroller mode). This program did behave properly.

I was a little unclear in your last response regarding compiler versions and how each one writes this register. You indicated that you are testing with V3.230 but that V3.249 should fix this issue. The reason I ask is I was planning to upgrade to see whether the latest version fixed this problem. However, I will probably have to upgrade to V4.xxx due to development being done on another module in this project having a need for it.

Is there any way to directly write to this register? Even through assy code?

I'll try to post again after I get final resolution.

Thanks
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Oct 31, 2006 12:59 pm     Reply with quote

Quote:
I was a little unclear in your last response regarding compiler
versions and how each one writes this register.

Your older version sets the Config bits to "Extended Microcontroller"
mode as the default.

Vs. 3.249 puts the PIC into "Microcontroller" mode as the default.
So CCS caught their error and fixed it sometime after your version.
They had not yet fixed it in vs. 3.230.

Quote:
Is there any way to directly write to this register ?

Even if the compiler creates incorrect settings for the Config bits,
you can change this in a menu in MPLAB, just before you program
the PIC. (Using ICD2, for example).
FISH6942



Joined: 03 Feb 2006
Posts: 13
Location: Minnesota

View user's profile Send private message

PostPosted: Tue Oct 31, 2006 2:55 pm     Reply with quote

I loaded V4.013 and it is properly writing to this config register. (both bits high)

FWIW, I had our Microchip FAE write a similar program using their C18 compiler. I loaded their hex file and ran it on our target. Looking at their hex file, it appears that their compiler doesn't write to this config register at all. Per the data sheet these two bits should default to high, however after running their program it had the identical results we had so it would appear that on this particular device these two bits default to zero.

I love a happy ending!!

PCM - Regarding writing to the Config Bits, this particular register isn't available on the Config Bit panel in MPLAB for this device. I was curious whether there was a way to write to them in code.
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