Continue to Site

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.

16f84 binary up/down counter

Status
Not open for further replies.

steelhacker

Newbie level 4
Joined
Jun 22, 2010
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
TNUS
Activity points
1,326
hello programmers, i am in need of some code for a 16f84.

I need a 7 bit up / down counter that is stepped by rotary encoder on porta input pins. and displayed in binary (led's) on portb output pins . i need it to start at 0 and count to 127 (0000000-1111111) then reset back to 0. i also need it to down count if instructed by the rotary encoder. .5 second delay between steps would be nice since it will be controlled by a slow human.

eventually i would like to add to the project and have that binary number converted to decimal on an LCD. but that is not important right now.

I know you guys probably get hit up all the time for this and i feel bad for asking but my brain is about to explode from trying to learn asm. i have succeeded in learning the absolute basics but it gets a little discouraging after a while. I have built myself a development board just for the task and have no problem getting the pic to count on its own but am having trouble with inputs.

Any help in this project would be GREATLY appreciated. Thanks!

Mod Fragrance is a loser
 

Hi,

Its not difficult to get a counter running - but first you need to check that your Encoders output is Pic 5v compatible - do you have any details on it ?

You might be able to connect it direct to a port or you might need some additional components.

If you have a counter running already then you are half way there.

The simplest way to read a 'slow' input is like this,
Wlth lets say PortB ,0 connected to the now compatible encoder

bankse1 TRISB
movlw b, '00000001' ;set PortB,0 to Input
TRISB
banksel PORTB

btfss PORTB,0 ;test port B, 0 if it is a high from the encoder then count +1
goto nocount ; not high so go out

incf COUNT,F ; increment the counter
; optional - now wait /test for encoder to go low


See how you go, if you get stuck then post your Code so we can see where things are going wrong.
 

The encoder i have is a pull from a radio, i haven't found a data sheet on it but i have experimented with it on my scope. It's pulses are out of phase from each other .
the pic would have to read the edge of the two outputs to determine direction.

is there a rotary encoder that is easier for me to integrate into the circuit given my lack of experience?

I am probably wrong, so please correct me.

i studied your sample code, it seems that the pic would check for a 0 and increment or check for a 1 and skip to decrement ...?????

i am assuming that this route would not work for this style rotary encoder.

I really appreciate you taking your time to help someone out. It is a reflection of your character! Thanks
 

Hi,

Sounds like you have an Incremental Encoder as shown here.
https://en.wikipedia.org/wiki/Rotary_encoder

As you are only reading it very slowly then using the simple method I described should work ok.
If you were reading at a higher speed there are other ways, but they are a bit too complicated for now.

The instruction BTFSS is complemented by the BTFSC so you can test and control for either high or low conditions.
Look in the pic16F84 Datasheet. towards the back is the full Instruction Set.

So you need to feed each phase into its own pic pin and then read each port and then decode the results to a displayable result.
However my level of Encoders is low and I do not know if the one you have can feed the pic directly, but if you have scoped it I assume you can make it send out 5v signals ?
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top