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

Pins A3 and A4 wont turn on, only toggle
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Oct 12, 2009 1:50 pm     Reply with quote

To clarify your circuit diagram, which side of the FET is the Source and
which side is the Drain ?
scaven92



Joined: 06 Oct 2006
Posts: 44

View user's profile Send private message

PostPosted: Mon Oct 12, 2009 1:52 pm     Reply with quote

I have changed my enable_led() function to accomodate this problem and everything is working smoothly.


Code:

void enable_led( int value, int time_ms, int number )
{
   int i, j = 0;

   if( number != 0 )
   {
      if( value ) status |= (1 << (number-1));   //Set bit i of shadow reg
      else status &= ~(1 << (number-1));         //Clear bit i of shadow reg
      output_a(status);
   }
   else
   {   
      for(i=0; i<7; i++)
      {
         if( value ) status |= (1 << i);   //Set bit i of shadow reg
         else status &= ~(1 << i);         //Clear bit i of shadow reg
         output_a(status);
         for(j=0; j<time_ms; j++) delay_ms(1);
      }
   }
}


Code:

void main()
{
   output_bit(LED_DRIVE, ON);
   while(1)
   {
      enable_led(ON, 500, ALL);
      delay_ms(500); 
      enable_led(OFF, 500, ALL);
      delay_ms(500); 
   }
}
scaven92



Joined: 06 Oct 2006
Posts: 44

View user's profile Send private message

PostPosted: Mon Oct 12, 2009 1:55 pm     Reply with quote

In my diagram the source of the fet is grounded and the drain connects to the cathode of the led.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Oct 12, 2009 3:36 pm     Reply with quote

The reason is because there is a bug in your version of the compiler
(vs. 4.093). In the start-up code, it's only clearing bits 0,1,2 of the
ANSELA register. It leaves bits 3, 4 and 5 in their power-up state,
which is all 1's. This means pins A3, A4 and A5 are still set as Analog
pins, which means they read back as 0's. That's what causing the RMW
problem.

To fix this, declare ANSELA above main() with a byte statement.
Then set it to 0 at the start of main() with a line of code. Example:
Code:

#byte ANSELA = 0x185

//==========================
void main()
{
ANSELA = 0; 


while(1);
}


If you do that, you probably don't need the RMW fix that you did to
your code.
scaven92



Joined: 06 Oct 2006
Posts: 44

View user's profile Send private message

PostPosted: Mon Oct 12, 2009 3:54 pm     Reply with quote

Wow, that has to be it. I will correct my code to handle this problem. I appreciate your help, you have saved me alot of time and made me aware of this Read-Modify-Write problem.

Should I send CCS an email with a link to this forum for this problem for future update?

Thanks again!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Oct 12, 2009 4:00 pm     Reply with quote

They fixed it in vs. 4.099, as shown below. Both ANSELA and ANSELB
are set to 0x00.
Code:

.... void main()
.... {
0004:  CLRF   04
0005:  BCF    03.7
0006:  MOVLW  1F
0007:  ANDWF  03,F

0008:  MOVLW  00
0009:  BSF    03.5
000A:  BSF    03.6
000B:  MOVWF  06     // 0x186 = 0x00  ANSELB

000C:  BCF    09.0   // Bug: 0x189 is not a register
000D:  BCF    09.1
000E:  BCF    09.2

000F:  BCF    03.6
0010:  BCF    1F.0   // ADCON1.0 = 0
0011:  BCF    1F.1   // ADCON1.1 = 0   Vref = Vdd
0012:  BSF    03.6
0013:  MOVWF  05     // 0x185  ANSELA = 0x00
.... while(1);
0014:  GOTO   014
scaven92



Joined: 06 Oct 2006
Posts: 44

View user's profile Send private message

PostPosted: Mon Oct 12, 2009 4:25 pm     Reply with quote

Great! I'll have to see if my 30 days of compiler updates is still valid or order an update package.

Thanks!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
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