' ********************************************************************** ' ** Program: gmbdae.BAS - Version : 1.1 - 14 June 2005 ** ' ** Compiler : Bascom AVR IDE - LIB 1.11.7.4 ** ' ** Board : GMB HR168 and GMM AM32 ** ' ** Society: grifo(r) ITALIAN TECHNOLOGY ** ' ** Via Dell' Artigiano 8/6 40016 San Giorgio di Piano (BO) ** ' ** Tel.+39 051 892 052 Fax +39 051 893 661 ** ' ** http://www.grifo.com http://www.grifo.it ** ' ** Written by: Graziano Gaiba ** ' ********************************************************************** ' ' 14.06.05 - Rel 1.1 By Graziano Gaiba ' This demo uses Timer 1 of Mini Module to generate, on CN7, a PWM signal ' with preset frequency and duty cycle programmable in percent by console. ' Such signal, connected to an opportune intergrating circuit (RC network, ' operational amplifire with capacitor on feedback, etc.) allows to obtain an ' anlog signal like the one of a D/A. Demo execution depends on which Mini ' Module is used and serial line configuration. ' ' Compiled file is smaller than 2048 bytes, so it can becompliled with free ' demo of BASCOM AVR. ' ' ' !!!!!!!!!!!!!!!!!!!!!!!!!!! IMPORTANT !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ' In menu Options | Compiler | Chip, set: ' ' Chip: M32 ' HW Stack: at least 64 ' Soft Stack: at least 32 ' Framesize: at least 64 ' ' $regfile = "m32def.dat" $crystal = 7372800 $baud = 19200 ' ' ********************* Constans declarations ************************* ' Const Cret = 13 ' Codice di ritorno di carrello Const Nl = 10 ' Codice nuova linea Const Clrscr = 12 ' codice di clear screen Const Bell = 7 ' codice di Bell ' '****************** Variables declaration ********************** ' ' Generic use Dim S As Word , Char As Byte ' Generic use and SetPwm Dim S1 As String * 1 Dim A As Eram Byte At 1023 ' '****************** Procedures declartion ********************** ' Declare Sub Init() ' Initialization Declare Function Leggi_char() As Byte ' Read one character (blocking) Declare Sub Check_ready() ' '************************** Main program ****************************** ' Main: Do Call Init() Print Chr(clrscr) ' Clear screen Print "Demo 1.1 for GMM AM32 + GMB HR168" Print Call Check_ready() ' Check board ready Print Print "Timer 1 is configured as 10 bit PWM (output on pin 6 of CN7 on GMB HR168)." Do Inputhex "Duty cycle in hex (E.g. 300): " , S Ocr1ah = High(s) ' Set duty cycle Ocr1al = Low(s) Print "E to exit or any other key to re-set duty cycle" Char = Leggi_char() Loop Until Char = "E" Tccr1b = 0 ' Stop Timer 1 Loop End ' ' *************************** Program end ****************************** ' ' ' **************************** Procedures ****************************** ' ' ' Initialize demo ' Sub Init() Ddrd.5 = 1 ' Set portd.5 as output Ocr1ah = &H02 Ocr1al = &H00 Tcnt1h = 0 ' Reset timer Tcnt1l = 0 ' Timer 1 configured for Fast PWM, No Prescaler, toggles 1 pin 6 of CN7 ' on every match between register OCR1A and counter register of Timer 1, does ' not use OCR1B. Tccr1a = &H83 ' Start Timer 1 Tccr1b = &H09 End Sub ' ' ' Reads a character in blocking way,converts it in capital letter and prints it ' Function Leggi_char() As Byte Local C As Byte C = Waitkey() Print Chr(c) C = C And &HDF ' Converts ASCII character in capital letter Leggi_char = C End Function ' ' ' Check for hardware ready ' Sub Check_ready() Test: If A = &H55 Then Goto L2 Else Goto Test End If L2: End Sub