MCU Detecting HIGH Wrong

Thread Starter

FroceMaster

Joined Jan 28, 2012
708
HI.
My MCU 16F18877
is attached as the schematic.
MCU detect the input as LOW when it should be HIGH,
When the end wire is floating,
When i connect the end to 0V it do not detect anything, but if held to +5V it detect as high,
Why ? is my resistor to big or ?
 

Attachments

spinnaker

Joined Oct 29, 2009
7,830
HI.
My MCU 16F18877
is attached as the schematic.
MCU detect the input as LOW when it should be HIGH,
When the end wire is floating,
When i connect the end to 0V it do not detect anything, but if held to +5V it detect as high,
Why ? is my resistor to big or ?
Can you please write in full complete sentences? This is very confusing. From the sounds of it you think should THE pin be high when it is floating? Is that correct? What makes you thing that?? Do you have internal pullups? If not then you don't know what value you might read if the input is floating. That is why they call it floating. :confused:


What does "do not detect anything" mean????? To me that is o Volts and it is doing exactly what it should be doing. What else would you expect?
 
Last edited:

Thread Starter

FroceMaster

Joined Jan 28, 2012
708
according to schematics i use a 47k ohm resistor to PULLUP.
it has allways been working, and a capasitor araound 100nf,
when input connects to ov, the MCU detect the "IO" as ov.= CORRECT.
When input connects to "float" the MCU detect still as 0v= WRONG.( Due to PULLUP)
 

Thread Starter

FroceMaster

Joined Jan 28, 2012
708
Sorry, wrong config of MCU
TRISA=1 = should have been all PORTA as input.
But if i added TRISA4=1; then my port worked correct.
 

Thread Starter

FroceMaster

Joined Jan 28, 2012
708
Next problem.
Have got the button to work partly.
The buttons connected to port C works like it should.
The buttons connected to port A will not work correct.

Attached both code and a schematic of the buttons with pullups and resistor.,
all resistor is 50k. and all CAP is 100 nf,
Code for pic is here.
C:
//
#include    "lcd1.c"
#include    "lcd2.c"
#include    "lcd3.c"
#include    "lcd4.c"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#pragma config FEXTOSC=XT
#pragma config RSTOSC=EXT1X
#pragma config CLKOUTEN=OFF
#pragma config CSWEN=ON
#pragma config FCMEN=ON
#pragma config MCLRE=ON
#pragma config PWRTE=OFF
#pragma config LPBOREN=OFF
#pragma config BOREN=ON
#pragma config BORV=LO
#pragma config ZCD=OFF
#pragma config PPS1WAY=ON
#pragma config STVREN=ON
#pragma config WDTCPS=WDTCPS_31
#pragma config WDTE=OFF
#pragma config WDTCWS=WDTCWS_7
#pragma config WDTCCS=SC
#pragma config WRT=OFF
#pragma config SCANE=available
#pragma config LVP=ON
#pragma config CP=OFF
#pragma config CPD=OFF

#define _XTAL_FREQ 4000000
#define FOSC 4000000L
#define back_light RB0
#define led1_on RE0
unsigned int secund,hour,minut,rain;
unsigned char timestr[6],minutstr[6],secstr[6],rainstr[6];
bit sec,rainincome;

