Using XOR to convert a Graycode Encoder

(instructions, reset, WDT, specifications...) PIC17Cxx, PIC18Fxxx

Re: Using XOR to convert a Graycode Encoder

Postby Roche » Thu Sep 19, 2019 6:12 pm

PM sent
Roche
 
Posts: 72
Joined: Fri Jul 11, 2014 12:35 pm
PIC experience: Professional 5+ years with MCHP products

Re: Using XOR to convert a Graycode Encoder

Postby GettinBetter » Sun Sep 29, 2019 1:53 pm

So I've identified a couple of things....
If I disconnect pin 4 (bit3) from the input because it is always on (well it only dims, which the PIC still sees as on) I can get the low numbers down to zero, and the high numbers up to 512 (I was expecting 512 i.e. half of 1024).
As far as the skipping & jumping numbers go, I found that stopping the spindle at the number it started to reverse and connecting pin 4 gave me the missing numbers.
So all that makes sense and I believe there is an electrical fault in the encoder so I will connect the other one to check. I wonder how likely is it that they will both have the same fault!

So then the reason it isn't going up to 1024 is that pin 10 (bit9), isn't being recognised as an input to the PIC!
Not great but it is progress.
Regards
Les
History teaches us that history doesn't teach us.
User avatar
GettinBetter
 
Posts: 43
Joined: Wed Jun 06, 2018 8:48 pm

Re: Using XOR to convert a Graycode Encoder

Postby GettinBetter » Sun Sep 29, 2019 5:38 pm

Sorted :D

The other encoder worked fine, which will have do for now. The reason for the low reading was the fact that while messing about with the code I removed or left out
the left shift for the second bit of Port C
Code: Select all
    G_PortC_0 = IO_RC0_PORT;                    //Pin RC0 Single bit Binary Input (sends to righter most bit0)
        // 00000001 what I think would be the result assuming all pins are high
    G_PortC_1 = IO_RC1_PORT<<1;              //shift RC1bit to bit1
       // 00000010 what I think would be the result assuming all pins are high

So when or'ing them the result was the same.
All great now... lovely incrementing values through 360 degrees, from 0 up to 1023 (i.e. 0 - 1023 = 1024 values).

Did what you guys suggested, slowed right down, proved each part, used the debugger.

Regards
Les
History teaches us that history doesn't teach us.
User avatar
GettinBetter
 
Posts: 43
Joined: Wed Jun 06, 2018 8:48 pm

Re: Using XOR to convert a Graycode Encoder

Postby Roche » Fri Oct 04, 2019 1:34 pm

Well done for perseverance...
Roche
 
Posts: 72
Joined: Fri Jul 11, 2014 12:35 pm
PIC experience: Professional 5+ years with MCHP products

Re: Using XOR to convert a Graycode Encoder

Postby steve1418 » Tue Jan 10, 2023 5:20 pm

GettinBetter wrote:
Roche wrote:This sort of got me intrigued. I only work in assembly - this seems to work OK:
Code: Select all
;------------------------------------------------------------------------------
;gray
; Converts 8 bit gray code to binary
; can almost certainly be optimised - takes about 91 +/- instructions to execute
; Uses 3 8 bit registers
;      input      ; input gray code
;      output      ; output binary
;      count       ; loop count
;------------------------------------------------------------------------------
gray:                  ; 8 bit gray to binary converter
   movlw   0x08         ; initialise loop count
   movwf   count

   clrf   output         ; clear the output

   btfsc   input, 7      ; test most significant bit
   bsf      output, 7

gray10:
   decfsz   count         ; loop until done
   bra      grayloop

   rlncf   input         ; preserve the input
   rlncf   output         ; final rotation
   return

grayloop:
   rlncf   input         ; all operations are on the most significant bit of input and output
   btfss   output, 7      ; which are rotated to evaluate each bit.
   bra      grayloop10
   rlncf   output
   btfss   input, 7
   bsf      output, 7
   bra      gray10
grayloop10:
   rlncf   output
   btfsc   input, 7
   bsf      output, 7
   bra      gray10
;------------------------------------------------------------------------------


I'm sure there are ways to improve it...

Regards,

Roche


That's interesting, is this something you've just created, and I assume you tested it? I don't know anything about assembly, but am aware it's possible to insert it into a 'C' file. The encoder I'm using is a 10bit so am using a 16bit var to concatenate both ports pins. Trouble is, the output is binary so there's still work to do on each value to convert to hex.

I took onboard what you guys are saying, I'll make an effort to learn to use the simulator and/or debugging options and break it into smaller parts proving each section.

It's still bugging me though, as to why the encoder has blank spots!

Regards
Les




i have the same quotation why the encoder has blank spots!
steve1418
 
Posts: 4
Joined: Tue Jan 10, 2023 5:08 pm

Previous

Return to 16-Bit Core

Who is online

Users browsing this forum: No registered users and 8 guests

cron