Shop OBEX P1 Docs P2 Docs Learn Events
Assembly - copy state one's pin to the more pins — Parallax Forums

Assembly - copy state one's pin to the more pins

LafetLafet Posts: 23
edited 2007-07-18 09:41 in Propeller 1
How it is possible in assembly copy state one's pin to the more pins?
E.g . (Pin1 , Pin2, Pin3) = Pin1.

Thanks

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-07-15 22:06
    You use some instruction to test for the state you want and set either the C or Z flag from that. You then use the MUXxx instruction to set the bits you want in the OUTA register like this:
         mov    temp,ina                       ' Copy INA to a temporary location
         test     temp,#%00010   wz    ' Test pin 1 and set Z accordingly
         muxz  outa,#%10100             ' Copy the Z flag to pins 2 and 4
    
    


    You need a temporary location for INA because that's a read-only location and
    can't be used in the destination field of an instruction.
  • LafetLafet Posts: 23
    edited 2007-07-16 21:54
    I am beginner and I don't know implement your code. I'd needed modify file "pwm.spin", to was signal PWM on two pins at the same time. I need PWM for drive 3 phase BLDC motor.
    '' File: pwm.spin
    '' Generates a pwm signal.
    
    CON
    
     _clkmode = xtal1 + pll16x
     _xinfreq = 5_000_000
    
    VAR
    
      long duty, period, pin
      byte cog
    
    PUB start(ioPin, tHigh, tCycle) : okay
    {{Start cog and PWM signal
        ioPin - selects I/O pin for sending the signal
        tHigh - number of clock ticks high
        tLow  - number of clock ticks low
    }}
        pin    := ioPin
        duty   := tHigh
        period := tCycle
    
        okay   := cog := cognew(@entry, @duty)
    
    PUB stop
    ''Stop cog and PWM signal
        waitpeq(0, |< pin, 0)
        dira[noparse][[/noparse]pin] := 0  
        if cog > 0
          cogstop(cog)
    
    PUB update(tHigh, tCycle)
        '' tHigh and tCycle should be in terms of clock ticks
        duty := tHigh
        period := tCycle
        
    DAT
    
    entry                   movi   ctra,#%00100_000
                            movd   ctra,#0
    
                            mov     addr, par
                            add     addr, #8
                            rdword  _pin, addr
                            movs    ctra,_pin
    
                            mov     temp, #1
                            shl     temp,_pin
                            or      dira,temp
    
                            mov     frqa,#1
    
                            mov     addr, par
                            add     addr, #4 
                            rdlong  _cntadd, addr
                            
                            mov     cntacc,cnt
                            add     cntacc,_cntadd
    
    :loop                   waitcnt cntacc,_cntadd
                            rdlong  _duty,par
                            mov     temp, par       '
                            add     temp, #1        '
                            rdlong  _duty, temp     '
                            neg     phsa,_duty
                            jmp     #:loop
    
    cntacc                  res     1
    _duty                   res     1
    _cntadd                 res     1
    _pin                    res     1
    addr                    res     1
    temp                    res     1
    
    



    Thanks Lafet
  • Mike GreenMike Green Posts: 23,101
    edited 2007-07-16 22:21
    This is a different problem than what you asked. Please be more careful in the future.

    You can't just modify pwm.spin to produce two outputs at the same time since pwm uses the
    cog's built-in counters and each counter has only one output of each polarity (if you change to
    differential mode which won't help you here). I don't understand why you can't use the same
    signal for more than one driver. You'll need drivers (MOSFETs or Bipolar transistors) for the motor
    windings anyway. The Propeller can only output about 20ma max from an I/O pin.

    How about posting your schematic and some information about the motors?
  • LafetLafet Posts: 23
    edited 2007-07-17 05:10
    I am sorry for my bad English. To the MOSFET driver is on line state from
    Propeller 6 signal conductors. 3 for upper side and 3 for lower side H-bridge.
    At the same time are excited always one upper and one lower MOSFET. PWM is need
    for generate step by step on pin (P0+P5, P0+P4, P4+P2, P3+P2, P3+P1, P1+P5). I
    attach flow diagram.

    Thank you very much.
  • StefanL38StefanL38 Posts: 2,292
    edited 2007-07-17 07:40
    Hello Lafet,

    if you could write in German please do so

    i'm good in englisch and i'm german.

    I'm very sorry, but i did not understand at all what you
    wrote in the last posting

    What kind of motor are you using?
    a steppermotor?
    if yes
    type unipolar or type bipolar?
    how many coils does the steppermotor have?
    what step-mode do you want to use
    fullstep?, halfstep?

    if it is another kind of motor
    what kind of motor

    if you could post the REAL circuit minimum of the 3-Phase MOSFET-Driver and the H-Bridge and Motor
    with EVERY SINGLE WIRE would be very great

    I'm not sure do you mean you have to switch P0..P5 in the following pattern?

    like the table showing the low-high-status of the IO-PIN ?

    P0 P1 P2 P3 P4 P5 P6
    1.) H L L L H
    2.) H L L H L
    3.) L H L H L
    4.) H L H L L
    5.) H L L L H

    what is the maximum frequency that you need ?

    if you need only some kiloHertz you don't need PWM.SPIN
    this could be programmed even in SPIN

    so please write something about what this motor is doing in the end

    is it only switched on and then running for hours in the same direction at one speed?

    does it make a lot of starts and stops and changing the direction?

    if you post enough information about your complete project it is much eaysier to find a
    REAL GOOD FITTING solution

    best regards

    Stefan
  • LafetLafet Posts: 23
    edited 2007-07-17 09:12
    I use small 3 phase BLDC motor. Brushless DC motor.
    Sequence:

    P5....P0

    100001 - step 1
    010001 - step 2
    010100 - step 3
    001100 - step 4
    001010 - step 5
    100010 - step 6

    I need PWM min. 8 kHz, rather but 10 kHz.
    I think, that the SPIN be slow, better is Assembly code.
    Motor - 42 steps on turn => 7 full sequence.
    MOSFET driver - HIP4086:

    http://www.intersil.com/cda/deviceinfo/0,1477,HIP4086,00.html#data

    Need all-purpose controller to 20000 rpm. I don't know, how much will starts and changes directions.
    I don't have circuit diagram, I use basic connection.

    Thank you very much, Lafet
  • StefanL38StefanL38 Posts: 2,292
    edited 2007-07-17 10:35
    Hello Lafet,

    this should be very easy in assembly-code

    at the moment i have not much time
    so i gave you just a short description of the principle

    that's just loading one of six 6-bit pattern to the OUTA-Register
    waiting some time and then load the next 6bit-pattern

    to get an all-purpose 0-20.000 rpm controller the waiting-time
    should be variable

    this could be done by a HUB-RAM-variable

    you have one cog with a SPIN-Program to change rotationspeed=waiting-time

    this SPIN-Prg launches a second cog with an assemblerdriver

    in the coginitstatement you have to pass the adress of this HUB-RAM-variable to the ASM-Prg

    in the ASM-Prg you can read HUB-RAM with the rdlong-command

    the ASM-Prg is switching the bitpattern from step 1 to step 2 ... step 6 and then starts again with
    the bitpattern for step 1

    so this is just a few mov-, waitcnt-, jmp-commands in assembly-code

    you could start with the LED-blink example from the manual
    the manual example toggle one bit by using the xor-command
    you have to use the MUXZ-command for changing Bit P0..P5 of the OUTA-register

    this as first tips how you can solve it

    maybe the next few days i have time (in the evening) to write some example-code

    best regards

    Stefan
  • Graham StablerGraham Stabler Posts: 2,507
    edited 2007-07-17 21:15
    Forgive me if I am off base but...

    I would have thought the PWM should be ANDed with the phase sequence so it acts like a DC motor with variable voltage input. The commutation is like the brushes, the PWM like the voltage supply.

    If you try to just change the times between the phases that will not do the same thing. Your suggestion Stefan is more like driving it as a stepper motor but varying the pulse frequency.

    Lafet,

    It seems the best thing would be to spend some time studying assembly on the propeller.

    Graham
  • LafetLafet Posts: 23
    edited 2007-07-17 22:05
    Thank you for help.
    By the regulation BLDC motors is need adjust PWM and commutation. PWM adjusts mean value voltage on winding. Change driving sequence is dependent on information from magnetic sensor (position rotor). I need have on two pins at the same time PWM. I would like use modification object file "PWM.SPIN", only I need copy state APIN from register CTRA into two pins according to the mask driving sequence.

    :loop                 waitcnt cntacc,_cntadd
                            rdlong  _duty,par
                            mov     temp, par       '
                            add     temp, #1        '
                            rdlong  _duty, temp     '
                            neg     phsa,_duty
    
    ***  here copy state APIN to the 2 other pins ***
    
                            jmp     #:loop
    
    



    Lafet
  • Graham StablerGraham Stabler Posts: 2,507
    edited 2007-07-17 22:20
    You would be better off not trying to use the counters to produe the PWM because APIN is being driven by hard ware and you want to try and make other pins follow it but you also have to check which pins should follow it so there is a delay between the two.

    Instead produce it directly using assembly and waitcnt.

    Have a look at this thread:

    http://forums.parallax.com/showthread.php?p=647408

    Step 3 happens to show some code for PWM. Step 2 describes bitmasks.

    Graham
  • StefanL38StefanL38 Posts: 2,292
    edited 2007-07-18 08:15
    Hello Lafet,

    does this mean you REALLY need PWM = variying ON/OFF-Time of the signal?
    AND changing the frequency?


    the waitcnt-command in assembly works the following way

    you setup the "waiting" initially

    DAT
    {Toggle P16 5 cycles}
    
                          mov      Time, cnt        'store actual value of counter in "variable" called Time
                          add      Time, #9         'add a minimum of 9 (Cycles) to this value because the counter goes on counting up while 
                                                    'the add-command and the waitcnt-command is beeing exectuted
                                                    'and the value of var Time must be still AHEAD of the actual countervalue. 
                                                    'otherwise the waitcnt-command will wait for 53 Seconds until he reaches again this value
                                                    '= counter will count to maxvalue=2^32 turn to 0 and count up to the value
    
    :loop                 waitcnt  Time, Delay      'now this waitcnt-command waits until the counter reaches the value of variable "Time" 
                                                    'then the value of variable Delay is ADDED to variable Time
                                                    'this means at the next waitcnt-command the Prop will wait until the counter will reach the value
                                                    'of variable Time. Which was already setup at the last waitcnt-command !
                                                    'this make it possible to do a different amount of commands inside a loop, that have a different runtime
                                                    'but the START of next loop will be exact after the SAME timedifference (comming from the "variable" Delay)        
                          xor      outa, Pin        
                          djnz     Cycles, #:loop    
    
    Pin      long         |< 16                     
    Delay    long         15_000_000                
    Cycles   long         10
    Time                  res 1                     
    
    
    




    in this example changing the ON/OFF-Time inside one Cycle is not included

    for changing ON/OFF-Time you have to use two waitcnt-command like in the example 3 datatransfer.spin
    from graham in his thread

    http://forums.parallax.com/forums/default.aspx?f=25&m=187621

    do you know the details how the commutation must be changed depending on the feedbacksensor?

    best regarrds

    Stefan
  • Graham StablerGraham Stabler Posts: 2,507
    edited 2007-07-18 09:41
    Stefan,

    If you have three hall sensors these can almost act like the brushes of a DC motor, they determine the commutation (change from one state to the next) while the PWM determines the power in and will change the speed of the motor which will then increase the commutation speed automatically. Of course with sensorless control you use the back EMF to provide the commutation info. So rather than driving the rate at which the state changes you alter the power in the states and let the motor itself increase the state change rate, clear as mud?

    I was looking at making an electric unicyle, I was considering making a big brushless disk motor myself to which I would attach a normal encoder with an index pulse. That would allow me to essentially treat the motor as a DC motor, the control from the tilt sensor would just control the PWM and direction and another cog would control the commutation based on the encoder. Easy to say but more work to do!

    Graham
Sign In or Register to comment.