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,621


    Did you find this post helpful? Yes | No

    Default Re: 1 Continuous MCPWM at a time

    Hello,
    I can't really see any problem with it.... What does doesn't work mean in this case, what does it do?

    The only think I can think of is if you have anything else connected to PortA so that the actual value assigned to EncoderState1 isn't 0 even when the encoder is in the zero-position. But since it works with the IF-THEN version it can't be that (?).

    Do you have a serial connection setup? If so you can HSEROUT some debug information which will make it easier to figure out what's going on. If not perhaps you could blink a LED the same number of times as the value that gets assigned to EncoderState1, just to see what's going on.

    /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,

    Thank you for your reply,
    The IF...THEN code still works (thanks for the tip putting just the subroutines at the top of main).
    Do you have a serial connection setup? If so you can HSEROUT some debug information which will make it easier to figure out what's going on.
    I am only using a PICkit 2 programmer. ?!

    If not perhaps you could blink a LED the same number of times as the value that gets assigned to EncoderState1, just to see what's going on.
    What do you mean ??


    This morning I've tried a different code :
    Code:
     
    Main:
    encoderstate1 = PORTA
    
            Select encoderstate1
            Case %000000
                GoSub GetADC
                GoSub SetPWM           
                OVDCOND = %00100010 'Q4 (PWM5) and Q10 (PWM1)
                PORTC = %00000011   'Q1 and Q7 ON   
            Case %000001
                GoSub GetADC
                GoSub SetPWM           
                OVDCOND = %00100010 'Q4 (PWM5) and Q10 (PWM1)
                PORTC = %00000011   'Q1 and Q7 ON
            Case Else 
                PORTC = 0
                OVDCOND = 0
            EndSelect
    In case 0, it is doing what it should do, now if I'm trying to give the value of 1 (I have a switch on portA.0, that is all !!) it jumps to case else, it means that it does not see the value 1 ??? Why not ? it is working with IF... THEN...
    Moreover, after switching my switch and giving the value 1 to portA.0, 4seconds after, it acts like if the value on portA.0 was 0... ???

    AHHH sometimes those pics know how to make you crazy, doesn't they ?
    Thanks for the help. Very much appreciated
    Last edited by barneyfrance; - 19th July 2011 at 11:28.

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


    Did you find this post helpful? Yes | No

    Default Re: 1 Continuous MCPWM at a time

    Hi,
    It's strange if it really does work with the IF-THEN version. However, as is common on these PICs there are analog inputs on PortA. These normaly needs to be switched to digital in order to work in digital mode (no surprise) and this PIC is no exception. I know you're using the ADC in your GetADC rotuine so I know you have it setup some way or another but are you sure that the pins used for the encoder are setup as digital? (ANSEL0 and ANSEL1 registers)

    My thought with the LED was something in the line of:
    Code:
    i VAR BYTE
    LED VAR PortB.7
     
    EncoderState1 = PortA
     
    For i = 0 to EncoderState1
      High LED
      Pause 200
      Low LED
      Pause 200
    NEXT
     
    'Rest of code
     
    Pause 2000  'Just to make a visual "mark" that the loop starts over
    Goto Main
    This should make the LED blink the number of times equal to the value loaded into EncoderState1. It should help you figure out what's going on.

    My money is on the ADC being configured to have its inputs on some of the pins you're trying to use as digital. I don't know why it seems to work with the IF-THEN version though....

    If this doesn't help can you post a schematic and the complete code?

    /Henrik.

  4. #4
    Join Date
    Jul 2011
    Posts
    29


    Did you find this post helpful? Yes | No

    Default Re: 1 Continuous MCPWM at a time

    Hello,

    I'll try this as soon as I can. I have configured correctly ANSEL0 and ANSEL1 and I'm using my pot on AN6 in order to have all of my inputs encoder on portA.
    Now, if this doesn't work i'll post my code and everything.
    However is there anyway to switch off my commutation sequence anytime using IF.THEN ? for instance :
    Code:
    main : 
    If switch=1 then
        if encoder=1 then
        PWM 1,2
    
        else if encoder = 2
        PWM 2,3     ==> I'm turning my Switch "Start/stop" here and I want the program to stop everything here and not wait the end of the loop ? 
    
        else if encoder= 3
        PWM 4,3
        Endif
    
    Endif
    
    Goto Main

  5. #5
    Join Date
    Jul 2011
    Posts
    29


    Did you find this post helpful? Yes | No

    Default Re: 1 Continuous MCPWM at a time

    The case code now works, now idea what happened... ?
    Now I have another question (I'm still interested about the one in the previous post).
    When I move my motor forward, my encoder gives 12 different values, however, when I will operate it backward, I have still 12 steps but within these steps there are some similar values.
    for example :
    0, 32, 48, 56, 60, 62, 63, 62, 60, 56, 48, 32
    Now for these 12 steps I need to activate different pins even though some values are the same, from my understanding, I will not be able to use select case / case in that "case" lol ?

  6. #6
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,621


    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.

  7. #7
    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

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