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

Port A as an Input not working
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
Sid2286



Joined: 12 Aug 2010
Posts: 119

View user's profile Send private message

Port A as an Input not working
PostPosted: Sun Apr 03, 2011 10:02 pm     Reply with quote

Hi,

I'm trying to get an input on port A and once there is an input i'm switching on the led...but some how it is not working on the hardware, but working on Proteus. The code is as follows:
Code:

#include <16f1936.h>
#device ICD=TRUE
#fuses HS,NOLVP
#use delay (clock=40000000)

LED_ON()
{
         output_high(PIN_B5);
         output_high(PIN_B6);
         output_high(PIN_B7);
         delay_ms(1000);
         output_low(Pin_B5);
         output_low(Pin_B6);
         output_low(Pin_B7);
         delay_ms(1000);
}

void main()
{
    while(1)
    {
          if(input(pin_A1)==1)
          {
                  while(1)
                   {
                       LED_ON();
                        if(input(pin_A1)==0)
                        {
                             output_low(Pin_B7);
                             output_low(Pin_B5);
                             output_low(Pin_B6);
                             break;
                         }
                    }
           
           }

     }

}


It works on Pin B1 but not on A1.
I tried to disable the analog input, but i don't know if I was right.
please help.

Thank you,
Sid
bkamen



Joined: 07 Jan 2004
Posts: 1615
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Sun Apr 03, 2011 10:33 pm     Reply with quote

1: Proteus has been shown to be generally unreliable....

However, for you purposes, you might be ok. Always hold proteus in doubt.

Next, keep in mind, PortB has weak pullups that portA typically does not.
Is the thing controlling the state to your PortA pin totem pole? (can drive high and low) or does it just hold low?

If it does not provide a high-low state, you'll need a pull-up resistor on the pin you're using. 4.7K is a good start to test with... from there, adjust to your needs.

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
Sid2286



Joined: 12 Aug 2010
Posts: 119

View user's profile Send private message

PostPosted: Sun Apr 03, 2011 10:43 pm     Reply with quote

thank bkamen

I did try to pull up the pin using 10K resistor, but it still did not work.
should I try using the 4.7K or is there any other problem.

Regards,
Sid
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Apr 03, 2011 10:54 pm     Reply with quote

Quote:
#use delay (clock=40000000)

The 16F1936 data sheet says the highest frequency of operation is
32 MHz in EC oscillator mode. The highest freq for HS mode is 20 MHz:
Quote:

TABLE 29-1: CLOCK OSCILLATOR TIMING REQUIREMENTS

http://ww1.microchip.com/downloads/en/DeviceDoc/41364D.pdf

What is your compiler version ?

Post a description of the external circuit connected to pin A1.
bkamen



Joined: 07 Jan 2004
Posts: 1615
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Sun Apr 03, 2011 10:57 pm     Reply with quote

Sid2286 wrote:
thank bkamen

I did try to pull up the pin using 10K resistor, but it still did not work.
should I try using the 4.7K or is there any other problem.


Well what is driving the PIC's input pin?

Not a user of proteus, I don't know if it matters, but you can't run that part at 40MHz. 32MHz is the max speed according to the datasheet.
I'm surprised the compiler doesn't complain.

Next, do you need the ICD=TRUE? (Does proteus require this? if you're simulating, you shouldn't. But again, I don't use proteus, so I don't know).
If you're debugging that's fine - can you confirm your program runs at all? (how about blinking the LED at startup to see if it does anything.)

Lastly, there is an "analog/digital" setting for PORTA pints (see datasheet and ANSELA) while the function input_pin()

The compiler probably sets that for you, but it's always good to double check.

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
bkamen



Joined: 07 Jan 2004
Posts: 1615
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Sun Apr 03, 2011 11:13 pm     Reply with quote

PCM programmer wrote:
Quote:
#use delay (clock=40000000)

The 16F1936 data sheet says the highest frequency of operation is
32 MHz in EC oscillator mode. The highest freq for HS mode is 20 MHz:
Quote:

TABLE 29-1: CLOCK OSCILLATOR TIMING REQUIREMENTS

http://ww1.microchip.com/downloads/en/DeviceDoc/41364D.pdf

What is your compiler version ?

Post a description of the external circuit connected to pin A1.


Although HS and a clock of 32M works in MPLAB's SIM...

I would drop back (for testing) to HS and a clock of 8MHz.

BTW, If I set this up and stimulate this in MPSIM using PCM 4.119, the flow works as written.

Also, if you want to use a 32MHz clock via external oscillator, the HS fused should be changed to ECL.

Cheers,

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
bkamen



Joined: 07 Jan 2004
Posts: 1615
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Sun Apr 03, 2011 11:17 pm     Reply with quote

