View previous topic :: View next topic |
Author |
Message |
Zek_De
Joined: 13 Aug 2016 Posts: 100
|
BLDC Sinusoidal Control |
Posted: Thu Nov 14, 2019 12:48 am |
|
|
Hi guys, I am trying to understand how to use sinusoidal control. I have codes someone did it. But I couldn't understand somewhere maybe someone have this experience, maybe can understand the basic points that I can continue. If you need all codes I can send but very long, this is why I am gonna send specific points.
int_sine_temp>>=10; This is interesting. What is it?
Code: |
Timer_Call_Back(void)
{
unsigned long long_temp=0;
pwm_step++;
switch (pwm_step)
{
case 1:
{
int_sine_temp=pgm_read_word(&torq_num2[k_a]);
int_sine_temp*=motor_volt;
int_sine_temp>>=10;
int_sine_temp+=half_capture_compare;
TCC0_CCBBUF=int_sine_temp;
int_sine_temp=pgm_read_word(&torq_num2[k_b]);
int_sine_temp*=motor_volt; ///4;
int_sine_temp>>=10;
int_sine_temp+=half_capture_compare;
TCC0_CCABUF=int_sine_temp;
int_sine_temp=pgm_read_word(&torq_num2[k_c]);
int_sine_temp*=motor_volt; ///4;
int_sine_temp>>=10;
int_sine_temp+=half_capture_compare;
TCC0_CCCBUF=int_sine_temp;
motor_amp_temp2+=adc_read(_motor_amp_pin);
motor_amp_temp2/=2;
motor_amp_temp=motor_amp_temp2;
}
//.
//.
//.
//Code has more
}
|
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Thu Nov 14, 2019 6:33 am |
|
|
re:
Quote: | int_sine_temp>>=10; This is interesting. What is it? |
I understand it to mean that the value or contents of the variable 'int_sine_temp' will be replaced with the original data, right shifted 10 bits.
A lot of PICs have a 10bit PWM which means 'math' is done with 16 bits. This code would allow the most significant bits of the 'math' to be used by the PWM module.
At least that's how I read it....
>>= would right shift 1 bit position
>>=4 would right shift 4 bit positions
I looked at my copy of the CCS manual and while >>= is listed, >>=10 isn't. It would have been nice to see, as I'm not a school educated C programmer !
Jay |
|
|
Zek_De
Joined: 13 Aug 2016 Posts: 100
|
|
Posted: Thu Nov 14, 2019 11:36 pm |
|
|
Hey Jay, of course I know shifting. I asked actually why this shifting used, actually it was probably about sinusoidal wave. >>10 is val/1024. I didn't realised it and I didn't use like that notation to divide. Sorry for wrong question. Now I am searching theory. |
|
|
|