Translate

Membuat alat untuk menghitung kecepatan putaran/detik dan Data logger

Membuat alat untuk menghitung kecepatan putaran/detik dan Data logger


       Kali ini saya akan menjelaskan mengenai bagaimana cara membuat alat untk memantau kecepatan putaran motor kemudian disimpan ke sd card, modul yang digunakan yaitu modul optocoupler dan komparator, modul RTC, dan modul mikrokontroller, jadi pada contoh ini di misalkan bahwa jika kecepatan putaran motor melebihi 10 maka akan menyimpan ke sd card, berikut penjelasan skemanya.


a. Minimum System




 b. Modul Optocoupler




 
 c. SD Card Modul





d. Program Bascom AVR

$regfile = "m32def.dat"
$crystal = 11059200
'==========================
Config Lcdpin = Pin , E = Portc.7 , Rs = Portc.6 ,
Config Lcdpin = Pin , Db4 = Portc.2 , Db5 = Portc.3 , Db6 = Portc.4 , Db7 = Portc.5
Config Lcd = 16 * 2
$lib "ds1307clock.lib"


Cursor Off
Cls


Ch Alias Pind.2
Config Pind.2 = Output
Config Ch = Input
Config Int0 = Falling
Const Debouncetime = 1
Dim Wtime As Byte
Dim Encounter As Integer
Set Ch


Const Clockmode = 0

Config Date = Dmy , Separator = /                           ' ngebatasin
Config Clock = User                                         ' this will dim the bytes automatic

'Date$ = "10/09/12"                                          'mm/dd/yy
'Time$ = "22:14:00"                                          'hh:mm:ss

'configure the scl and sda pins
Config Sda = Portc.1
Config Scl = Portc.0

Const Ds1307w = &HD0                                        ' Addresses of Ds1307 clock
Const Ds1307r = &HD1

'VARIABEL TIME ////////////////////////////
Dim Weekday As Byte                                         'dim other needed variables
'Dim Day As Byte
'Dim Bln As Byte
'Dim Thn As Byte
'Dim Sthn As Byte

'VARIABEL MMC//////////////////////////////
Dim A As Byte
Dim L As String * 10
Dim Ff As Byte
Dim S As Long
Dim Diskf As Long
Dim Disks As Long
Dim Nama As String * 20

'VARIABEL TGS
Dim Co As Integer
Dim No As Integer
Dim Ax As Single
Dim Vo As Single
Dim X As Single
Dim Y As Single
Dim Rs As Single
Dim D As Single
Dim E As Single
Dim Ppm As Single
Dim Ro As Single

Dim Res As String * 10
Dim Ppm1 As String * 10
Dim Hitung As Integer
'================================================================
Dim P As Byte
'================================================================

$include "Config_AVR-DOS32.BAS"
$include "Config_MMC32.bas"

Ff = Drivereset()
Ff = Driveinit()



$external Waitms

Perintah:

Waitms 500

Gosub Getdatetime




On Int0 Getencoder
Wtime = 100
Encounter = 0

Enable Interrupts
Enable Int0

A = 0


Do
If Encounter > 10 And A < 5 Then
Goto Utama
End If

Set Portd.6
Waitms Wtime

If Encounter > 10 And A < 5 Then
Goto Utama
End If

Upperline
Lcd "encounter: " ; Encounter ;
Reset Portd.6
Lowerline
Lcd "Count = " ; A

If Encounter > 10 And A < 5 Then
Goto Utama
End If

Waitms Wtime

Incr A

If Encounter > 10 And A < 5 Then
Goto Utama
End If

If A > 5 Then
A = 0
Encounter = 0
End If

Cls
Loop



Utama:
Disable Interrupts
Cls
Waitms 200
Upperline
Lcd " PLEASE WAIT !!"
Wait 1
Cls
Do
If Gbdriveerror <> 0 Then                                   'CEK MEMORY CARD ERROR
   Cls
   Locate 1 , 1
   Lcd "Error Config"
   Locate 2 , 1
   Lcd "CEK MEMORY"
   Wait 2

