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

input pins constantly high

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







input pins constantly high
PostPosted: Sat Sep 09, 2006 10:44 am     Reply with quote

Hi, I'm using some simple switches for inputs on a PIC16f876. There are 10K resistors pulling the pins down and the switches pull the pins up.
Some of the pins go permanently high and are useless as input pins. This happened to c5 and c7 and b0.
The programme runs motors via a L298 motor driver and the inputs are some limiter micro switches that stop the motors when they are pressed (in the pulse() routine). Any ideas why this happens?

Many thanks, Moritz.

Code:

#include <16f876.h>
//#include <stdlib.h>
#device *=16
#fuses HS,nowdt, PROTECT,PUT,nolvp
//#fuses XT,NOWDT,NOPROTECT
//#fuses INTRC_IO,NOWDT,NOBROWNOUT,NOPROTECT,PUT,NOLVP
#use delay(clock=20000000)

#use rs232(baud=9600, xmit=pin_b6, rcv=PIN_b3)


#define startbutton pin_b2//check!!!
#define led0 pin_b3
#define en0 pin_a4
#define en1 pin_a1
#define en2 pin_c6
#define en3 pin_c1

#define c0 pin_a5
#define d0 pin_a3
#define c1 pin_a2
#define d1 pin_a0

#define c2 pin_c4
#define d2 pin_c3
#define c3 pin_c2
#define d3 pin_c0

#define sense0 pin_b6
#define sense1 pin_b3
//#define sense2 pin_b2
#define sense3 pin_b1
#define sense4 pin_b0
#define sense5 pin_c7
#define sense6 pin_c5

long p1val[3], p1count=0;
long p0val[3], p0count=0;
long p3val[3], p3count=0;

               //dir0-1,power0-100, until time0-400
                   //0
long p3[12]={  1,98,50,    //wind in waist from relaxed for 5s
               1,10,400,    //hold in,
               0,50,450,   //wind out 10-15
               0,0,600};   //stop winding out 15s until end
               
long p1[12]={  0,30,50,
               0,0,300,         //bib start down
               1,88,350,  //bib go up @10s
               1,0,600};  //bib inactive until end
               
long p0[12]={  0,60,20,    //sleeves go out
               0,0, 300,    //sleeve start out, motor off
               1,88,320,  //sleeve go in at 10s
               1,0,600};    //sleeve stops




void flashled(void)
{
output_high(led0);
delay_ms(80);
output_low(led0);
delay_ms(80);
}

void setdir(void)
{
//sets motor direction
if (p1val[0]==0)   //BIB down
      {
      output_low(c1); output_high(d1);
      }
else                                         //BIB up
      {
      output_high(c1); output_low(d1);
     }

if (p0val[0]==0)  //sets motor direction // SLEEVE down
      {
     output_high(c0); output_low(d0);
      }
else                                         // SLEEEVE up
      {
     output_low(c0); output_high(d0);
     }

if (p3val[0]==0)  //sets motor direction // waist out
      {
      output_low(c3); output_high(d3);
      }
else                                         //waist in
      {
      output_high(c3); output_low(d3);
      }

}


void renewvar(long time) //replaces variables at time points
{
//int a;
if(p1val[2]==time)
      {
p1val[0]=p1[p1count];
p1count++;
p1val[1]=p1[p1count];
p1count++;
p1val[2]=p1[p1count];
p1count++;
      }
if(p0val[2]==time)
      {
p0val[0]=p0[p0count];
p0count++;
p0val[1]=p0[p0count];
p0count++;
p0val[2]=p0[p0count];
p0count++;
      }
if(p3val[2]==time)
      {
p3val[0]=p3[p3count];
p3count++;
p3val[1]=p3[p3count];
p3count++;
p3val[2]=p3[p3count];
p3count++;
      }

setdir();

 }






