Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Problem setting pic 16f690 for input

Status
Not open for further replies.

Ducados

Junior Member level 1
Joined
Aug 14, 2009
Messages
16
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Spain
Activity points
1,434
pic16f690 setup ports

I'm having a problem programming the 16f690, I need 2 inputs on porta and only RA1 is behaving correctly. The problem occurs if I configure RA2 or any other pin as input. The pin senses input OK, but keeps sensing input for another 2 or 3 seconds, in other words it doesn't stop sensing input when the input is removed.

I've tried various configurations with ANSEL, ANSELH and CM1CON0.

I'm just trying to move a motor back and forward depending on the input.

Here's a code example, If anyone can help I'll sure be grateful.


bsf STATUS,5
movlw 00h
movwf 87h
bcf STATUS,5


; SETUP PORTS A AND B TO INPUT

bsf STATUS,5
movlw 0xFF
movwf TRISA ; Make PortA all input
movlw 0xFF
movwf TRISB ; Make PortB all input

banksel ANSEL
movlw h'0'
movwf ANSEL
movlw h'0'
movwf ANSELH
bcf STATUS,5

loop

btfsc PORTA,1
goto bwd

btfsc PORTA,2
goto fwd

goto loop

fwd:
movlw b'000001' ; GO FORWARD
movwf 07h
goto loop

bwd:
movlw b'000100' ; GO BACKWARD
movwf 07h
goto loop
 

polymath

Full Member level 4
Joined
May 2, 2006
Messages
231
Helped
28
Reputation
56
Reaction score
4
Trophy points
1,298
Location
England
Activity points
3,115
16f690 programm examples

Hi

Have you any pull-down resistors on your input pins?

The PIC input pins are high impedance and will hold a HI charge for some time.

It is common (and good) practice to have the pins inactive HI and then switch them LO to GND/VSS.

You can then use the weak pull-up feature built into PortA of the 16F690 and save on hardware.

hope this helps Polymath
 

    Ducados

    Points: 2
    Helpful Answer Positive Rating

Ducados

Junior Member level 1
Joined
Aug 14, 2009
Messages
16
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Spain
Activity points
1,434
programmer 16f690

Thanks for the information because it can take days to plough through all the documentation.

When connected to the programmer via usb, everything goes swimmingly, but when I connect to an outside voltage source, the pic board goes instable and some pins start oscillating and I can't seem to identify an exact value to pitch the pulldown or pullup resistors as some pins start to behave with 5 or 6k, while others up to 47k.

Thanks
 

daviddlc

Full Member level 5
Joined
Feb 11, 2007
Messages
260
Helped
35
Reputation
70
Reaction score
9
Trophy points
1,298
Location
USA
Activity points
2,709
What do you have connected to the inputs ?
 

Ducados

Junior Member level 1
Joined
Aug 14, 2009
Messages
16
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Spain
Activity points
1,434
Well let me explain what I'm trying to do, I'm trying to build a verticle pendulum and the motor needs to drive when the pendulum starts to fall. so the inputs are to sense the pendulum movement. I realize I need to tie down the inputs but I also need RA1 and RA2 to behave identically or I will never achieve the equilibrium.

I originally thought I could leave the inputs "open" (LOL) and contact them to vdd when the pendulum starts to fall, then drive the motor. That's not possible because if the inputs are not tied down they oscillate and act as super sensitive touch controls and the cables act as aerials.

I'll investigate the resistor values today, thanks for the help you guys.
 

BobK

Member level 1
Joined
Mar 25, 2005
Messages
39
Helped
8
Reputation
16
Reaction score
3
Trophy points
1,288
Location
USA
Activity points
1,887
Hi,

You mentioned power supply issues. Do you have a .1uf cap across the power supply pins of your PIC? It also wouldn't hurt to have a 100uf cap across the power supply inputs also. The resistor values for pullups/pulldowns can be anything from 1K on up. I generally use 4.7K.

HTH,

BobK
 

    Ducados

    Points: 2
    Helpful Answer Positive Rating

Ducados

Junior Member level 1
Joined
Aug 14, 2009
Messages
16
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Spain
Activity points
1,434
I have resolved the issue by using RA3 and RA4 with 2 resistors (5.6k) to Vss, the pendulum works almost perfectly (it's a bit jerky). I still don't understand why RA1 and RA2 behave so differently but reading the documentation it's obvious they are different.

I have put a 3 second delay on startup to allow the pic to settle and give me time to balance the pendulum.

Today I'll fit the capacitor across the power input, thanks again you guys.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top