PDA

View Full Version : Problem with a program...



hawk72501
- 9th September 2005, 18:38
I have made the following program:


INCLUDE "modedefs.bas"

TRISB=%11111111
TRISC=%00001010

W1 VAR WORD
W2 VAR WORD
loop:
Count PORTB.7,3000,W1
Count PORTB.6,3000,W2

SerOut2 PORTC.0,84,["TIMES COUNTSa:",DEC W1,13,10]
SerOut2 PORTC.0,84,["TIMES COUNTSb:",DEC W2,13,10]

GoTo loop


In pins B.7 and B.6 i have connected the 2 channels of an incremental quadrate encoder.The problem is that channel A(PortB.7) shows the right pulses but channel B(PortB.6) shows always 0 !I am sure that i have made the right connections .Do you know what goes wrong?

Thank you in advance.Don't hesitate to answer me.I am desperate!

mister_e
- 9th September 2005, 22:45
how you connect the encoder? Pull-up, PUll-down resistor are there??

Ingvar
- 12th September 2005, 08:37
Are you rotating the encoder for all six seconds? If you only rotate it while counting pulses on PortB.7, you will miss the pulses on portB.6.

Acetronics2
- 12th September 2005, 08:46
You're right, ingvar ...

as PBP can't do two things at a time ...it reads Portb.7 for 3 seconds and THEN Portb.6 for the 3 following seconds ...

No hope this way ...

Alain

hawk72501
- 12th September 2005, 10:57
Ingavr and acetronics thanks for replying!Have you any idea how to make it working to count simultaneously the 2 channels?

Mister_e thanks for replying.If i use a pull-up resistor of 2.7K is that ok?Should i turn the internal pull-ups off?

Acetronics2
- 12th September 2005, 14:05
Hi Hawk,

another thread is still open on this subject ... SEARCH function !!!

11 results ... no less !!!

Alain

mister_e
- 12th September 2005, 20:25
Ingavr and acetronics thanks for replying!Have you any idea how to make it working to count simultaneously the 2 channels?

COUNT is not design to count on 2 pin at the time. You can use Interrupt on PORTB change. Once in the interrupt routine, read the whole PORTB, keep only the upper bit and see wich is LOW, increment a counter variable and TADA.

OR without interrupt routine, poll the interrupt flag and do the same as above.

HTH