Shop OBEX P1 Docs P2 Docs Learn Events
help declaring nibble variables... — Parallax Forums

help declaring nibble variables...

kutalinelucaskutalinelucas Posts: 80
edited 2011-12-20 19:35 in BASIC Stamp
Hey guys, I was wondering if somebody could give me a little help

I have a few bs-2 modules controlling stepper motors; the problem is one of the pins remains consistantly high, and the circuit boards are already made up.

In my BS2 program, the coils of the motor are energised by sequencing through OUTA; pins p0->p3 BUT, pin3 is dead so I was wondering if theres a way I can declare a 4-bit variable but with pins P0,P1,P2,& P4?

saying that I guess I could change the step sequence to include a fifth pin and remove the dead pin from the module; so then could somebody help me out with how to declare 5 pins as a variable?, as opposed to declairing a nibble

Any response is greatly appriciated...

Cheers,

Comments

  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2011-12-20 16:28
    Hi, you would have to use bytes for the step values instead of the nibbles and create a mask for output

    Assuming P0,P1,P2 and P4
    mask=(OUTL & 224) + StepValue
    OUTL=mask
    
    

    224 ( %11100000 ) will preserve anything thats going on with P5,P6 and P7 should they be outputs.

    The step values in the data table will have to be re written to take into account the faulty pin, so for example %1010 will become %10010

    Jeff T.
  • kutalinelucaskutalinelucas Posts: 80
    edited 2011-12-20 16:47
    Fantasic...thanks loads

    Lucas.
  • kutalinelucaskutalinelucas Posts: 80
    edited 2011-12-20 17:05
    Sorry, just to check as I'm not with my equipment at the moment...can the OUTL statement be modified through masking? ie, would I now declare the coils output as

    mask = (OUTL & 224) + StepValue
    OUTL = mask

    Coils VAR OUTL

    Lucas.
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2011-12-20 17:18
    Hi, you would re write it as this
    mask=(Coils & 224) +StepValue
    Coils=mask
    

    and you are right when you say Coils Var OUTL , which I am assuming will replace Coils Var OUTA.

    Jeff T.

    EDIT: it also requires that the DIR register has P4 set to output in addition to P0,P1,P2
    EDIT2 : thinking about it you don't even need the mask variable
    Coils=(Coils & 224) + StepValue
    
  • kutalinelucaskutalinelucas Posts: 80
    edited 2011-12-20 17:55
    Great...I think that makes sense and I'm sure I'll work it out in the morning, but just in case does this look OK?

    Coils Var OUTL
    
    Setup:
      DIRA = %1111       
      DIRB = %0001
    
    Step1   DATA   %10100
    Step2   DATA   %00110
    Step3   DATA   %00011
    Step4   DATA   %10001
    [/SIZE][SIZE=2]Step_Rev:
    stpIdx = stpIdx + LastStep //NumSteps                 
    GOTO Do_Step[/SIZE]
    [SIZE=2]
    Do_Step:
    READ (Step1 + StpIdx), (Coils & 224)                         
    PAUSE stpDelay                                       
    RETURN   [/SIZE]
    [SIZE=2]
    


  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2011-12-20 18:30
    Hi, you don't have all the code there but I would think that your steps would be one contigous part of EEPROM with step0 being the first step, the remaining three would be indexed from the first, stepidx=0 stepidx=1 stepidx=2 and stepidx=3.
    I know the way you have it is fine and clarifies the steps so I guess its whatever you prefer.

    eg: from the Parallax example
    Steps  DATA    %0011, %0110, %1100, %1001 
    

    the READ will have to be done separately from the OUT, in the Parallax example Phase is used as the variable to hold the step value
    READ (Steps +stepidx),Phase
    Coils=(Coils & 224) + Phase
    

    I don't see a way to avoid the extra step at the moment
    .
    Jeff T.

    Another EDIT: looking at the DIRA and DIRB, if they remain as inputs then you will not need the mask of 224 so you could indeed just set the outputs from the READ values
    READ (Steps + stepidx),Coils
    PAUSE stpDelay
    
  • kutalinelucaskutalinelucas Posts: 80
    edited 2011-12-20 19:35
    fantastic...thanks for all your help

    Lucas.
Sign In or Register to comment.