1 Continuous MCPWM at a time


Closed Thread
Results 1 to 40 of 47

Hybrid View

  1. #1
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: 1 Continuous MCPWM at a time

    Hi,
    What is this encoder you're using? Is it some kind of resolver with digital output? And why does the seqeunce change (not just reversing) when you reverese the direction of rotation? Or am I missunderstanding?

    If knowing the intended direction of rotation isn't enough then I currently don't see how it's going to be done since the sequence is the same in both directions.

    Are you sure you don't have a second output on that encoder? This looks like a low resolution sine-wave to me which leads me to belive what you have is some kind of SIN/COS resolver with a digital interface. (?) Do you have a datasheet you can link to?

    The MCPWM module on the '4431 has dedicated faultinputs which can be setup to shut down the PWM. Either until the fault-input is cleared (good for cycle-by-cycle current limit) or untill a fault reset of the module is performed. Perhaps you could use that to stop the commutation. Otherwise you'll simply need to check the state of the switch as often as you need to - or use an external interrupt.

    /Henrik.

  2. #2
    Join Date
    Jul 2011
    Posts
    29


    Did you find this post helpful? Yes | No

    Default Re: 1 Continuous MCPWM at a time

    Hello,

    Sorry for the late reply, it is nothing complicated like that. it is just 6 optical switches mounted on the rotor therefore 6 inputs on my pic that gives me a truth table. (in function of the inputs ON or OFF, I know what phases of the motor I need to turn ON/OFF).
    For the clockwise rotation, it goes like this :
    000000
    000001
    000011
    000111
    001111
    011111
    111111
    111110
    111100
    etc

    and for anti clockwise it goes like this :
    000000
    100000
    110000
    111000
    111100
    111110
    111111
    111110
    111100
    etc, as you can see for anti clockwise I am getting the same values but it is not the same phases ON, I need to turn ON (for 360 mechanical degrees, I have 3 times these 12 "cases").


    Otherwise you'll simply need to check the state of the switch as often as you need to
    Can you give me a simple example ?

    Many thanks again for your answers

  3. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: 1 Continuous MCPWM at a time

    Hi,
    OK, if I get this right it should be enough to remember the previous state of the input.

    FWD: 0,1,3,7,15,31,63,62,60,56,48,32
    REV: 0,32,48,56,60,62,63,31,15,7,3,1

    If the current state is 15 and the previous state is 7 we're going forward, if the current state is 15 and the previous state is 31 we're going backwards.
    Code:
    EncoderState = PortA
    If EncoderState <> OldState THEN  ' Don't run commutation code if shaft hasn't moved. 
     
    Select Case EncoderState
     
    Case 0
      If OldState = 32 THEN  'We're moving FWD
      'Code for FWD
      ELSE
      'Code foe REV
      ENDIF
    
    Case 1
      If OldState = 0 THEN   'We're moving forward
      'Code for FWD
      ELSE
      'Code for REV
      ENDIF
     
    Case 3
      If OldState = 1 THEN   'We're moving forward
      'Code for FWD
      ELSE
      'Code for REV
      ENDIF
     
    ' And so on for all twelve states.
     
    OldState = EncoderState  'Remember current state.
    ENDIF
    As for the switch, I just mean that if you don't think it's enough to check at the beginning of the loop you'll have to check it as often as you think is neccessary, for example in each case statement. Personally I think that it's enought to check it one time in the main loop since only one of the Case blocks will get executed anyway. But I may have missed something.

  4. #4
    Join Date
    Jul 2011
    Posts
    29


    Did you find this post helpful? Yes | No

    Default Re: 1 Continuous MCPWM at a time

    mhhh that sounds great !!! this will work I think ! I have a switch that tells me to go forward or backward I can add it to this !
    yes effectively the switch at the top of the loop in "case code" is enough.
    However when I start my pic it won't move, will it ? because no previous state ? or am I missing something ?

  5. #5
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: 1 Continuous MCPWM at a time

    That's correct, since the shaft can be in any location on powerup you need to establish the proper encoderstate at bootup and then initialise OldState to the apropriate value depending on the desired direction of rotation - before entering the Main routine. You could do it with something like this but please doublecheck the sequence here, I'm not sure I've got it right.
    Code:
    'Get index of current encoderstate, Temp will be 0-11
    Lookdown EncoderState, [0,1,3,7,15,31,63,62,60,56,48,32],Temp
     
    'Now initialise OldState to correct value depending on desired direction of rotation.
    If DesiredDirection = Forward THEN
      Lookup Temp, [32,0,1,3,7,15,31,63,62,60,56,48], OldState
    ELSE
      LookUp Temp, [1,0,7,15,31,63,62,60,56,48,32], OldState
    EndIf

  6. #6
    Join Date
    Jul 2011
    Posts
    29


    Did you find this post helpful? Yes | No

    Default Re: 1 Continuous MCPWM at a time

    thx i'll keep try that in the morning =)

  7. #7
    Join Date
    Jul 2011
    Posts
    29


    Did you find this post helpful? Yes | No

    Default Re: 1 Continuous MCPWM at a time

    actually this can't work because my reverse values are :
    0, 32, 48, 60, 62, 63, 62, 60, 56, 48, 32....
    I'm getting desesperate with these switches...

  8. #8
    Join Date
    Jul 2011
    Posts
    29


    Did you find this post helpful? Yes | No

    Default Re: 1 Continuous MCPWM at a time

    fwd values : 0, 1, 3, 7, 15, 31, 63, 62, 60, 56, 48, 32
    reverse values : 0, 32, 48, 60, 62, 63, 62, 60, 56, 48, 32

    I have 2 truth tables with switches to turn on/off for these values.
    Now i have a pot and a switch start/stop and a switch fwd/reverse..
    Now we should not be able to change the sequence commutation if the pot is not 0 so I did a little code like this :


    Code:
    Direction VAR bit
    direction = 0
    
    Main:
    
            encoderstate1 = PORTA
            
            GoSub GetADC
            
            If ADRESH = 0 Then 'value of the pot stored in ADRESH
                If ADRESL = 0 Then ''value of the pot stored in ADRESH
                    direction = PORTE.1 'switch for direction
                EndIf
            EndIf
    
    if encoderstate = 0  then
    'switches turn ON/OFF
    elseif encoderstate = 1 then 
    'switches turn on OFF
    elseif encoderstate = 3 then 
    ..... etc
    endif
    
    goto main
    I'm getting desesperate to put all this together with my switches
    and my reverse sequence with if then. ifelse isn't working properly (need to have oldstate stored like you told me, Olson no ?)

  9. #9
    Join Date
    Jul 2011
    Posts
    29


    Did you find this post helpful? Yes | No

    Default Re: 1 Continuous MCPWM at a time

    also, if my motor is moving forward and then suddendly i turn on switch to go backward, that won't be beautiful... I need to add some sort of security that allow to start the commutation code only if my pwm is 0 or something like that, no ?

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