View previous topic :: View next topic |
Author |
Message |
Sensor
Joined: 04 Nov 2004 Posts: 33
|
18F toggling pin problem |
Posted: Thu Nov 16, 2006 10:19 am |
|
|
PIC: 18F6527
Voltage: 5V
Osc: 7.3728MHZ
Compiler: PCWH 3.236
I am having a problem with the 18F6527. All I am trying to do is set a pin high and then set the same pin low and I cannot do it. I had a design with a 16F and everything worked great... now I am try to reuse the same code on my 18F but nothing is working. So I've cut the code down to the following:
Code: |
#include <18F6527.h>
#device adc=10
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //High speed Osc (> 4mhz)
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOIESO //Internal External Switch Over mode disabled
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOPUT //No Power Up Timer
#FUSES NOCPD //No EE protection
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT //Program memory not write protected
#FUSES NOCPB //No Boot Block code protection
#FUSES NOEBTRB //Boot block not protected from table reads
#FUSES NOEBTR //Memory not protected from table reads
#FUSES NOWRTD //Data EEPROM not write protected
#FUSES NOWRTC //configuration not registers write protected
#FUSES NOWRTB //Boot block not write protected
#FUSES NOLPT1OSC //Timer1 configured for higher power operation
#FUSES NOMCLR //Master Clear pin enabled
#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES BBSIZ2K //2K words Boot Block size
#use delay(clock=7372800)
void main()
{
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
#use fast_io(C)
set_tris_c(0x80);
while(TRUE)
{
output_high(PIN_C1);
delay_ms(1000);
output_low(PIN_C1);
delay_ms(1000);
}
}
|
The Pin never goes high. Why? If I change the pin I want to toggle to a port_B pin, it works fine. |
|
|
Ttelmah Guest
|
|
Posted: Thu Nov 16, 2006 11:17 am |
|
|
Turn off CCP2.
This outputs on pin C1, and it's operation overrides the port settings.
Best Wishes |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Thu Nov 16, 2006 11:27 am |
|
|
In the simulator your program is working fine, but only when I disabled the BBSIZ2K fuse. |
|
|
Sensor
Joined: 04 Nov 2004 Posts: 33
|
|
Posted: Fri Nov 17, 2006 10:32 am |
|
|
I tried disabling the BBSIZ2K and it did not work.
I verified that only RC1 from portC is the problem.
Ttelmah, in the datasheet it says, by default, the CCP2MX configuration bit equals one, so ECCP2 is assigned to RC1. So if I clear the CCP2MX bit, then ECCP2 is multiplexed with RE7. So either way, if the bit the cleared or set, I will lose either RC1 or RE7 as a general purpose GPIO. Is that correct?
I am new to the 18F series, can you tell me how to clear the bit? |
|
|
Ttelmah Guest
|
|
Posted: Fri Nov 17, 2006 10:44 am |
|
|
Just turn the CCP off. You 'lose' the output bits, if the module is enabled. The fuse allows you to set 'which' bit is lost.
I'd normally expect the module to be 'off', but some modules on the PIC default to on, or are turned on by CCS, so I'd simply try disabling it, and see if the pin works (setup_ccp2(CCP_OFF)).
Best Wishes |
|
|
FISH6942
Joined: 03 Feb 2006 Posts: 13 Location: Minnesota
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Nov 17, 2006 12:55 pm |
|
|
Here is the errata for the 18F6527:
http://ww1.microchip.com/downloads/en/DeviceDoc/80253b.pdf
It says:
Quote: |
5. Module: ECCP
PIC18F6XXX device�s Configuration Word,
CONFIG3L, is not [implemented] and will switch
the ECCP2 output pin similar to the PIC18F8XXX
devices if the Processor mode does not select
Microcontroller mode.
Work around
In MPLAB � IDE, program the PIC18F6XXX device
as its PIC18F8XXX equivalent and assign the
Processor mode bits (PM<1:0>) to �11� for
Microcontroller mode. |
I'm not sure how to interpret this. It sounds like they want you
to set the PIC type to 18F8527 and manually set the two lowest
bits in Config3L to 11, by using the Configure Menu in MPLAB.
If you try this in MPLAB, it will give you a warning message when
you tell ICD2 to "connect" to your PIC. But, it will still "connect" and
it will apparently go ahead and program. I tested this with an 18F452.
Here are the Config fuses for your program, when compiled with PCH
vs. 3.236. This is from the .LST file. The bottom two bits in Config3L
are already set to 11. So it's possible that all you need to do is to
select "18F8527" in MPLAB, in the Configure/Select Device menu,
before you do the programming.
Quote: | Configuration Fuses:
Word 1: 0200 HS NOIESO NOFCMEN RESERVED
Word 2: 1E19 NOBROWNOUT NOWDT BORV25 NOPUT WDT32768
Word 3: 01F3 CCP2C1 NOLPT1OSC NOMCLR RESERVED
Word 4: 0091 STVREN NODEBUG NOLVP NOXINST BBSIZ2K
Word 5: C0FF NOPROTECT NOCPD NOCPB
Word 6: E0FF NOWRT NOWRTD NOWRTC NOWRTB
Word 7: 40FF NOEBTRB NOEBTR |
|
|
|
|