32-bit Quadrature Counter With Serial Interface


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2006
    Location
    INDIA
    Posts
    89

    Default 32-bit Quadrature Counter With Serial Interface

    Can enybody convert this code into picbasic using SHIFTIN ? I dont know ASM
    LS7366R is a 32-bit CMOS counter, with direct interface for quadrature clocks from incremental encoders.For communications with microprocessors or microcontrollers, it provides a 4-wire SPI/MICROWIRE bus.The four standard bus I/Os are SS/, SCK, MISO and MOSI.

    Code:
    ;Sample routines for PIC18CXXX interface
    /************************************************************************************/
    ;Initialize PIC18Cxxx portc in LS7366 compatible SPI
    ;Setup: master mode, SCK idle low, SDI/SDO datashift on high to low transition of SCK
    ;SS/ assertion/deassertion made with direct manipulation of RA5
    ;Initialize portc
    CLRF PORTC                ;Clear portc
    CLRF LATC                  ;Clear data latches
    MOVLW 0x10               ;RC4 is input, RC3 & RC5 are outputs
    MOVWF TRISC             ;RC3=CLK, RC4=SDI, RC5=SDO
    BCF TRISA, 5               ;RA5=output
    BSF PORTA, 5              ;RA5=SS/=high
    CLRF SSPSTAT             ;SMP=0 => SDI data sampled at mid-data
    BSF SSPSTAT, CKE        ;CKE=1 => data shifts on active to idle SCK transitions
    MOVLW 0x21                ;SPI mode initialization data
    MOVWF SSPCON           ;Master mode, CLK/16, CKP=0 => CLK idles low
                                     ;data shifted on active to idle CLK edge
    /********************************************************************/
                                            ; WR_MDR0
    BSF PORTA, 5                      ;SS/=high
    BCF PORTA, 5                      ;SS/=low
    MOVLW 0x88                       ;LS7366 WR_MDR0 command
    MOVWF SSPBUF                   ;Transmit command byte
    LOOP1 BTFSS SSPSTAT, BF    ;Transmission complete with BF flag set?
    BRA LOOP1                           ;No, check again
    MOVF SSPBUF, W                 ;Dummy read to clear BF flag.
    MOVLW 0xA3                       ;MDR0 data:fck/2, synchronous index. index=rcntr, x4
    MOVWF SSPBUF                   ;Transmit data
    LOOP2 BTFSS SSPSTAT, BF    ;BF set?
    BRA LOOP2                          ;No, check again
    BSF PORTA, 5                      ;SS/=high
    /********************************************************************/
                                            ;RD_MDR0
    BSF PORTA, 5                      ;SS/=high
    BCF PORTA, 5                      ;SS/=low
    MOVLW 0x48                       ;LS7366 RD_MDR0 command
    MOVWF SSPBUF                   ;Transmit command byte
    LOOP1 BTFSS SSPSTAT, BF    ;BF flag set?
    BRA LOOP1                          ;No, check again
    MOVWF SSPBUF                   ;Send dummy byte to generate clock & receive data
    LOOP2 BTFSS SSPSTAT, BF    ;BF flag set?
    BRA LOOP2                          ;No, check again
    MOVF SSPBUF, W                 ;Recieved data in WREG.
    MOVWF RXDATA                   ;Save received data in RAM
    BSF PORTA, 5                      ;SS/=high
    Datasheet: http://www.lsicsi.com/pdfs/Data_Sheets/LS7366R.pdf

    .

  2. #2
    Join Date
    Mar 2006
    Location
    INDIA
    Posts
    89


    Did you find this post helpful? Yes | No

    Default

    I wrote this code but not working

    Code:
    DEFINE OSC 20
    INCLUDE "MODEDEFS.BAS"
    INCLUDE "MY_LCD.bas
    CMCON = 7
    ADCON1 = 15
    CVRCON = %00000000 'CVref turned off
    
    OUTPUT PORTA.5
    OUTPUT PORTC.3
    OUTPUT PORTC.5
    INPUT PORTC.4
    
    Symbol HC_latch = PORTA.5   
    symbol HC_SDI = PORTC.4  ;RC4=SDI
    symbol HC_SDO = PORTC.5   ;RC5=SDO
    SYMBOL HC_Clk = PORTC.3  ;RC3=CLK
    
    RD_MDR0 var word
    WR_MDR0 var word
    
    pause 1000
    
    start:
            HC_Latch = 0
            shiftin HC_SDI, HC_Clk, MSBFIRST,[RD_MDR0]        
            pauseus 1
            HC_Latch = 1 
    
            Lcdout $FE,1
            lcdout "Count =", DEC5 RD_MDR0
            
            pause 200
            goto start
    .

  3. #3
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by precision View Post
    I wrote this code but not working.
    And this is for which PIC?

  4. #4
    Join Date
    Mar 2006
    Location
    INDIA
    Posts
    89


    Did you find this post helpful? Yes | No

    Default

    for PIC 18F4550

    .

  5. #5
    Join Date
    May 2007
    Posts
    65


    Did you find this post helpful? Yes | No

    Cool

    I don't ASM. BTW, A good choice you may consider is to get a cheap and powerfull PIC18Fxx31: 2331 2431 4331 or 4431, wich provide a powerfull hardware Quadrature Encoder Interface (QEI) onchip module, with a confortable wide set of interrupts focused on presition and fast rotary decoding. Hope this pics help you.
    "Beethoven had his critics too, see if you can name 3 of them"

Similar Threads

  1. Replies: 33
    Last Post: - 19th March 2010, 03:02
  2. 32 bit counter
    By Charles Linquis in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 19th December 2007, 15:10
  3. How to set TMRO & TMR3 as Counter?.
    By NatureTech in forum mel PIC BASIC Pro
    Replies: 21
    Last Post: - 18th May 2007, 08:52
  4. Microcontroller with 2 way paging application problem
    By oneohthree in forum mel PIC BASIC Pro
    Replies: 30
    Last Post: - 20th April 2007, 17:27
  5. USART interrupt not interrupting right
    By Morpheus in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 6th March 2005, 01:07

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts