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 support@ccsinfo.com

Output_High to one pin resets other outputs on same port

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



Joined: 19 May 2010
Posts: 36
Location: UK

View user's profile Send private message

Output_High to one pin resets other outputs on same port
PostPosted: Wed Mar 02, 2011 12:18 pm     Reply with quote

I have come across a problem whilst migrating some code from an old PC with an old version of the CCS compiler, has anyone seen this before?

Compiler version PCW 4.118, ICD-U64 programmer
Code:

#include <16F685.h>
#FUSES INTRC_IO,NOWDT,PUT,MCLR,PROTECT,NOCPD,NOBROWNOUT,NOIESO,NOFCMEN
#use delay(clock=1000000)

void main()
{

   setup_oscillator( OSC_1MHZ );
   setup_adc( ADC_OFF );
   setup_adc_ports( NO_ANALOGS );
   setup_ccp1(CCP_OFF);
   setup_comparator(NC_NC_NC_NC);

   output_b(48);
   delay_ms(5000);
   output_high(PIN_B4);
   delay_ms(5000);
   output_high(PIN_B5);
   while(true)
   {
   }
}


Pin B4 and B5 are connected to LED's. When the program executes
Code:

output_b(48);

both LED's are on. But then when it executes the code :
Code:

 output_high(PIN_B4);

Pin B5 goes off and only B4 is on, and when it executes the code
Code:

output_high(PIN_B5);

then B5 goes on but B4 goes off.

Looking at the symbol file it seems the compiler is not properly setting the bits in the ANSEL and ANSELH register during the
Code:

setup_adc_ports( NO_ANALOGS );


I have added the function :
Code:

void No_Analog()
{
   #ASM ASIS
      //Page 2
      BCF 0x03,5
      BSF 0x03,6
      //ANSEL to all zeros
      MOVLW 00
      MOVWF 0x1E
      //ANSELH to all zeros
      BCF 0x1F,0
      BCF 0x1F,1
      BCF 0x1F,2
      BCF 0x1F,3
      BCF 0x03,6
      //AD converter off
      BCF 0x1F,0
   #ENDASM
}


and this seems to have fixed it. On the old compiler (PCM 3.242) it does not have this problem. Is this another bug?
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Wed Mar 02, 2011 1:07 pm     Reply with quote

This can also happen, if the load current is so high, that the output pins won't reach the minimum high level.
Setting a pin involves a read-modify-write cycle, the pins not set in the command are read in from the
port. If no high level can be recognized for a pin, it will be reset.

P.S.: The wrong ANSEL setup is a new V4.118 bug. It's corrected in V4.119.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Mar 02, 2011 1:36 pm     Reply with quote

There's a bug in vs. 4.118 for the 16F685. The start-up code and also the
setup_adc_ports() function don't properly disable some of the analog pins,
in the ANSEL and ANSELH registers. Pins that are left in the analog
state, but are used for digital i/o will be read as "0". The PIC does a
Read-Modify-Write operation on the whole port it writes to pin. That's why
all the other analog pins on that port are reset to 0 when you do an
output_high(PIN_B4). It reads them as 0's and writes them back as 0's.

Also, the top two bits of ANSEL are not setup properly.

This bug was fixed in vs. 4.119. So if you have maintenance with CCS,
you could upgrade and fix it.

You could do this as a work-around:
Code:

#byte ANSEL  = 0x11E
#byte ANSELH = 0x11F

void main()
{
ANSEL = 0;     // Make all analog pins be digital i/o pins
ANSELH = 0;
levdev



Joined: 19 May 2010
Posts: 36
Location: UK

View user's profile Send private message

PostPosted: Wed Mar 02, 2011 3:17 pm     Reply with quote

Thanks for the input, wish I'd asked earlier as I spent most of this afternoon tracking this one down. I've installed the latest version and the problem is fixed for the AD initialisation at least, but now my read or write eeprom isn't working (whereas it was on the old compiler version). Unfortunately debugging is nearly impossible because The 16F685 doesn't support debug mode, and I haven't got an RS232 port. The test program below highlights the problem by flashing an LED.
Code:

#include <16F685.h>
#FUSES INTRC_IO,NOWDT,PUT,MCLR,PROTECT,NOCPD,NOBROWNOUT,NOIESO,NOFCMEN
#use delay(clock=8000000)
#use fast_io(B)

void Initialise_uC()
{
   setup_comparator(NC_NC_NC_NC);
   setup_ccp1(CCP_OFF);
   setup_oscillator(OSC_8MHZ);
   setup_adc( ADC_OFF );
   setup_adc_ports( NO_ANALOGS );
   set_tris_b( 0b10000000 );
   output_b(0);
}

void write_float(float scale)
{
   int i;
   for (i = 0; i < 4; i++)
   {
      write_eeprom(i+8, *(&scale + i) );
   }
}

float read_float()
{
   float reading;
   int i;
   for (i = 0; i < 4; i++)
   {
      *(&reading + i) = read_eeprom(i+8);
   }
   return reading;
}

void output_LED(float j)
{
   float i;
   for (i=0;i<j;i=i+1)
   {
      output_high(PIN_B4);
      delay_ms(100);
      output_low(PIN_B4);
      delay_ms(100);
   }
}

void main()
{
   float j;
   Initialise_uC();
   delay_ms(3000);
   //if switch is pressed at startup then write value to eeprom
   if( input( PIN_B7 )==0)
   {
      write_float(20);
      output_high(PIN_B4);
      delay_ms(100);
      output_low(PIN_B4);
      delay_ms(100);
   }
   delay_ms(3000);
   while(1)
   {
      j=read_float();
      output_LED(j);
      delay_ms(3000);
   }
}

Do you have any idea why this works when I compile and prgram it with the old version (3.242) but not the new version (4.119). It should flash the LED 20 times, but when compiled with version 4.119 it flashes about 130 times.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Mar 02, 2011 3:22 pm     Reply with quote

See this thread:
http://www.ccsinfo.com/forum/viewtopic.php?t=30461

CCS has routines to do this, for vs. 4.xxx of the compiler. Use them
instead of your routines.

#include the following file in your program and call the CCS routines:
Quote:

c:\program files\picc\drivers\internal_eeprom.c
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