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

16F690 problem when using PORTC outputs

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



Joined: 02 Jun 2009
Posts: 5

View user's profile Send private message

16F690 problem when using PORTC outputs
PostPosted: Tue Jun 02, 2009 4:49 am     Reply with quote

Hi,

I've been testing pic 16F690 PORTC as digital I/O but something is not working properly. Whenever I set/reset one of PORTC lines to HI, all the others will reset to LOW. I'm almost sure that this must be one hardware problem since I already tried other C compilers and I have the same problem! Probably something that I forgot to switch off! I'm kind of lost, already tried so many things ... any help will be much appreciated!

CCS compiler version is: 4.057

My code:
Code:

#include <16F690.h>
#use delay(clock=4000000)
#use fast_io(C)
#fuses INTRC_IO, NOWDT, PUT, HS, PUT, NOPROTECT, BROWNOUT, MCLR, NOCPD
//------------------------------------------------------------

void main(void)
{
  delay_ms(100); // power up delay
 
  setup_adc_ports(NO_ANALOGS|VSS_VDD);
  setup_adc(ADC_OFF);
  setup_ccp1(CCP_OFF);
  setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
  setup_timer_1(T1_DISABLED);
  setup_timer_2(T2_DISABLED,0,1);
  setup_comparator(NC_NC_NC_NC);
  setup_oscillator(OSC_4MHZ);
  setup_vref(FALSE);

  set_tris_b(0b00111111);
  set_tris_c(0b11111000);

  while( TRUE )
  {
    output_high(PIN_C0); // ledC0 on, ledC1 off, ledC2 off
    delay_ms(500);
    output_high(PIN_C1); // ledC0 off, ledC1 on, ledC2 off
    delay_ms(500);
    output_high(PIN_C2); // ledC0 off, ledC1 off, ledC2 on
    delay_ms(500);
    output_high(PIN_B6); // ledB6 on, ledB7 off
    delay_ms(500);
    output_high(PIN_B7); // ledB6 on, ledB7 on
    delay_ms(500);
 

    output_low(PIN_C0); // ledC0 off, ledC1 off, ledC2 off
    delay_ms(500);
    output_low(PIN_C1); // ledC0 off, ledC1 off, ledC2 off
    delay_ms(500);
    output_low(PIN_C2); // ledC0 off, ledC1 off, ledC2 off
    delay_ms(500);
    output_low(PIN_B6); // ledB6 off, ledB7 on
    delay_ms(500);
    output_low(PIN_B7); // ledB6 off, ledB7 off
    delay_ms(500);
  }
}
//--------------------------------------------------//


PortB is working properly! I've read some topics that mentioned ANSEL registry, also tried to access to clear but no luck (trying to config PORTC to digital I/O):
Code:

...
setup_vref(FALSE);

// STATUS,RP0,RP1,PORTC,ANSEL required to be custom defined in 16f690.h file
// Used MPLAB->Watch to get registry address

#asm
BCF STATUS,RP0         ;Bank 0
BCF STATUS,RP1         ;
CLRF PORTC            ;Init PORTC
BSF STATUS,RP1         ;Bank 2
CLRF ANSEL                ;digital I/O
BSF STATUS,RP0         ;Bank 1
BCF STATUS,RP1         ;
BCF STATUS,RP0         ;Bank 0
#endasm

  set_tris_b(0b00111111);
  set_tris_c(0b11111000);
...


Regards.
Ttelmah
Guest







PostPosted: Tue Jun 02, 2009 5:22 am     Reply with quote

You are selecting both INTRC_IO, and HS. You cannot have both. There must only be _one_ oscillator type selected. Won't cause your problem, but should be corrected.

Question. What are the PortC lines connected _to_?.

Your problem, sounds like the 'classic' PIC RMW problem.

On the more basic PIC's, when you set a bit on a port, the processor actually performs a 'read, modify, write' cycle. The level on each port pin is read, the new bit value is "or'ed" with this (the modify), and then the result is written back out. The problem arises, if you have circuitry on output pins, that does not allow them to actually 'pull up' (or down, when going the other way), to the level that is 'seen' by the processor as a 'high'. When the internal 'read' is performed, the pin is not 'seen' as high, so when the value is written back, it is turned off.
So (for instance), if you have a pin connected to a LED, without a current limiting resistor, the pin only goes up to perhaps 2.7v. If this is below the 'high' threshold for the pin when used as an input, when you try to set another pin, this one will go low.
Now, this problem is worse on pins with 'Schmitt' inputs, since on these the high threshold is typically 4v, rather than 2.4v on other pins.
The problem can be seen for a number of reasons:
1) Pin is really overloaded....
2) Pin has a lot of capacitance attached, so it takes significant _time_ to reach a selected level.
3) Though legitimately loaded, the load is high enough, that the threshold is just not reached.

