Shiftout - shiftin question


Closed Thread
Results 1 to 9 of 9
  1. #1
    Join Date
    Apr 2010
    Location
    Sweden
    Posts
    10

    Question Shiftout - shiftin question

    Hello.
    I have a compass-module from Hitachi. I have had it connected to a Basic stamp with good result. Now i would like to run it with a PIC. But the program get stucked in the loop below. It assumes to send out (%1100) at shiftout and that is what it should get back at shiftin, but something went wrong here. I use PIC16F690 and I think I tryed to connect and program it to every pin in every thinkable combination.
    Do anyone have some idea who can help me?
    I am a new PIC-user.





    DO ' Status flag checking loop
    HIGH En: LOW En ' Measurement status command

    SHIFTOUT DinDout,clk,MSBFIRST,[Report\4]
    SHIFTIN DinDout,clk,MSBPOST,[Status\4] ' Get Status


    LOOP UNTIL s = Ready ' Exit loop when status is ready
    Last edited by Lasse1; - 3rd April 2010 at 23:12.

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Hi and welcome to the forum.

    When using MSBFIRST you have to
    Code:
    Include "modedefs.bas"
    Near the beginning of your code.

    It is also a good idea when posting a problem to post the whole code. The problem may not be where you think...

    If the above does not fix the problem tell us the model of the part you are connecting to.
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Apr 2010
    Location
    Sweden
    Posts
    10


    Did you find this post helpful? Yes | No

    Default

    Thank you very much for your quick respons.

    Here comes the whoole beguinning of my code, the rest is in progress and can absolute confuse you, so I don´t include it. I am absolut sure that the program stucks at the shiftout/shiftin-loop, and as you can see it starts and goes there very soon.
    As you can see I allready included the "modedefs.bas"-file. (I tried to attache my code in a box now, but dont know how so I copy it in below).

    The connected module is a Hitachi HM55B

    I tried a lot of ideas, pauses, changed chiftout-commands and things.

    I hope you or anyone can have some idea.

    Friendly regards / Lasse




    include "modedefs.bas"

    DinDout var portb.6 ' P6 transceives to/from Din/Dout
    Clk var portb.5 ' P5 sends pulses to HM55B's Clk
    En var portb.4 ' P4 controls HM55B's /EN(ABLE)
    rela var porta.0
    knapp var portb.6
    Reset CON %0000 ' Reset command for HM55B
    Measure CON %1000 ' Start measurement command
    Report CON %1100 ' Get status/axis values command
    Ready CON %1100 ' 11 -> Done, 00 -> no errors
    NegMask CON %1111100000000000 ' For 11-bit negative to 16-bits

    x VAR Word ' x-axis data
    y VAR Word ' y-axis data
    s VAR byte ' Status flags
    angle VAR Word ' Store angle measurement
    EE VAR byte
    Promangle VAR byte
    btnwk VAR Byte
    droj VAR byte
    define shift_pauseus 100

    HIGH rela
    droj = %0001


    goto huvud


    ' -----[ Subroutines ]--------------------------------------------------------
    compass:
    ' Compass module subroutine

    HIGH En: LOW En ' Send reset command to HM55B
    SHIFTOUT DinDout,clk,MSBFIRST,[Reset\4] 'OBS! jag har ersatt MSBFIRST med ,1,

    HIGH En: LOW En ' HM55B start measurement command
    SHIFTOUT DinDout,clk,MSBFIRST,[Measure\4] 'Ersatt MSBFIRST med ,1, även här
    s = 0 ' Clear previous status flags

    DO ' Status flag checking loop
    HIGH En: LOW En ' Measurement status command

    SHIFTOUT DinDout,clk,MSBFIRST,[Report\4]
    SHIFTIN DinDout,clk,MSBPOST,[Status\4] ' Get Status


    LOOP UNTIL s = Ready ' Exit loop when status is ready

    SHIFTIN DinDout,clk,MSBPOST,[x\11,y\11] ' Get x & y axis values

    HIGH En ' Disable module

    IF (y.BIT10 = 1) THEN y = y | NegMask ' Store 11-bits as signed word
    IF (x.BIT10 = 1) THEN x = x | NegMask ' Repeat for other axis
    return
    ' End subroutines-------------------------------------------------------

    huvud:
    DO ' Main loop

    tillb1:


    gosub compass ' Get x, and y values

    angle = x ATN -y ' Convert x and y to brads
    angle = angle */ 180 + 1 ' Convert brads to degrees

  4. #4
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Looks really close to the Basic Stamp code but one big difference when switching to PBP is many of the chips have analog built in.

    Just about every pin on the 690 has analog. So read through this
    http://www.picbasic.co.uk/forum/showthread.php?t=561
    and the data sheet.

    For the 690 to turn off the analog you will need to add this near the beginning.
    Code:
    CM1CON0 = 0  'Should turn off the Comparators
    CM2CON0 = 0
    ANSEL = 0       'Turns ADC off
    You may want to start off with a simple "blinky" program just to make sure the 690 is running correctly.
    Dave
    Always wear safety glasses while programming.

  5. #5
    Join Date
    Apr 2010
    Location
    Sweden
    Posts
    10


    Did you find this post helpful? Yes | No

    Default

    Thank you!
    It was really good information. I missed this analog thing. Now the PIC seems to work more logic, or moore like a stamp. But it still dont work with this compass-module. I think that I will start to test the same things I allready have done before I typed this new strip, and maybee et will work. If you don´t have any moore good information I maybee have missed?
    I get back here and tell how it was going.
    / Lasse

  6. #6
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    What version of PBP are you using?

    And you may want to look at the source code compared to your code. There was a couple things I think missing but have not had a chance to really pick it over.

    But first, is the PIC® running? Can you make an LED blink at an expected rate. Maybe it is not running at the correct speed?
    Dave
    Always wear safety glasses while programming.

  7. #7
    Join Date
    Apr 2010
    Location
    Sweden
    Posts
    10


    Did you find this post helpful? Yes | No

    Default

    Hello again.
    Thanks for your engagement!
    It is still dont working.

    I think that I have the latest and best PBP-version. I baught it last week.
    The code is allmost a copy from the sourse-code (made for Basic stamp where it works). And I checked the speed. It seems to me as it is correct. I light a led up and paused for 10 000. Checked, and it was 10 sek.
    I think I tryed everything. Now I am really drained of ideas.
    You are more than welcome to came up with new ideas.
    Friendly regards / Lasse
    Last edited by Lasse1; - 5th April 2010 at 14:54.

  8. #8
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Looking at your code again
    Code:
    SHIFTIN DinDout,clk,MSBPOST,[Status\4] ' Get Status
    
    LOOP UNTIL s = Ready ' Exit loop when status is ready
    I do not see a "Status" array variable defined but I do see a "s" variable.
    Dave
    Always wear safety glasses while programming.

  9. #9
    Join Date
    Apr 2010
    Location
    Sweden
    Posts
    10


    Did you find this post helpful? Yes | No

    Default

    Thanks again.
    I think that I tried it before. Type "SHIFTIN DinDout,clk,MSBPOST,[S\4]" instead of "status". But now I tried again. It dont work. Do you think that it is some different depending of witch pins I use? Do I need to try different pins every change I try?
    Friendly regards / Lasse

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