Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

BLDC RPM Speed Measurement

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
RikyFitriadi

Bascom Member



Joined: 05 Feb 2015
Posts: 1

PostPosted: Thu Feb 05, 2015 7:55 am    Post subject: BLDC RPM Speed Measurement Reply with quote

Dear All,

At this moment , I'm ongoing to finish my final project about BLDC Motor Speed control
Here is BLDC motor specification :

1) Max RPM = 520 Rpm
2) Max Voltage = 48 V
3) 3 Hall Effect Sensor
4) The number of pole pairs = 20

And here is my design :
1) Use ATMega16 with Bascom AVR Compiler
2) Clock 16 MHz
3) LCD 16*2

I already success make BLDC motor working with commutation using PWM. The next step I want do RPM measurement. But I still have problem. The program I made give not correct value of RPM if compare to physical looking. Hope anyone can help me?

Here is my Bascom Code :
Code:
'===============================================================
'PWM + KOMUTASI2FASA MOTOR KANAN VERSI 2 TIMER2  CCW
'===============================================================

$regfile "m16adef.dat"
$crystal = 16000000
$baud = 115200

'-- Timers init ----------------------------------------------------------------
'TMR2 use FAST PWM mode
 Tccr2.wgm20 = 1
 Tccr2.wgm21 = 1

 Tccr2.com20 = 0
 Tccr2.com21 = 1

Config Adc = Single , Prescaler = Auto , Reference = Avcc



Config Porta = Output
Config Portb = Output
Config Portc = Output
Config Pind.7 = Output
Config Portd.2 = Input
Portd.2 = 1

Hijau Alias Pina.5
Biru Alias Pina.6
Kuning Alias Pina.7

2fasa_step6_ccw Alias &B00100100
2fasa_step5_ccw Alias &B00100001
2fasa_step4_ccw Alias &B00001001
2fasa_step3_ccw Alias &B00011000
2fasa_step2_ccw Alias &B00010010
2fasa_step1_ccw Alias &B00000110


Dim Pot As Word
Dim Ta As Single
Dim Count As Integer
Dim Rotation As Single
Dim Rpm As Single
Dim Num_of_pole As Integer


Ta = 0.04
Num_of_pole = 20

'-- LCD config ------------------------------------------------------------------
Config Lcdbus = 4
Config Lcd = 16 * 2
Config Lcdpin = Pin , Db4 = Porta.0 , Db5 = Porta.1 , Db6 = Porta.2 , Db7 = Porta.3 , E = Porta.5 , Rs = Porta.4
Cls

Start Adc
Enable Interrupts

Do
   Config Int0 = Falling
   Enable Interrupts
   Enable Int0
   On Int0 Enkoder_hall


   Config Timer1 = Timer , Prescale = 256
   On Timer1 Regler
   Timer1 = 63035
   Enable Timer1
   Start Timer1

   Config Timer2 = Pwm , Pwm = On , Prescale = 64 , Compare Pwm = Clear Down
   Pot = Getadc(1)
   Ocr2 = Pot
   Gosub Komutasi2fasa_ccw
   Gosub Ceksensor_ccw
   Enable Timer2
   Start Timer2
   $sim

   Wait 4
   Print Rpm
Loop
End

Enkoder_hall:
   Incr Count
Return

Regler:
   Timer1 = 63035
   Rotation = Count / Ta
   Rpm = Rotation / Num_of_pole
   Count = 0
Return

Komutasi2fasa_ccw:
   If Hijau = 0 And Biru = 0 And Kuning = 1 Then Portb = 2fasa_step5_ccw
   If Hijau = 0 And Biru = 1 And Kuning = 1 Then Portb = 2fasa_step4_ccw
   If Hijau = 0 And Biru = 1 And Kuning = 0 Then Portb = 2fasa_step3_ccw
   If Hijau = 1 And Biru = 1 And Kuning = 0 Then Portb = 2fasa_step2_ccw
   If Hijau = 1 And Biru = 0 And Kuning = 0 Then Portb = 2fasa_step1_ccw
   If Hijau = 1 And Biru = 0 And Kuning = 1 Then Portb = 2fasa_step6_ccw
Return

Ceksensor_ccw:
   If Hijau = 0 And Biru = 0 And Kuning = 1 Then
      Portc.0 = 0
      Portc.2 = 0
      Portc.4 = 1
   End If
   If Hijau = 0 And Biru = 1 And Kuning = 1 Then
      Portc.0 = 0
      Portc.2 = 1
      Portc.4 = 1
   End If
   If Hijau = 0 And Biru = 1 And Kuning = 0 Then
      Portc.0 = 0
      Portc.2 = 1
      Portc.4 = 0
   End If
   If Hijau = 1 And Biru = 1 And Kuning = 0 Then
      Portc.0 = 1
      Portc.2 = 1
      Portc.4 = 0
   End If
   If Hijau = 1 And Biru = 0 And Kuning = 0 Then
      Portc.0 = 1
      Portc.2 = 0
      Portc.4 = 0
   End If
   If Hijau = 1 And Biru = 0 And Kuning = 1 Then
      Portc.0 = 1
      Portc.2 = 0
      Portc.4 = 1
   End If
Return


(BASCOM-AVR version : 2.0.7.8 )
Back to top
View user's profile
amirf

Bascom Member



Joined: 25 Aug 2009
Posts: 154

indonesia.gif
PostPosted: Thu Feb 05, 2015 10:46 am    Post subject: Reply with quote

check this out : http://www.mcselec.com/index2.php?option=com_forum&Itemid=59&page=viewtopic&t=12399&highlight=rpm
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR All times are GMT + 1 Hour
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
You cannot attach files in this forum
You cannot download files in this forum