# Trying to understand the sine look up table

Discussion in 'Microcontrollers' started by elecLear78, Jun 12, 2017.

1. ### elecLear78Member

Joined:
Jul 16, 2013
Messages:
227
Likes:
1
Location:
india
I am trying to understand the following project
http://www.microchip.com/wwwAppNotes/AppNotes.aspx?appnote=en020394 . This is the application note for AN900 and also downloaded the source code. I am struck with the sine look up table which is provided in the source code
Code (text):

TABLE   code 0x0600       ;was 0x0100
;below table is from 270 degrees to 90 degrees @ 10 degree resolution; for 20MHz, PR2 = F9, Timer2 1:1 prescale
;sine_table db   0x00,0x02,0x08,0x11,0x1E,0x2E,0x40,0x54,0x69,0x80,0x96,0xAB,0xBF,0xD1,0xE1,0xEE,0xF7,0xFD,0xFF

;below table is from 270 degrees to 90 degrees @ 10 degree resolution; for 16MHz, PR2 = 137, Timer2 1:1 prescale
sine_table db   0x00,0x02,0x08,0x11,0x1E,0x2E,0x40,0x54,0x69,0x80,0x96,0xAB,0xBF,0xD1,0xE1,0xEE,0xF7,0xFD,0xFF

I have understood that from 270 degrees to 180 the sine values are negative and from 180 to 9o they are positive values and hence if i decode the hex values they are the complements for positive and negative values. My question is sin(270) is -1. Is it not required that the table should contain -1? Please help. Where exactly he is extracting -1 from the table.

File size:
37.2 KB
Views:
27
2. ### misterTWell-Known MemberMost Helpful Member

Joined:
Apr 19, 2010
Messages:
2,697
Likes:
368
Location:
Finland
All the numbers in the code are positive, but negative values are driving diffrenet MOSFETs in the motor driving bridge. This is my guess. I don't have time to inspect the example project more closely.

Take a look at the schematics at the end of the AN900 (page 15). Especially how the different pwm-channels are connected.

EDIT:
Actually, I think 0x00 means -1 (lower MOSFET constantly on). And 0xFF means +1 (upper MOSFET constantly on). Any value between is the mean value how long upper and lower mosfets are on. For example, 50% duty-cycle switches between the upper and lower mosfets so fast that the resulting voltage at the motor terminal is 0.

Last edited: Jun 12, 2017
3. ### elecLear78Member

Joined:
Jul 16, 2013
Messages:
227
Likes:
1
Location:
india
Ok thank you very much for the reply. I will look at the schematics and get back to you. Please help me to understand this project.

Joined:
Jan 12, 1997
Messages:
-
Likes:
0

5. ### misterTWell-Known MemberMost Helpful Member

Joined:
Apr 19, 2010
Messages:
2,697
Likes:
368
Location:
Finland

Start from here: https://www.digikey.com/en/articles/techzone/2013/mar/an-introduction-to-brushless-dc-motor-control
Then google more by searching "controlling 3 phase brushless motor" or something similar.

I think you have a lot to learn, but the theory is not that hard if you do not try to rush it. Take your time to understand the hardware first. How 3-phase motors and dc motors are controlled using half-bridges (google "half bridge motor driver"). I think my explanation in my previous post was a little too simplified. In theory it might be correct, but in practice there is a lot more details to consider and learn. And at the end, there are more than one way to control a motor.

But I can't teach you further. It would just involve me to google and repeat what I find. It is better if you do the googling yourself. Do the reading. And of course.. ask when you encounter some specific detail you struggle to understand. Then I (and others) are able to help you much much better.

Last edited: Jun 12, 2017
• Like x 2
6. ### elecLear78Member

Joined:
Jul 16, 2013
Messages:
227
Likes:
1
Location:
india
I have been reading a lot of documentation about the BLDC motors and how to drive them for a long time. These are the points I have understood
1. There will be 6 PWM outputs from the micro controller.
2. The 6 PWM outputs are connected to the six legs of the H Bridge or IGBT's.
3. The H and L legs are complementary with dead time.
4. The outputs of the H bridge are used to drive the stator winding's U,V,W.
5. At any instant of time, one of the winding's should be driven to VDC and one has to be grounded and the thirdone is left open.
6. At every 120 degrees the state is changed or can be driven by Sine Look up table.

Please correct me if i am wrong in my understanding.

Questions really i don't understand are
1. As per the link provided to drive the motor in one step let us say i have to switch on U winding to VDC and V winding to -VDC. To achieve that I will enable H1 and enable L2 (I am assuming). Now my biggest doubt is should it always be 100% duty for permanent ON or it can be 50% duty or which duty should i select. Let us assume i can select 50% duty then there will be 50% OFF time of H1 then will the behavior not change as we wanted that H1 should be ON in that commutation period. And if switch L2 also with 50% duty ON. What will happen in this case? Because we wanted L2 to be OFF in this period.

2. How do i link the sine look up table which in turn as i read is the pwm duty cycle to switching ON the legs. (Specifically if i have to send -VDC to one of the winding's, PWM with what duty cycle should i apply to the leg?) .

7. ### elecLear78Member

Joined:
Jul 16, 2013
Messages:
227
Likes:
1
Location:
india
For the first question i found out that we can apply pwm and the output voltage is proportional to the duty cycle applied of the high side. Not sure if i am correct.

8. ### misterTWell-Known MemberMost Helpful Member

Joined:
Apr 19, 2010
Messages:
2,697
Likes:
368
Location:
Finland
Brushless DC motors are not actually DC motors, but more like 3-phase AC motors. They are driven with alternating voltage an current. So the voltage applied to the coils are sine waves. The frequency of the sine wave controls the speed and the amplitude controls the torque. So when the motor is spinning, your pwm signals need to generate sinewaves matching the speed of the motor. Simply said, when you want to increase the speed, you increase the frequency of your generated sine waves.

• Like x 1
9. ### elecLear78Member

Joined:
Jul 16, 2013
Messages:
227
Likes:
1
Location:
india
Thank you very much.

10. ### elecLear78Member

Joined:
Jul 16, 2013
Messages:
227
Likes:
1
Location:
india
I was studying the microchip application note using v/f method and the note asks to maintain constant value for voltage vs frequency which is the torque. Can you please tell what value should i maintain? Can i get this value from motor specifications?

11. ### elecLear78Member

Joined:
Jul 16, 2013
Messages:
227
Likes:
1
Location:
india
Sorry for continuous posts. I have created a flow chart for V/f control method. Request to please provide your feedback in case if you say not on track then i will close this thread.

File size:
44.1 KB
Views:
28