static void interrupt isr(void)   // Here is interrupt function - the name is unimportant.
{
 
if(TMR1IF)             // Was this a timer overflow?
    {
          TMR1IF=0;        // Clear interrupt flag, ready for next
        TMR1L=0x00;
         TMR1H=0x80;     // If we set TMR1 to start at 0x8000 (32768), the TMR1 will overflow every 1 second
               
         sec=1;             // adds a sec.
    }
if (IOCAF4)  // if pulse on RA4.
{
    rainincome=1;
    IOCAF4=0;
 
}

}
         void setup(void)
{  
TRISA0=1; //set all A port in
TRISA1=1;
TRISA2=1;
TRISA3=1;
TRISA4=1;
TRISA5=1;
TRISA6=1;
TRISA7=1;

TRISB0=0; // port b0 = out
TRISB3=0; // PORT B3 = out
TRISB5=1;// CHANGE
TRISB6=1;
TRISB7=1;

TRISC0=1; // ALL C = IN
TRISC1=1;
TRISC2=1;
TRISC3=1;
TRISC4=1;
TRISC5=1;
TRISC6=1;
TRISC7=1;

TRISD0=0; // ALL D = out
TRISD1=0;
TRISD2=0;
TRISD3=0;
TRISD4=0;
TRISD5=0;
TRISD6=0;
TRISD7=0;

TRISE0=0; // E0 = out

WPUA6=1; // PULL UP no neeed have pullups.
WPUA7=1;
WPUC2=1;
WPUC3=1;
WPUC4=1;
WPUC5=1;
WPUC6=1;
WPUC7=1;
CCDEN=0; // disable current control.  not nessasary on input?

ANSELA=0b00000000; // set alle digital.
ANSELB=0b00000000;
ANSELC=0b00000000;
ANSELD=0b00000000;
ANSELE=0b0000;

//timer 1 setup
T1CS0=0; // 0110 = SOCS
T1CS1=1;
T1CS2=1;
T1CS3=0;
T1CKPS0=0; // no prescale
T1CKPS1=0;
nT1SYNC=1; // no sync
 
lcd1_init();  //lcd's init
lcd1_goto(0);
lcd2_init();
lcd2_goto(0);
lcd3_init();
lcd3_goto(0);
lcd4_init();
lcd4_goto(0);
}
      
 
void main (void)
{
     setup();
  
     lcd1_clear();
     lcd2_clear();
     lcd3_clear();
     lcd4_clear();
  
 
    back_light=1; // turn on light in LCD
 
    T1RD16=1; // turn on timer1
    TMR1ON=1; // turn on timer1
    T1GE=0; // gate allways count
    IOCIE=1; // enable IOC
   IOCAP4=1; // interrupt on pin RA4

 
 
 
   TMR1IE=1;  // enable interrupr for timer1
   GIE=1; // enable global interrupr
    PEIE=1;  // enable interrupr
 
    //led1_on=0; // kill the led to test
    lcd3_goto(0x00);
         lcd3_puts("Run : ");
      
     while (1)
     {
         if (RA6)//test only
         {
             lcd2_goto(0x00);
             lcd2_puts("NR 1 HIGH");
        }
         if (!RA6)
         {
             lcd2_goto(0x00);
             lcd2_puts("NR 1 LOW ");
        }
         if (RA7)
         {
             lcd2_goto(0x0a);
             lcd2_puts("NR 2 HIGH");
        }
         if (!RA7)
         {
             lcd2_goto(0x0a);
             lcd2_puts("NR 2 LOW ");
          
        }
         if (RC2)
         {
             lcd2_goto(0x40);
             lcd2_puts("NR 3 HIGH");
        }
         if (!RC2)
         {
             lcd2_goto(0x40);
             lcd2_puts("NR 3 LOW ");
        }
      
         if (RC3)
         {
             lcd2_goto(0x4a);
             lcd2_puts("NR 4 HIGH");
        }
         if (!RC3)
         {
             lcd2_goto(0x4a);
             lcd2_puts("NR 4 LOW ");
         }  //end test only
      
      
         if (rainincome==1) // if rain RA4 active.
         {
             rain++;
             lcd1_goto(0x00);
             utoa(rainstr,rain,10);
             lcd1_puts(rainstr);
             rainincome=0;
          
         }
      
         if (sec==1)
         {
             secund++;
             if (secund>=60)
             {
             secund=0;
             minut++;      // og plusser et minut
          
        if (minut>=60)  // hvis minut = 60
        {    minut=0;    // minut = 0
        hour++;        // og plusser en time.
     
        }
             }
                 
                 lcd3_goto(0x06);
         utoa(timestr, hour, 10);        // laver om til streng
    if (hour<10)lcd3_puts("0");        // hvis timer er under 10 skriv 0
        lcd3_puts(timestr);            // skriver timer
        lcd3_puts(":");
         utoa(minutstr, minut, 10);        // laver om til streng
    if (minut<10)lcd3_puts("0");        // hvis timer er under 10 skriv 0
        lcd3_puts(minutstr);            // skriver timer
        lcd3_puts(":");
          utoa(secstr,secund,10);
          if (secund<10)lcd3_puts("0");
          lcd3_puts(secstr);
       
      
         }
      
         sec=0;
         }
      
}
When i measure the voltage on pin RA6 or RA7 the voltage is 0v, should be 5v.
Like the PIN is holding it low ?
 

Attachments

JohnInTX

Joined Jun 26, 2012
4,787
FIXED, rerouted to port E. had 2 free pin there,
RA6+RA7 was used to Externclock and could not disable it.
Glad you got it working! FWIW, you can use RA6 and RA7 as general IO pins by specifying bits in CONFIG1. See pp 93 of the datasheet. Also, Microchip discourages setting/clearing TRIS bits one at a time. The resulting bsf/bcf instructions can be problematic when working on IO shared with certain peripherals. The preferred method is something like:

TRISB = 0bxxxxxxxx; // write register as a whole byte like you did with ANSEL.

But nothing succeeds like success so carry on!
 

be80be

Joined Jul 5, 2008
2,395
CLKOUTEN = 1
FEXTOSC
100 = OFF External Oscillator is disabled. RA7 is available as a general purpose I/O.

That should fix it to use RA6 ana RA7
 
Top