|
|
View previous topic :: View next topic |
Author |
Message |
Guest
|
Problem with 16F882 |
Posted: Wed Feb 25, 2009 4:42 pm |
|
|
Hi all,
I just migrated a design from the 16F873A to the 16F882 to take advantage of the new chips lower operating voltage capability. I am running the 16F882 at 3.3V. The new chip also has more capability, and I'm finding that my original code no longer works correctly. In particular, some digital I/O on pins RA0, RA1, and RA2 are acting flaky. These pins are shared with a comparator function on the new chip, so I think this is the root of my problem. It is my understanding that functions like the comparator are disabled at power-up, by I have also done that (I think) programatically. Unfortunately, I'm still observing the flaky behaviour.... Here is an example program that demonstrates the problem. At start-up, I flash a power LED (on RA1) a few times and then leave it on. As soon as I do this, I set another line (RA0) high, and this causes the power LED to go off. If I comment out this line the LED stays on.
Code: |
//-----< Include Files, setup fuses >-----
#include <16f882.h>
#fuses XT, NOWDT, NOPROTECT, PUT, NOLVP, BORV21
// Tell compiler clock speed is 4.00 MHZ Crystal
#use delay(clock=4000000)
//-----< General Program Defines >-----
#define Xbee_Reset Pin_A0 // Reset line to Xbee module (active low)
#define Pwr_Led Pin_A1 // Green Power LED
void main(void)
{
int8 iIndex;
// Here we turn-off the A/D converter and comparator modules as a precaution....
Setup_adc_ports( NO_ANALOGS );
Setup_comparator(NC_NC_NC_NC);
// Here we set the default variable and output states....
output_low(Xbee_Reset); // hold the Xbee in reset
output_low(Pwr_LED);
// Here we blip the Power LED at power-up to show that the interface is working
for ( iIndex = 0 ; iIndex < 3 ; iIndex++ )
{
output_high(PWR_LED);
delay_ms(250);
output_low(PWR_LED);
delay_ms(250);
}
// Here we leave the Power LED ON
output_high(PWR_LED);
// Here we enable the Xbee module
output_high(Xbee_Reset);
while(1){}
} // end Main
|
My compiler version is v4.050.
Any thoughts?
Thanks,
Mike |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Feb 25, 2009 8:35 pm |
|
|
Your version has a bug in the start-up code and in the setup_adc_ports()
function. It doesn't set the ANSEL register. To fix this, you'll need to
do it manually. Add the lines shown in bold below:
Quote: |
#byte ANSEL = 0x188
void main(void)
{
int8 iIndex;
Setup_adc_ports( NO_ANALOGS );
Setup_comparator(NC_NC_NC_NC);
ANSEL = 0x00; // Set A/D pins to all digital
// Here we set the default variable and output states....
output_low(Xbee_Reset); // hold the Xbee in reset
output_low(Pwr_LED); |
---------
Edit: Removed fix for ANSELH. Only ANSEL needs a fix in vs. 4.050.
Last edited by PCM programmer on Thu Feb 26, 2009 4:20 pm; edited 1 time in total |
|
|
Guest
|
|
Posted: Thu Feb 26, 2009 4:08 pm |
|
|
Has this been reported to CCS? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Feb 26, 2009 4:17 pm |
|
|
It's a problem in vs. 4.050. It's not a problem in the current vs. 4.086. |
|
|
Guest
|
|
Posted: Thu Feb 26, 2009 4:40 pm |
|
|
Thanks... |
|
|
Guest
|
|
Posted: Fri Feb 27, 2009 5:16 pm |
|
|
PCM,
Thanks, that solved my problem! My applicaton is now working 100% with the new chip!
As a matter of good programming etiquette, should I be explicitly disabling things like the comparator and analog-to-digital modules in my programs if they are not used? What is the generally accepted convention?
Thanks,
Mike |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Feb 27, 2009 5:35 pm |
|
|
Normally you don't have to. CCS puts in start-up code to disable
the comparators, the vref module, and also to make Port A into a
digital port. This code is in the .LST file, at the start of main().
You don't see it in your source code.
Often, when CCS updates the compiler with new PICs, some of these
things are not done correctly. In some cases it can be fixed by calling
the setup_comparator(), setup_vref(), and setup_adc_ports() functions
with 'disable' parameters. But sometimes those don't work, either.
They may have the same bug as the start-up code. That's the case
with setup_adc_ports() with your PIC in vs. 4.050. Then you have to
manually set things up by writing directly to register(s). |
|
|
|
|
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
|