In SX Microcontrollers, SX/B Compiler and SX-Key Tool, _BPM_ wrote: I just basically added variables to cover the extra encoders. The problem I ran into is that when all is said and done, you have too many variables. I thought about some method of data storage, but don't see how that is different from declaring variables. I might be able to eliminate 6 variables, but I don't see any way to do more. I think the problem is, I need to maintain a WORD cound for every encoder. thats six word variables. on Top of everything else. Right now its set up for 3 encoders. If I add 1 more byte variable I am over my ram. My fear isn't that it can't be done, unless done in a way that removes the simplicity of sxb. I would prefer to keep it fairly simple. And am not going to bother with assembly. [code] ' ------------------------------------------------------------------------- ' Device Settings ' ------------------------------------------------------------------------- DEVICE SX28, OSC4MHZ, TURBO, STACKX, OPTIONX FREQ 4_000_000 ID "ENCODER" ' ------------------------------------------------------------------------- ' IO Pins ' ------------------------------------------------------------------------- EncPort3 VAR RC ' encoder port EncPort2 VAR RB ' encoder port TRIS_Enc3 VAR TRIS_C TRIS_Enc2 VAR TRIS_B ' ------------------------------------------------------------------------- ' Constants ' ------------------------------------------------------------------------- ' ------------------------------------------------------------------------- ' Variables ' ------------------------------------------------------------------------- encCheck VAR Byte 'MaxVal VAR Byte enc1old VAR Byte ' previous encoder bits enc2old VAR Byte ' previous encoder bits enc3old VAR Byte ' previous encoder bits 'enc4old VAR Byte ' previous encoder bits 'enc5old VAR Byte ' previous encoder bits 'enc6old VAR Byte ' previous encoder bits enc1 VAR Byte ' new encoder bits enc2 VAR Byte ' new encoder bits enc3 VAR Byte ' new encoder bits 'enc4 VAR Byte ' new encoder bits 'enc5 VAR Byte ' new encoder bits 'enc6 VAR Byte ' new encoder bits encCount1 VAR Byte ' encoder value encCount2 VAR Byte ' encoder value encCount3 VAR Byte ' encoder value 'encCount4 VAR Byte ' encoder value 'encCount5 VAR Byte ' encoder value 'encCount6 VAR Byte ' encoder value change1 VAR Byte change2 VAR Byte change3 VAR Byte 'change4 VAR Byte 'change5 VAR Byte 'change6 VAR Byte Pot1 VAR Word Pot2 VAR Word Pot3 VAR Word 'Pot4 VAR Word 'Pot5 VAR Word 'Pot6 VAR Word '-------------------------------------------------------------------------- ' Interrupt Start ' ------------------------------------------------------------------------- INTERRUPT GOTO Handle_Int ' ------------------------------------------------------------------------- ' Subroutines / Jump Table ' ------------------------------------------------------------------------- ProcessPot1 SUB ' ------------------------------------------------------------------------- ' Interrupt Code ' ------------------------------------------------------------------------- Handle_Int: ' Runs every 64 uS @ 4 MHz (no prescaler) enc1 = EncPort2 & %00000011 ' get econder bits enc2 = EncPort2 & %00001100 enc3 = EncPort2 & %00110000 'enc4 = EncPort2 & %00001100 'enc5 = EncPort2 & %00110000 'enc6 = EncPort2 & %11000000 change1 = enc1old XOR enc1 ' test for change1, put result into change1 change2 = enc2old XOR enc2 ' test for change1, put result into change1 change3 = enc3old XOR enc3 ' test for change1, put result into change1 'change4 = enc4old XOR enc4 ' test for change1, put result into change1 'change5 = enc5old XOR enc5 ' test for change1, put result into change1 'change6 = enc6old XOR enc6 ' test for change1, put result into change1 GoSub ProcessPot1 ISR_Exit: RETURNINT ' ========================================================================= PROGRAM Start ' ========================================================================= ' ------------------------------------------------------------------------- ' Program Code ' ------------------------------------------------------------------------- Start: encCount1 = 8 enc1 = EncPort2 & %00000011 ' read encoder pos enc1old = enc1 ' copy Toggle RB.7 Pot1 = 32768 OPTION = $88 ' interrupt, no prescaler Main: Watch Pot1, 16, UDEC GoTo Main ' ------------------------------------------------------------------------- ' Subroutine Code ' ------------------------------------------------------------------------- ProcessPot1: IF change1 > 0 THEN ' change1? enc1old = enc1old << 1 ' adjust old bits enc1old = enc1old XOR enc1 ' test direction IF enc1old.1 = 1 THEN IF encCount1 < 12 THEN ' if max, no change1 INC encCount1 If encCount1 = 12 Then Toggle RC.0 encCount1 = 8 Inc Pot1 ' increase value Endif Endif Else IF encCount1 > 4 THEN ' if 0, no change1 DEC encCount1 ' decrease value If encCount1 = 4 Then Toggle RC.0 encCount1 = 8 DEC Pot1 ' decrease value Endif Endif Endif enc1old = enc1 ' save last input Endif Return [/code] ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=147541#m282083 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)