CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

BLDC Sinusoidal Control

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Zek_De



Joined: 13 Aug 2016
Posts: 100

View user's profile Send private message

BLDC Sinusoidal Control
PostPosted: Thu Nov 14, 2019 12:48 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Nov 14, 2019 6:33 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Nov 14, 2019 11:36 pm     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group