Shop OBEX P1 Docs P2 Docs Learn Events
The BS2 and the BS2sx with the V2X compass module from PNI... — Parallax Forums

The BS2 and the BS2sx with the V2X compass module from PNI...

denodeno Posts: 242
edited 2005-05-28 21:15 in BASIC Stamp
Hello, again to fellow Stampers...

I have got an interesting problem, that has developed by switching a BS2 stamp for a BS2sx stamp to increase the programming speed of my satellite tracker.· I have been using the V2X compass module for years now with the BS2 with very good results.· However, I wanted to improve preformance with the SX.· In other words, faster azmuth correction speed of the dish as the boat drifts around on its anchor.

I have changed the BAUD to match the SX, and changed the timing issues associated with SHIFTIN command.· Now for the tricky part of explaning the problem.· The V2X outputs to the stamp a 16 bit word of which only 9 bits are used to give an azmuth reading of 0 degrees to 359 degrees.

With the SX stamp only, when the output (using· DEBUG and also·a LCD on the sat tracker) reaches 255 degrees, (which is 8 bits), the output from the SX jumps to 10 bits because the 10th bit is a 1, bypassing the 9th bit all together.· It only takes 9 bits of data to generate a number to 359. The other 7 bits of data of the 16 bit word are supposed to be 0. What this means is all readings above 255 degrees are 512 (degrees) to high.· So I had to program in an:··· IF rawHeading > 255 THEN
································································· ··rawHeading = rawHeading - 512
·································································ENDIF
This addition of code makes the sat tracker work just fine...

So the 64 dollar question is...why does the regular old BS2 work without the IF..THEN and the SX has to have the IF..THEN in place to output a azmuth heading from 0 degrees to 359 degrees.

Any thoughts on this..

