Shop OBEX P1 Docs P2 Docs Learn Events
!!!PWM Question!!! — Parallax Forums

!!!PWM Question!!!

gambrinogambrino Posts: 28
edited 2009-04-15 17:38 in Propeller 1
Hello forum , i would like to generate 3 PWM phase-shifted , can somebody guide me to generate them? i started from the PWM in the object exchange, file name ( Dedicated pwm generator) , and i changed the code to make wait for the cog but it's seems on the ocsilloscope on pin1 is ok , the Pin7 is not . my code is in the attachment .

Thank you for your help .

Post Edited (gambrino) : 4/15/2009 2:05:25 PM GMT

Comments

  • StefanL38StefanL38 Posts: 2,292
    edited 2009-04-07 12:19
    Hello gambrino,

    to me it is not clear want you want to do

    can you post a drawing with all three channels and how they should depend from each other ?

    best regards

    Stefan
  • gambrinogambrino Posts: 28
    edited 2009-04-07 15:57
    Hello Stefan ,
    i add to the first post the picture of the 3 signals .
    Thanks
  • Mike GreenMike Green Posts: 23,101
    edited 2009-04-07 16:08
    What sort of repetition rate are you talking about? What sort of pulse width range? Does the next sequence of pulses follow the first directly or is there a pause? Your drawing shows one pulse directly following the other. Is that what you want? This is the sort of information Stefan was requesting ... the exact timing needed.
  • gambrinogambrino Posts: 28
    edited 2009-04-07 16:14
    My goal is to spin a HDD motor , the HDD motor is 3 phases DC brushless motor , what do you recommand me to use ?
    Thanks
  • StefanL38StefanL38 Posts: 2,292
    edited 2009-04-07 17:07
    hello Gambrino,

    It is the same as always:
    As soon as more information is provided NEW solutions can be suggested

    To all other forum members especially the newbies:

    As you can see from this example it is EXTREMLY useful to provide quite a lot information
    in your posting. The members of THIS forum are ALL patient enough to read 10-50 well formatted lines of text
    and who doesn't will just surf to another thread

    As the ANN1-democode dedicates a cog to run it anyway you can use for example
    the code shown below which requires one cog too.

    In your picture the ON/OFF-Ratio for all 3 channels is 1:2
    Depending on the maximum frequency you can do this easily in SPIN

    For different frequencies simple change the resulting value of Delay

    ''Phase_shiftet_Pulse_Out
    
    CON
      _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000
    
      Bit_Pattern1 = %100
      Bit_Pattern2 = %010
      Bit_Pattern3 = %001
    
      WaitTicks = 385 'minimum waittime in SPIN 
      
    OBJ
      debug : "FullDuplexSerial_Configurable" '"FullDuplexSerial"
    
    Var
      long Delay
        
    PUB TestBitPattern
      DirA[noparse][[/noparse]20..22] := 7  ' set 3 bits as output 1 + 2 + 4 = 7
    
      OutA[noparse][[/noparse]20..22]  := 0
    
      Delay := WaitTicks 
      repeat
        WaitCnt(Delay + Cnt)
        OutA[noparse][[/noparse]20..22] := Bit_Pattern1 '3 bits in Bit_Pattern fit into the 3 bit definition 20..22   
    
        WaitCnt(Delay + Cnt)
        OutA[noparse][[/noparse]20..22] := Bit_Pattern2  
    
        WaitCnt(Delay + Cnt)
        OutA[noparse][[/noparse]20..22] := Bit_Pattern3    
    
    



    In SPIN there is a minimum-value for waitcnt it is 385 this gives a frequency of 16,8 kHz.
    If this isn't fast enough you can do the same in ASM

    best regards

    Stefan

    Post Edited (StefanL38) : 4/7/2009 5:30:16 PM GMT
  • TreeLabTreeLab Posts: 138
    edited 2009-04-07 17:08
    Gambrino, is this the sort of thing you are thinking of? The code compiles, but I do not expect that it will run the HDD motor without some feedback mechanism. Be careful not to fry the coils, and it will probably need to be slowed down after the 10-50 Hz loop terminates, but this should give you something to start with. If the motor does turn, see if the rotation frequency matches what is expected based on the driving frequency and the number of coil sets within the motor.

    Let me know how this turns out.

    Cheers!
    Paul Rowntree
    {{
        trial code to generate 3 phase-shifted outputs
        p. rowntree April 2009
        Use at own risk
    }}
    con
    CON _clkmode = xtal1 + pll16x
        _xinfreq = 5_000_000             
    
        apin = 8                    
        bpin = 9                    
        cpin = 10
    
    var
        long     High_Cnt
        long     Stack[noparse][[/noparse]20]     ' I have no idea if this is large enough
        long     Cog, Success
        
    pub Main  | f
    
       Success := (Cog := cognew( ThreeSpinWaves, @Stack) +1 )
        
        repeat
           repeat f from 10 to 50
             High_Cnt := CalcWaitCnt( f ) ' f is the cycle frequency, how many times to do an A-B-C sequence per second
    
             repeat 10                    ' apply this speed for 10 seconds
                waitcnt( clkfreq+cnt )
    
    
    
    pub CalcWaitCnt( Hz )
      result := clkfreq 
      if Hz <> 0
        result := clkfreq/(3*Hz)
    
    
    pub ThreeSpinWaves
    
    ' set the three pins to be outputs in this cog
        dira[noparse][[/noparse] apin ]~~
        dira[noparse][[/noparse] bpin ]~~
        dira[noparse][[/noparse] cpin ]~~
    
    ' continually output the waves
    ' changing the value of High_Cnt will change the cycle frequency
    '
        repeat
             outa[noparse][[/noparse] apin ]~~
             waitcnt( High_Cnt+cnt )
             outa[noparse][[/noparse] apin ]~
             
             outa[noparse][[/noparse] bpin ]~~
             waitcnt( High_Cnt+cnt )
             outa[noparse][[/noparse] bpin]~
             
             outa[noparse][[/noparse] cpin ]~~
             waitcnt( High_Cnt + cnt )
             outa[noparse][[/noparse] cpin ]~
    
    
  • JonnyMacJonnyMac Posts: 9,194
    edited 2009-04-14 15:21
    As an excise in writing PASM (I'm new to it) I wrote the attached program. In the spin section of the program all you have to do is change the value of phaseTime to change the speed of the motor. Of course, you'll need to know what the motor expects and there is a minimum timing that you need for the waitcnt instruction used, though I don't know what that is in PASM. The screen shot from a logic analyzer shows the program matches your initial diagram.
    807 x 632 - 144K
  • gambrinogambrino Posts: 28
    edited 2009-04-14 22:24
    Thank you Jonny. Is it dangerous to try this codes to a HDD motor without feedback mechanism?or i need to use An opto interrupter ?
  • JonnyMacJonnyMac Posts: 9,194
    edited 2009-04-14 23:53
    I don't know anything about running HDD motors; my goal was to produce the waveform you asked for at the top of the thread.
  • TreeLabTreeLab Posts: 138
    edited 2009-04-15 03:32
    Gambrino, my concern for the coils was that if you specify too slow a frequency (to start up the rotation for example) then the on time for a coild could be rlatively long, and this could lead to heating. I fried on HD motor, and you can feel the increased friction of the rotor.

    Cheers!
    Paul Rowntree
  • gambrinogambrino Posts: 28
    edited 2009-04-15 12:29
    i tried the code SPIN (which TreeLab wrote it) and the code PASM (which JonnyMac wrote it) , but the problem is that the HDD motor is not spinning one complete rotation , he's doing like 3 steps and sometime stop , what do you recommand to me ?
    Thank you in advance.


    Cheers!
  • JonnyMacJonnyMac Posts: 9,194
    edited 2009-04-15 14:14
    Is the waveform you specified correct? Both versions of the program produce it -- if the motor isn't spinning (no pun intended) then it may in fact want something else.
  • PropabilityPropability Posts: 142
    edited 2009-04-15 17:38
    I thought someone has written code to control this type of motor.

    OK looked and found this http://obex.parallax.com/objects/414/
Sign In or Register to comment.