Solutions differ according to which applies.
If the first, then you need to fix the hardware.
If the second, you can add a delay after changing any pin.
If the third, then you need to hold a local 'copy' of what you want to put on all the pins, and update the whole port with this copy, when you change any pin.

PortC, on your PIC, has Schmitt inputs.

A search for 'RMW' or or 'read modify write', here, or on the Microchip site will find loads about this.

Best Wishes
sevensins



Joined: 02 Jun 2009
Posts: 5

View user's profile Send private message

PostPosted: Tue Jun 02, 2009 5:44 am     Reply with quote

The INTRC_IO was kind of last minute test that I have picked up form other post and forgot to remove it, but all my other test I tried without it! Thanks for pointing it out, will remove it right away.

Sorry, forgot to mention the basic setting, the tested pins have a 1K resistor connected between pin and 5V (VDD) and also 1 LED from pin to ground for visual output!

Thank you for your guide lines, sure that they will help me to solve my problem!

Will post my results soon.

Regards.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jun 02, 2009 11:34 am     Reply with quote

Post a schematic of the circuits connected to Port C pins.
You can upload the schematic to a free image hosting site and post
a link to it, or you can use ASCII art to show the circuit. Example:
http://www.ccsinfo.com/forum/viewtopic.php?t=33292&start=12

If you use ASCII art, put it in a Code block, and use the Preview button
to make sure it looks good before you post it. It will probably require
some editing before it looks good.
bungee-



Joined: 27 Jun 2007
Posts: 206

View user's profile Send private message

PostPosted: Tue Jun 02, 2009 3:27 pm     Reply with quote

@sevensins:

You should connect your LED-s like this:
Code:

           ___
pic pin---|___|-->|- GND



So the pic will supply VCC to led when needed.
sevensins



Joined: 02 Jun 2009
Posts: 5

View user's profile Send private message

PostPosted: Tue Jun 02, 2009 6:10 pm     Reply with quote

Hi again, sorry for the late response, got disconnected from net at work :(.

It was indeed and electric problem, just removed the leds and used a multimeter to check for the voltage and its working properly! I've extended the delays between pins settings to measure voltage properly, I got 5V (HIGH) and it only goes to 0V (LOW) when expected!

Ttelmah got it right:
1) Pin is really overloaded....

here is my connections for the pull-up and led:
Code:

         1K            Led
+5v ---/\/\/\/---o---|>|-------- GND
                 |             
                 |
          PIC PORTC RC0


I'm also using this for PORTB and it works well!
For PORTC I will probably need to use a transistor to drive the led!

Driving the led directly from PORTC won't work either! No Problem, lesson learned!

Thank you all for pointing this out, I was getting nuts, trying to determine if it was a software problem, or even a hardware bug!

Ttelmah, I owe you one! ;)

Regards,

Nelson.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jun 02, 2009 6:36 pm     Reply with quote

You need a series resistor. Get rid of the pull-up and add the series
resistor, as shown in bungee's post. You can use 330 or 470 ohms.
sevensins



Joined: 02 Jun 2009
Posts: 5

View user's profile Send private message

PostPosted: Tue Jun 02, 2009 6:55 pm     Reply with quote

Sorry, my mistake ... using a 330 resistor will do the trick!

Thanks PCM programmer!
Ttelmah
Guest







PostPosted: Wed Jun 03, 2009 2:46 am     Reply with quote

To put this in perspective, the output pins _will_ be overloaded. This applies to PortB as well. However you are 'getting away with it' on PortB, since the logic high threshold for a TTL input, is 2.4v. Basically, the only thing stopping the PIC from being destroyed by this, is the internal current limit at 25mA, on each output pin....
The LED's, may also be being driven outside their 'safe' area. 25mA, is beyond the upper rating for many small LEDs, and is the 'maximum' for most. Operating at the maximum for anything, is potentially risky.
If you really do want to deliver 25mA or more into the LED's, then consider an external driver circuit. Otherwise, just add a series resistor. The actual value needed will depend on the Vf of the LED involved, but typically something like 270 or 330R, for a red LED is normal, and keeps currents in a safe area.

Best Wishes
sevensins



Joined: 02 Jun 2009
Posts: 5

View user's profile Send private message

PostPosted: Wed Jun 03, 2009 4:48 am     Reply with quote

Much appreciated for all your help! I really feel embarrassed for such mistake!
I'm used to apply pull-up resistor for certain chips, normally when using bus lines. Got distracted with the excitement trying to implement something nice but in short time, hurry is not good for anything!

Very valuable lesson learned today! My apologizes for any inconvenience!

Regards,

Nelson.
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