Deno

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-05-28 14:33
    While not likely, is is possible that the V2X can't keep up with the speed of the BS2sx SHIFTIN/SHIFTOUT commands? I doubt it, but based on the information you've provided, I can't think of anything else. What other changes did you make to the code? If you were only using DEBUG for your output, then the BS2 program should have run unmodified (other than the $STAMP directive change) on the BS2sx.

    As we frequently suggest, posting your code (if possible) is always the best way to get help -- sometimes we're all too close to our own code to see problems that others might detect easily.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • denodeno Posts: 242
    edited 2005-05-28 16:01
    Hello again...first let me pass along what the V2X compass manual says about the Serial Clock Pin (SCLK).

    I slave mode, SCLK is an input, and data must be read from the V2X when SCLK is high (data is valid on the rising edge of SCLK). The maximum rate for clocking out data is 1 Mhz. There is no minimum time that the data is valid, so you can wait as long as you want before it is polled again (unless it is RESET before the next time it is polled again).

    In slave mode, the V2X must receive 16 falling and 16 rising edges of the clock (to clock out the data before it is polled again (unless it is RESET before the next time it is polled again).

    OK..now here is the code I have used successfully for a long time using the BS2. This is the SUB ROUTINE that I call for a compass heading:

    '===V2X COMPASS ROUTINE__BS2_stamp=====================
    V2Xcompass:
    OUT8 = 1 'P/C...must be logic hi for V2X to start calculations
    OUT10 = 1 'SS ...must be logic hi for V2x to start calculations
    PULSOUT 8, 2000 'pulse P/C low for 4 msec...BS2
    hold_1:
    IF IN9 = 0 THEN hold_1 'EOC waits until calculation is finished
    PAUSE 2 'wait 2 msec
    OUT10 = 0 'SS
    'starting the CLOCK pin(OUT14) high seems to produce the full 16 pulses that are required by the V2X...
    OUT14 = 1 'added 15may04 'start clock pin at high level
    PAUSE 2 'wait 2 msec
    SHIFTIN 15, 14, MSBPRE, [noparse][[/noparse]rawHeading_1\16] 'msbpre
    OUT10 = 1 'SS
    RETURN
    'I get a good heading every itineration with the above code.

    '===V2X COMPASS ROUTINE__BS2SX=====================
    V2Xcompass:
    OUT8 = 1 'P/C...must be logic hi for V2X to start calculations
    OUT10 = 1 'SS ...must be logic hi for V2x to start calculations
    PULSOUT 8, 8000 'pulse P/C low for 6.4 msec...BS2sx
    hold_1:
    IF IN9 = 0 THEN hold_1 'EOC waits until calculation is finished
    PAUSE 2 'wait 2 msec
    OUT10 = 0 'SS
    'starting the CLOCK PIN high OUT14) as above in the BS2 code...
    OUT14 = 1 'added 15may04 'start clock pin at high level
    PAUSE 2 'wait 2 msec
    SHIFTIN 15, 14, MSBPRE, [noparse][[/noparse]rawHeading_1\17] 'msbpre
    'now I have to change the number of bits to shift in to 17, 16 won't work.
    OUT10 = 1 'SS
    IF rawheading_1 > 255 THEN 'for some reason...Transistion form an 8 bit number (255)
    rawheading_1 = rawHeading_1 - 512 '>to a 9 bit number (256 to 359) doesn't work with the
    ENDIF '>BS2sx. The rawheading binary output jumps to a 10 bit
    '>number (larger then 359). So a subtraction of 2^9 or
    '> 512 is necessary to keep the compass heading between
    '>0 degrees and 359 degrees. The bs2 doesn't do this.
    RETURN
    The more I play around with this, I think the BS2SX is just to fast for the V2X compass module. What do you think?

    Deno
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-05-28 16:14
    One of the problems that you may be having is that you're attempting to start the clock at a high level. Perhaps speed is letting you get away with this in the BS2 and not in the BS2sx. When SHIFTIN is loaded, the clock pin is made an output low, then the clocking his low-high-low. Since there is no minimum clock speed you could solve this by writing·a small subroutine that clocks the bits in the way the V2X wants it done (I did this with the PlayStation controller).

    If you can point me to the data sheet I will write a subroutine for you.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • denodeno Posts: 242
    edited 2005-05-28 16:17
    Hello again....When I typed up the above post, I did have everything spaced in an easy to read format with the right indents, etc. But it would appear that when I sent it off to cyperspace, it lost it's spaces, and indents...sorry as now it appears to be heard to read...hope that all readers can muddle your way thru the code....

    Deno
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-05-28 16:21
    It's best to use the "Post Reply" box to maintain formatting. Another thing I would strongly suggest is that you read our "The Elements of PBASIC Style" information that's included in the help file. Using internal names like OUT14, etc., is a very quick way to introduce programming errors -- and it makes one's program very difficult for others to follow. Give your pins meaninful names and you can cut down on comments as well as programming errors.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-05-28 16:27
    After our exchange I remember that Rogic Arrick had used that compass with his BS2-powered ARobot.· Perhaps his code will lend some insites -- you might want to give it a try on your BS2sx and see if it works.· I don't have the compass to test, so this may be the best help I can offeer.

    http://www.robotics.com/arobot/vector.html

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • denodeno Posts: 242
    edited 2005-05-28 16:39
    Jon..you are right about using names for pin assignments, which I do use in coding now, but this code is old, written in 1999 and I haven't gotten around to rewriting it. I just went along with the old coding scheme when I work on it.

    I tried to get the complete web address for the the V2X compass module data sheet (small book), but my internet services provider seems to be playing around with my very slow dial up connection, anyway, the web site address is www.precisionnav.com and please don't confuse there new compass module (V2Xe) with the one I am using (V2X).

    And, thanks for the tip on using the POST REPLY box instead of this QUICK REPLY box.

    Deno
  • Tracy AllenTracy Allen Posts: 6,658
    edited 2005-05-28 16:48
    Hi Deno,

    The V2X data sheet I have states that the minimum pulse width for the P/C low pulse should be 10 milliseconds (You have 4 ms on your BS2 and 6.4ms on your BS2sx). Also, the pause from EOC high to SS\ low should also be 10 milliseconds minimum (You have 2 ms). It may be that a 10ms pause is also required between SS\ low and the first clocking of the SHIFTOUT command. You have 2ms there. I don't know why the V2x needs those extra delays, or how making them longer could resolve the problem you have in going to the faster BS2sx.

    The SHIFTIN command should only have to shift 16 bits, but your program is shifting 17. The data sheet is not too clear, but it looks like the V2x outputs its first data bit _after_ the first clock pulse, so the appropriate command would be,
    SHIFTIN 15, 14, MSBPOST, [noparse][[/noparse]rawHeading_1\16] '
    msbpost
    The Stamp manual says the range of "bits" is o 1 to 16 and I'm not sure what happens when bits=17. The reason you had to go to 17 is because of setting the clock line high to begin with. As Jon explained, the first thing the SHIFTIN command does is to set that line low, and that should clock out the first data bit, the one you are picking up with msbpre.

    The SHIFTOUT command in operation pulses the clock line high and then low, waits for a few microseconds, then reads the data line, then another clock pulse, read the data line, and so on. The clock is always low when it reads the state of the data line. The V2x moves from one bit to the next on the 1->0 transition of the clock line, so if the V2x is slow in outputting those bits, the Stamp might misread them. However, even the BS2sx SHIFTOUT command is working at less than 50 khertz, while the V2x claims that it can work at up to 1mhz. So a timing delay there seems unlikely. As Jon says, it is possible to bit bang the SHIFT and try it at a much lower speed.

    P.S., here is a link to a data sheet from Jameco: www.jameco.com/wcsstore/Jameco/Products/ProdDS/126703.PDF

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com

    Post Edited (Tracy Allen) : 5/28/2005 5:00:47 PM GMT
  • denodeno Posts: 242
    edited 2005-05-28 21:11
    Hello Tracy,

    When I first started building this Sat Tracker with the V2X, I did try the SHIFTIN 15, 14, MSBPOST, [noparse][[/noparse]rawHeading_1\16] which resulted in every other itineration being %1111111111111111 from the V2X. By playing around, and starting the clock pulse high before the SHIFTIN, and then using 16 clock pulses, I was able to get every itineration of the V2Xcompass sub routine to output a valid azmuth heading, so I left it at that.

    Now with the SX, I find by experimentation, that again I must start the clock pulse high and now use 17 clock pulses to output a valid azmuth angle every pass thru the sub routine. Otherwise with only 16 clock pulses every other pass is
    %1111111111111111. The code above for the SX does work quite well, and response time for azmuth correction of the dish is faster, but again, I can't seem to figure out why the stamp, (if it is the SX) would jump over that 9th bit which is need to give an angle between 256 degrees and 359 degrees, and show the 10th bit as a 1?? It must be a timing issue.

    Looping to bit bang would slow down the SX to a point where I should just stay with the BS2, don't you think??

    Thanks to all who have read and contributed...

    Deno
  • denodeno Posts: 242
    edited 2005-05-28 21:15
    PS to Tracy...I forgot to mention that as far as the pulse widths mentioned in your post, I started out with the recommended pulse widths, but in an effort to speed up the calculations of the V2X, I started reducing the times until the V2X started hanging up, and then I backed up a little until it started working again and left it there. I did the same thing with the SX.

    Thank again....Deno
Sign In or Register to comment.