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

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



Joined: 06 Oct 2006
Posts: 44

View user's profile Send private message

Pins A3 and A4 wont turn on, only toggle
PostPosted: Fri Oct 09, 2009 2:58 pm     Reply with quote

Hello,

I am using a PIC16LF722 for a project and I am have difficulty with two pins RA3 and RA4.

When I may the call output_bit(PIN_A3, 1) or output_bit(PIN_A4, 1) they turn on for about 1 ms, then turn off. I have posted my code below, I can turn on the other pins fine.

I have verified this with a scope, the pins are fed into the gate of a transistor with a pulldown resistor.

The code below just enables all leds for 5 sec, turns them off for 2 sec, then turns them all on again. Please help! Thanks!

Code:

#include <16LF722.h>
#device adc=8

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES INTRC                    //Resistor/Capacitor Osc with CLKOUT
#FUSES NOPUT                    //No Power Up Timer
#FUSES MCLR                     //Master Clear pin used for I/O
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NODEBUG                  //No Debug mode for ICD

#use delay(clock=500000)

#DEFINE  LED_DRIVE      PIN_C2
#DEFINE  LED1           PIN_A0
#DEFINE  LED2           PIN_A1
#DEFINE  LED3           PIN_A2
#DEFINE  LED4           PIN_A3
#DEFINE  LED5           PIN_A4
#DEFINE  LED6           PIN_C1
#DEFINE  LED7           PIN_A5

int leds[7] = {LED1, LED2, LED3, LED4, LED5, LED6, LED7};

void setup()
{
   setup_timer_0(RTCC_INTERNAL);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
}

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

   if( number != 0 ) output_bit(leds[number-1], value);
   else
   {   
      for(i=0; i<7; i++)
      {
         output_bit(leds[i], value);
         for(j=0; j<time_ms; j++) delay_ms(1);
      }
   }
}

void main()
{
   int i, j = 0;

   setup();

   output_bit(LED_DRIVE, 1);
   enable_led(1, 0, 0);
   delay_ms(5000);
   enable_led(0, 0, 0);
   delay_ms(2000); 

   output_bit(LED_DRIVE, 1);
   enable_led(1, 0, 0);
   
   while(1);
}


I am using 4.093 compiler, PCWHD.


Last edited by scaven92 on Mon Oct 12, 2009 4:07 pm; edited 1 time in total
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Oct 09, 2009 3:15 pm     Reply with quote

Look at the pin tables in the Overview section of the PIC data sheet.
It says:
Quote:

RA4/T0CKI -- RA4 can also be the clock input to the Timer0 module.
Output is open drain type.

Pin A4 can't output a high level to the LED.



To test the pin A3 problem, try a simple little test like this:
Code:

void main()
{

output_bit(LED_DRIVE, 1);
   
while(1)
  {
   output_high(PIN_A3);
   delay_ms(500); 
   output_low(PIN_A3);
   delay_ms(500); 
  }
   
}
scaven92



Joined: 06 Oct 2006
Posts: 44

View user's profile Send private message

PostPosted: Fri Oct 09, 2009 3:34 pm     Reply with quote

Thanks for the quick response.

I reviewed the data sheet and all I find is that RA4 is TTL Input type, CMOS output type, and General Purpose I/O, without saying anything about the Open Drain only. It also lists that when configured it can be and Analog input or output. I often use the PIC18F452, that that states that it is in fact an OD output. Is there a misprint or am I blind? Through the use of a scope I am seeing a high logic level on poth A3 and A4 for 1-2 ms and I only have a pulldown resistor on the gate of the n-type fet.

I am looking at page 16 of http://ww1.microchip.com/downloads/en/DeviceDoc/41341D.pdf.

I will try your suggestion for pin A3 and get back to you.

Thanks!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Oct 09, 2009 3:37 pm     Reply with quote

You are right. In my haste, I looked at the data sheet for 16F72.
scaven92



Joined: 06 Oct 2006
Posts: 44

View user's profile Send private message

PostPosted: Fri Oct 09, 2009 3:47 pm     Reply with quote

I have tried your main for both pins A3 and A4 and they work! Both output_high(PIN_A3) and output_bit(PIN_A3, 1) work.

Let me look more into my function call enable_led() to see where things get messed up.

I tried this main function and it does NOT work. I have added DEFINES too for the new labels.



Code:


#DEFINE  ON          1
#DEFINE  OFF         0
#DEFINE  ALL         0

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


I have also tried condensing that function and it still does not work.

Code:

void main()
{
   int i, j = 0;

   output_bit(LED_DRIVE, ON);
   
   while(1)
   {
      for(i=0; i<7; i++)
      {
         output_high(leds[i]);
      }
      delay_ms(500);
      for(i=0; i<7; i++)
      {
         output_low(leds[i]);
      }
      delay_ms(500);
   }
}
scaven92



Joined: 06 Oct 2006
Posts: 44

View user's profile Send private message

PostPosted: Fri Oct 09, 2009 4:19 pm     Reply with quote

Its seems like I have no problem turning them on individually, but when I turn all of the leds on two of them only pulse and won't come on.

