In SX Microcontrollers, SX/B Compiler and SX-Key Tool, robotnerd007 wrote: I am storing the encoder value in a word variable; however, i need more space than a word variable can provide. I really need to count up to around 90,000 pulses. I was wondering how to do this is. I would not mind sacrificing some resolution to get a greater range of distance that i could count. I dont really know how to modify the code i have to only detect 2 of the edge changes instead of the 4 that it does now. Is there another easier way to do this that i dont know about or am overlooking? Here is a copy of the code that i am using now. DEVICE SX28, OSCHS3, TURBO, STACKX, OPTIONX FREQ 50_000_000 ID "ENCODER" ' ------------------------------------------------------------------------- ' IO Pins ' ------------------------------------------------------------------------- EncPort VAR RA ' encoder port TRIS_Enc VAR TRIS_A ' ------------------------------------------------------------------------- ' Constants ' ------------------------------------------------------------------------- MaxVal CON 100 EndVal con 17000 SlowVal con EndVal-2000 ' ------------------------------------------------------------------------- ' Variables ' ------------------------------------------------------------------------- encCheck VAR byte encOld VAR byte ' previous encoder bits encNew VAR byte ' new encoder bits encValue VAR word ' encoder value tmpB3 VAR Byte ' ------------------------------------------------------------------------- INTERRUPT ' ------------------------------------------------------------------------- ' Runs every 64 uS @ 4 MHz (no prescaler) ISR_Start: encNew = EncPort & %00000011 ' get econder bits tmpB3 = encOld XOR encNew ' test for change IF tmpB3 > 0 THEN ' change? encOld = encOld << 1 ' adjust old bits encOld = encOld XOR encNew ' test direction IF encOld.1 = 1 THEN IF encValue < EndVal THEN ' if max, no change INC encValue ' increase value ENDIF ELSE IF encValue > 0 THEN ' if 0, no change DEC encValue ' decrease value ENDIF ENDIF encOld = encNew ' save last input ENDIF ISR_Exit: RETURNINT ' ========================================================================= PROGRAM Start ' ========================================================================= ' ------------------------------------------------------------------------- ' Subroutine Declarations ' ------------------------------------------------------------------------- ' ------------------------------------------------------------------------- ' Program Code ' ------------------------------------------------------------------------- Start: encNew = EncPort & %00000011 ' read encoder pos encOld = encNew ' copy encValue = 0 ' clear value OPTION = $88 ' interrupt, no prescaler ' ========================================================================= low rc.7 main: ' clear value Do If encValue = EndVal then goto stop 'tells BS2 when to slow down and when to stop a robot IF encValue = SlowVal then goto slowdown loop slowdown: high RC.7 goto main stop: low RC.7 end ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=259381#m263278 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2008 (http://www.dotNetBB.com)