' ********************************************************************** ' ** Program: gmbdae.BAS - Version : 1.1 - 29 January 2004 ** ' ** Compiler : Bascom AVR IDE - LIB 1.11.7.4 ** ' ** Scheda : GMB HR84 and GMM AM08 ** ' ** 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 ** ' ** sales@grifo.it tech@grifo.it grifo@grifo.it ** ' ** ** ' ** Written by: Graziano Gaiba ** ' ********************************************************************** ' ' Rel. 1.1 29.01.04 - By Graziano Gaiba ' ' This demo uses Timer 2 of Mini Module to generate, on CN4, 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: M8 ' HW Stack: at least 64 ' Soft Stack: at least 32 ' Framesize: at least 64 ' ' $regfile = "m8def.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 Byte ' Generic use and SetPwm Dim S1 As String * 1 ' '****************** Procedures declartion ********************** ' Declare Sub Init() ' Initialization Declare Function Leggi_char() As Byte ' Read one character (blocking) ' '************************** Main program ****************************** ' Main: Do Call Init() Print "PWM demo" Print Print "Timer 2 (8 bit) is configured as PWM (pin 8 of socket)." Do Inputhex "Duty cycle in hex (E.g. 0F): " , S Ocr2 = S ' Set duty cycle Print "F to exit or any other key to re-set duty cycle" S = Leggi_char() Loop Until S = "F" Tccr2 = &H48 ' Stop Timer 2 Loop End ' ' *************************** Program end ****************************** ' ' ' **************************** Procedures ****************************** ' ' ' Initialize demo ' Sub Init() Ddrb = Ddrb Or &H08 ' Set portb.3 as output Ocr2 = &H80 ' Duty Cycle 50% ' Timer 2 configured for Fast PWM, No Prescaler, Sets to 1 pin 8 of socket ' on every match between register OCR2 and counter register of Timer 2 Tccr2 = &H79 Tcnt2 = 0 ' Reset timer 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