I believe that when I turn one of the ports on (either A4 or A3) than turn on one of the others, the previous one turns off. This is only evident in A3 and A4. I'm going to have to look at the disassembly to see if something is not right.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Oct 09, 2009 4:45 pm     Reply with quote

It could be a read-modify-write problem. Describe the external LED
circuits in detail. Give the part number of the LEDs and the size of the
series resistors (in ohms). Describe any other parts in the LED circuit.
scaven92



Joined: 06 Oct 2006
Posts: 44

View user's profile Send private message

PostPosted: Fri Oct 09, 2009 5:30 pm     Reply with quote

I have attached the following LEDs, resistors and transistors to the following pins: A0, A1, A2, A3, A4, A5, C1 (all wired the same).

I have a power enable for the power source to the leds, which is connected to pin C2.

I am using a 5V supply through a 91 ohm resistor through a white led ( http://www.mouser.com/ProductDetail/Kingbright/APHH1005RWF-A/?qs=48MD8zkHsZDjhqU9RfTJ7g%3d%3d) which is connected to the drain of a 2N7002 N-Mosfet. The source of the mosfet is grounded. A 10k ohm resistor is connected from the gate of the mosfet to ground. Each of the above mentioned pins of the PIC is connected to the gate to its mosfet. The PIC runs on 3.3V supply and is using an internal oscillator.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Oct 09, 2009 5:36 pm     Reply with quote

I'm having difficulty following your description. Can you use ASCII art
to draw a schematic. There are examples in this thread:
http://www.ccsinfo.com/forum/viewtopic.php?t=39100
Compose it in a text editor with a fixed font (non-proportional).
Then copy and paste it into your post. Put it in a Code block to
preserve the formatting. Preview it to make sure it looks correct.

Just draw a schematic of one of the LED/FET circuits.
scaven92



Joined: 06 Oct 2006
Posts: 44

View user's profile Send private message

PostPosted: Fri Oct 09, 2009 5:58 pm     Reply with quote

I have the following circuit, one for each of the following pins: A0, A1, A2, A3, A4, A5, C1 (7 total LEDs).

I also have pin C2 used for to turn on the 5V supply for all of the LED's.

Code:

         91ohm          Led         2N7002
+5v ---/\/\/\/-------|>|-------- \__/----|> GND
                                   |             
                                   |           10k
                                   o -------/\/\/\/---|> GND
                                   |
                              PIC PORT
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Oct 09, 2009 9:28 pm     Reply with quote

Quote:
void main()
{
int i, j = 0;

output_bit(LED_DRIVE, 1);
enable_led(1, 1, 0);
delay_ms(5000);
enable_led(0, 1, 0);
delay_ms(2000);

output_bit(LED_DRIVE, 1);
enable_led(1, 1, 0);

while(1);
}

Add a delay to each enable_led() call, as shown above in bold.


Quote:

void enable_led( int value, float time_ms, int number)

Also, the delay should not be a float. Change it to an 'int'.
scaven92



Joined: 06 Oct 2006
Posts: 44

View user's profile Send private message

PostPosted: Mon Oct 12, 2009 10:33 am     Reply with quote

I tried the delay and it acts the same, the two leds connected to A3 and A4 blink for a very belief moment while all the other leds come on.

I am lost...
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Oct 12, 2009 10:42 am     Reply with quote

To prove if it's a Read-Modify-Write problem, try setting up a shadow
register for Port A. This would be just an 'int8' variable, called
PortA_Shadow or something like that. Then do all your bit operations
on that variable. After doing a bit operation on the shadow register,
then write the entire shadow register to Port A in one operation, by
using the output_a() function.

This means that the only way you will write to Port A will be with the
output_a() function. You will never use output_bit() or output_low()
or output_high() on individual pins. Port A will only be written to
with a full port write operation.

See if that fixes your problem.
scaven92



Joined: 06 Oct 2006
Posts: 44

View user's profile Send private message

PostPosted: Mon Oct 12, 2009 12:27 pm     Reply with quote

Alright I will try that. If it is a read-modify-write problem, wouldn't a 500ms delay between port reads be enouph to allow that pin to settle to the correct value? The only load on that pin is the gate to the fet and the 10k pulldown, no substantial capacitive loads.

I'll let you know in a few.

Thanks for the help!
scaven92



Joined: 06 Oct 2006
Posts: 44

View user's profile Send private message

PostPosted: Mon Oct 12, 2009 12:48 pm     Reply with quote

It looks like it is the read-modify-write problem you have previously mentioned. I was able to turn all the LED's on.

I have a question though, even if I put a 500ms delay in between successive bit manipulations on PORTA, I still run into the problem. I don't see how there is such a load on the pin to cause the state to change and the next read of the port to not be what I set it to 500ms prior. I only have a 10k pulldown and the port in feeding directly into the gate of the fet.

For the meantime I will use the shadow variable to keep track of every bit manipulations and write the PORT as a whole.

This is still leaving me confused as to why this is happening.

Thanks,

Chris
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 1, 2  Next
Page 1 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