void init(void)
{

output_low(en0);
output_low(en1);
output_low(en2);
output_low(en3);

p1val[0]=p1[p1count]; //reads first values from matrix
p1count++;
p1val[1]=p1[p1count];
p1count++;
p1val[2]=p1[p1count];
p1count++;

p0val[0]=p0[p0count]; //reads first values from matrix
p0count++;
p0val[1]=p0[p0count];
p0count++;
p0val[2]=p0[p0count];
p0count++;

p3val[0]=p3[p3count];
p3count++;
p3val[1]=p3[p3count];
p3count++;
p3val[2]=p3[p3count];
p3count++;


//sets motor direction
setdir();
delay_ms(50);

}

void pulse(void)
{
int pulse,pwm;
   for (pulse=0;pulse<100;pulse++) //one pulse per ms switch on enx
   {
   if(p1val[0])
   {if(p1val[1]&&!input(sense5))output_high(en1);}
   else
   {if(p1val[1]) output_high(en1);}
     
     
     
     
 if(p0val[0])     
   {if(p0val[1]&&!input(sense4))output_high(en0);}
 else
   {if(p0val[1]&&!input(sense6))output_high(en0);}     
     
     
   if(p3val[1])
      {
      output_high(en3);
      }

   for (pwm=0;pwm<101;pwm++)  //check when to switch off enx
      {
      delay_us(5);
      if(pwm==p1val[1])
         {
         output_low(en1);
         }
      if(pwm==p0val[1])
         {
         output_low(en0);
         }
      if(pwm==p3val[1])
         {
         output_low(en3);
         }

      }

   }
}

main()
{
long time;
//int pulse, pwm;

set_tris_a(0b00000000);
set_tris_b(0b00111111);

init();
flashled();
flashled();
flashled();
delay_ms(4000);
flashled();


for (time=0;time<200;time++) //counts time in 1/10 s
   {
   pulse();
   renewvar(time);

   }

//wait for startbutton here
 flashled();

 while(!input(startbutton))
   {
   pulse();

   }

 flashled();

//the show starts here//


for (time=200;time<600;time++) //counts time in 1/10 s
   {
   pulse();
   renewvar(time);
   }

while(1) flashled();

}

MoritzW
Guest







input pins constantly high
PostPosted: Sat Sep 09, 2006 12:42 pm     Reply with quote

I should have mentioned that the switches pulled the pins to 7V rather than 5V, could this have damaged the pins? Aren't they high impedance when used as input pins?
Some pins first worked an then stopped working...

Crying or Very sad Moritz.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Sep 09, 2006 1:11 pm     Reply with quote

You probably destroyed those pins. Assuming your Vdd is +5v, the
data sheet says the maximum allowable voltage on a pin is +5.3v.
Quote:

15.0 ELECTRICAL CHARACTERISTICS
Absolute Maximum Ratings
Voltage on any pin with respect to VSS (except VDD, MCLR. and RA4) ...... -0.3 V to (VDD + 0.3 V)


You didn't connect your switches in the normal way. The industry
standard is to have a pull-up resistor to Vdd (4.7K, for example) on
the pin, and then when the switch closes, it will put Ground on the pin.

I'm not sure where this technique started of putting a pull-down resistor
on the pin, and then pulling it high with a voltage. This is definitely not
the industry standard way of doing it. I think it started with hobbyists,
who use the Basic Stamp. They just didn't know any better.

Also, another commonly used technique is to have a series resistor
in the circuit, so if the PIC pin is accidentally turned into a high-level
output pin and the switch is closed, then the pin won't be damaged.
This could happen during debugging, or during operation, if say, an
electrical glitch occurs.
See page 19 of the PicDem2-Plus board, where switch S3 goes to
pin RB0. They also have a capacitor in there. I don't use that.
http://ww1.microchip.com/downloads/en/DeviceDoc/51275b.pdf
MoritzW
Guest







Thank you
PostPosted: Sat Sep 09, 2006 2:28 pm     Reply with quote

Thanks for clarifying this. What an embarassing mistake Embarassed
All the best from London, Moritz.
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