Oh,

My working code looks like this:

Code:
#include <16f1936.h>
#device ICD=TRUE
#fuses HS,PLL,NOLVP
#use delay (clock=32M)

void LED_ON(void) {
   output_high(PIN_B5);
   output_high(PIN_B6);
   output_high(PIN_B7);
   delay_ms(1000);
   output_low(Pin_B5);
   output_low(Pin_B6);
   output_low(Pin_B7);
   delay_ms(1000);
}

void main() {
   while(1) {
      if(input(pin_A1)==1) {
         while(1) {
            LED_ON();
            if(input(pin_A1)==0) {
               output_low(Pin_B7);
               output_low(Pin_B5);
               output_low(Pin_B6);
               break;
            }
         }
      }
   }
}

_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
Sid2286



Joined: 12 Aug 2010
Posts: 119

View user's profile Send private message

PostPosted: Mon Apr 04, 2011 12:00 am     Reply with quote

Thanks PCM and bkamen

My hardware has nothing complicated.
I have used a comparator LM339 and the output is given to the Pin A1 of PIC16F139. Compiler version is 4.

Once the output of comparator goes high the LED should blink. moreover the output of the comparator has a pull up resistor of 3.3K(as per LM339 datasheet).

also as per bkamen, though port B has a weak internal pull ups, I never pulled them up using a program, but still it was working with pin_B1.

sid
temtronic



Joined: 01 Jul 2010
Posts: 9229
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Apr 04, 2011 5:09 am     Reply with quote

First, I assume a VDD of 5 volts.

LM339 must have pullup and 3k3 seems fine.Easy to check with DVM

Check the datasheet for other peripherals that use PortA and disable them.ADC typically is the defaulted use of I/O pins.

If you used MPLAB to compile code and burn PIC , did you set build configuation to 'release' from 'debug' AND recompile ?
Sid2286



Joined: 12 Aug 2010
Posts: 119

View user's profile Send private message

PostPosted: Mon Apr 04, 2011 5:58 am     Reply with quote

Yes I did that.. While using MPLAB! If i use B1 instead of A1 it works fine.. I don't know what else I need to add in the above code!
temtronic



Joined: 01 Jul 2010
Posts: 9229
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Apr 04, 2011 6:18 am     Reply with quote

I just downloaded the datasheet for the 1936, seems Port A.1 is also used for analog,comparator and LCD uses !
Sounds like you haven't disabled those, to use that pin exclusively for digital I/O.
I'd check the listing to see that the proper bits in the correct registers are being set.If not it might be a compiler bug,in which case you may have to manually do the correct setup.The header file might be wrong,I don't have it or the PIC so I can't help further.
The fact the software works on PortB on real hardware seems to indicate a 'setup' or bit setting problem,the listig will show !
Sid2286



Joined: 12 Aug 2010
Posts: 119

View user's profile Send private message

PostPosted: Mon Apr 04, 2011 6:28 am     Reply with quote

Thanks temtronics!
can u help me on how to disable the rest of the multiplexed applications except I/O.
bkamen



Joined: 07 Jan 2004
Posts: 1615
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Mon Apr 04, 2011 6:37 am     Reply with quote

temtronic wrote:
I just downloaded the datasheet for the 1936, seems Port A.1 is also used for analog,comparator and LCD uses !
Sounds like you haven't disabled those, to use that pin exclusively for digital I/O.
I'd check the listing to see that the proper bits in the correct registers are being set.If not it might be a compiler bug,in which case you may have to manually do the correct setup.The header file might be wrong,I don't have it or the PIC so I can't help further.
The fact the software works on PortB on real hardware seems to indicate a 'setup' or bit setting problem,the listig will show !


I bet it's a proteus problem. I simulated it last night with MPSIM and it worked as expected.

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
temtronic



Joined: 01 Jul 2010
Posts: 9229
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Apr 04, 2011 8:06 am     Reply with quote

The OP says it worked in hardware with PORTB, so I hope he's NOT using still in problematic Proteus !
If so, well, he's out of luck, I do NOT use ANY simulators.NONE simulate the real world,at least none of them that I've seen in the past 30+ years.

The OP should post his complete program and the setup error will probably show up real fast.
Sid2286



Joined: 12 Aug 2010
Posts: 119

View user's profile Send private message

PostPosted: Mon Apr 04, 2011 8:13 am     Reply with quote

Bkamen you are getting me all wrong! I wrote the program with A1 and simulated with proteus it worked and so I tried it on hardware where it did not work.
Now since it did not work I replaced A1 with B1 and it worked on hardware.. ..Strange! I guess there is some program issue.
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