End If

A = Initfilesystem(1)                                       'init file system
If A <> 0 Then
   Cls
   Locate 1 , 1
   Lcd "Error MEMORY"
   Locate 2 , 1
   Lcd "CEK MEMORY CARD"
   Wait 2
   Cls
   Goto Perintah

End If
  'Goto Perintah
  'Cls

If A = 0 Then
   Cls
   Locate 1 , 1
   Lcd "MEMORY OK"
   Wait 1
End If


Diskf = Diskfree()
Select Case Diskf                                           'CEK FREESPACE
S = Diskf
S = Str(s)

Case Is > 3000 : Locate 2 , 1
                  Lcd " Free > 3MB"
                  Lcd S


Case Is > 1000 : Locate 2 , 1
                  Lcd " Free > 1MB"
                  Lcd S


Case Else : Locate 2 , 1
             Lcd "!! FREE < 1MB !!"
             Wait 1
             Locate 2 , 1
             Lcd "GANTI memoryCARD"

End Select

Wait 3
Gosub Getdatetime
Cls
Upperline
Lcd Date$
Lowerline
Lcd Time$
Wait 3
Cls
Ff = Freefile()

L = "TEST"
Nama = L + ".txt"
Open Nama For Append As #ff                                 'buat file baru (bisa append bisa output)

Print #ff , "             RESULT"
Print #ff , "#################################"
Print #ff , "#" ; Date$ ; ", " ; Time$
Print #ff , "#################################"
Print #ff , "KECEPATAN: " ; Encounter ; "km/jam"
Print #ff ,

Close #ff                                                   'tutup file

Cls
   Locate 1 , 1
   Lcd "FILE CREATED"
   Wait 2
   Goto Perintah
   Cls

   Loop
   Return

'///////////////////////////////////////////////////////////////////////////////
'dari ds1307clock.lib
Getdatetime:
  I2cstart                                                  ' Generate start code
  I2cwbyte Ds1307w                                          ' send address
  I2cwbyte 0                                                ' start address in 1307

  I2cstart                                                  ' Generate start code
  I2cwbyte Ds1307r                                          ' send address
  I2crbyte _sec , Ack                                       'detik
  I2crbyte _min , Ack                                       ' MINUTES
  I2crbyte _hour , Ack                                      ' Hours
  I2crbyte Weekday , Ack                                    ' Day of Week
  I2crbyte _day , Ack                                       ' Day of Month
  I2crbyte _month , Ack                                     ' Month of Year
  I2crbyte _year , Nack                                     ' Year
  I2cstop
  _sec = Makedec(_sec) : _min = Makedec(_min) : _hour = Makedec(_hour)
  _day = Makedec(_day) : _month = Makedec(_month) : _year = Makedec(_year)
Return

Setdate:
_day = Makebcd(_day) : _month = Makebcd(_month) : _year = Makebcd(_year)
I2cstart                                                    ' Generate start code
I2cwbyte Ds1307w                                            ' send address
I2cwbyte 4                                                  ' starting address in 1307
I2cwbyte _day                                               ' Send Data to day
I2cwbyte _month                                             ' Month
I2cwbyte _year                                              ' years
I2cstop
Return

Settime:
_sec = Makebcd(_sec) : _min = Makebcd(_min) : _hour = Makebcd(_hour)
I2cstart                                                    ' Generate start code
I2cwbyte Ds1307w                                            ' send address
I2cwbyte 0                                                  ' starting address in 1307
I2cwbyte _sec                                               ' Send Data to SECONDS
I2cwbyte _min                                               ' MINUTES
I2cwbyte _hour                                              ' Hours
I2cstop
Return

Getencoder:
  Waitms Debouncetime
  If Ch = 0 Then
     Incr Encounter
  End If
  Gifr = 64
Return









 

No comments:

Post a Comment