Please verify the logic

Status
Not open for further replies.

electronicsman

Full Member level 5
Joined
May 4, 2012
Messages
291
Helped
11
Reputation
22
Reaction score
12
Trophy points
1,298
Activity points
3,737
Hi, for understanding purpose i have done the following to drive a motor. Please tell me which portions are absolutely wrong and which are to be modified. I have created a sine look up table and in a timer interrupt of 10ms i am loading one value each upto 256. So it is a kind of from 0 degrees to 360 degrees so one degree each every 10ms interrupt. To drive the legs for switching a vague method i have created is calculate the difference between previous voltage to present voltage and increase the duty cycle by some value of 20. I plan to change this switching sequence. I can see the motor rotating. Please suggest.
 

I have created a sine look up table and in a timer interrupt of 10ms i am loading one value each upto 256...

The concept seems correct at all, I used the same look-up logic with an inverter. I'm assuming you mean by 256 to the maximum allowed value to the duty-cycle register of some PWM module.

To drive the legs for switching a vague method i have created is calculate the difference between previous voltage to present voltage and increase the duty cycle by some value of 20.

There are issues on this method; the most critical is that you are using a constant correction value instead of using some kind of loopback control proportional to the difference.
 

Thank you very much for the reply.

The concept seems correct at all, I used the same look-up logic with an inverter. I'm assuming you mean by 256 to the maximum allowed value to the duty-cycle register of some PWM module.

No i am not loading duty cycle. can you please see the code i have attached. My doubt is should i load duty cycle?
Code:
void Sinewave(void)
{
    static int index=0;
    
    if(index <= 256)
    {
         voltage_a= sin(2*PI*index/256);
         voltage_b= sin(2*PI*index+85/256);
         voltage_c= sin(2*PI*index+170)/256);
         index++;
    }
    else
    {
         index = 0;  
    }    
}

The above sine function i am calling in 10ms.
There are issues on this method; the most critical is that you are using a constant correction value instead of using some kind of loopback control proportional to the difference.
Code:
void pwm(void)
{
    double diff_phaseA=0.0;

   
   previous_phaseA=present_phaseA;
   present_phaseA=  voltage_a;
   
    if(present_phaseA >  previous_phaseA)
    {
     diff_phaseA= present_phaseA -  previous_phaseA;
     PDC1 += diff_phaseA * 200; /* diff_phaseA is in the range of 0.00 hence multiplying with 200*/
     if(PDC1 >= 500)
         PDC1 = 500;
    }
    else
    {
        
       diff_phaseA = previous_phaseA -  present_phaseA ;
        PDC1 -= diff_phaseA  * 200;
        if(PDC1 <= 2)
            PDC1=2;
    } 
}
Based on voltage difference i am loading the pdc value. And i am not getting constant value. But the motor is rotating very slowly. please help.
 

Many unclear points. Your are initially talking about a sine look-up table, but Sinewave() seems to calculate three phase voltages on the fly. The calculation is expectable very slow, probably taking a multiple of 10 ms, depending on the processor power.

Also what's the intended speed? 256 steps per 360° and 10 ms step rate gives only 23 rpm / number of pole pairs.

Don't understand yet what pwm() is doing...
 

I am sorry for not being very clear. Actually i am trying to generate three sine waves 120 apart for three phases. Now i want to switch the legs based on this voltage but don't know how to do it. I want to acheive this by pwm.
 

There are in total 6 pwm legs H1,L1, H2,L2,H3, L3 driving the 6 mosfets. The configuration is H bridge. The position i can read using an encoder.
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…