I am making a convertor of digital to similar, already compile this = program of the microchip page but to the moment to arm it, surprise!!!!, = don't work me, somebody could please help myself...!!! =20 Thank you...........Osvaldo =20 That I should make so that it works with the pic 16F628??? The program this in the page of Microchip for the pic 16F620: =20 http://www.microchip.com/download/appnote/devspec/16cxx/00655a.pdf =20 but I adapt it for the pic 16F628: ERRORLEVEL 0, -302 ;************************************************************************= ************************************************* TITLE "PWM based sine wave generator" LIST P=3D16F628, R=3DDEC INCLUDE LIST ; P16F628.INC Standard Header File, Versi=F3n 1.01 Microchip = Technology, Inc. LIST __CONFIG _BODEN_OFF&_CP_OFF&_PWRTE_ON&_WDT_OFF&_XT_OSC ; ;************************************************************************= ************************************************* ; File: SINE.ASM ; Author: Rob Stein ; Date: 12/20/95=20 ; Assembler: MPASM V01.40 ; Xtal: 20 Mhz ; Inst Clk: 5 Mhz (200nSec) ;************************************************************************= ************************************************* ; Description: ; Outputs a 60 hz sythesized sine wave (32 step) via a general ; purpose I/O pin (RB1) into a low pass filter. A software PWM ; routine is used to create 32 separate sinewave steps. This ; software was prototyped whith the PICDEM1 board. ; ; Circuit Diagram: ; ; 2.7k 2.7k ; RB1 __/\ /\ /\_____/\ /\ /\_____ Analog Output ; \/ \/ | \/ \/ | =20 ; | | ; ----- 0.1=B5F ----- 0.1=B5F=20 ; ; ----- ----- ; | | ; | | ; GND GND ; ; ROM Usage: 98 words ; ; RAM Usage: 6 bytes ; ;*************************** Constant Definition = *********************************************************************** FXTAL EQU .20000000 ; Crystal Frecuency FINST EQU FXTAL/4 ; Instruction Cycle Frecuency =20 FSINE EQU .60 ; Sine Function Frecuency STEP# EQU .32 ; Number of steps FSTEP EQU FSINE * STEP# ; Step frecuency ;*************************** Register definition = **********************************************************************=20 TEMPW EQU 0x20 ; Temporary interrup storage for w DELAYCNT1 EQU 0x21 ; Delay routine counter low DELAYCNT2 EQU 0x22 ; Delay routine counter high STEPCOUNT EQU 0x23 ; Sine step counter OUTLOW EQU 0x24 ; PWM low cycle load TMR0 OUTHIGH EQU 0x25 ; PWM high cycle load for TMR0 OPTION_REG EQU 0x81 TRISA EQU 0X85 =20 TRISB EQU 0X86=20 =20 ;******************************* Bit Definition = ************************************************************************ PWM EQU 0x01 ; RB1 used for PWM output ;************************************************************************= ************************************************* ; Reset Vector ;************************************************************************= ************************************************* org 0x000 goto Start ; Begining of Program ;************************************************************************= ************************************************* ; Interrup Vector and Service Routine ; This interrup routine is entered via an overflow of TMR0 from ; 0xFF to 0x00. A test of RB1 deteermines if the next time state ; is a high or low cycle. The next interrupt will occur based the ; TMR0 reload value (OUTLOW or OUTHIGH). ; ; The interrup routine was designed to use a minimial number of ; instruction cycles. This was doen to maximize the PWM duty cycle ; range (ie. a 5% to 95% range is achievable with this ISR). Note ; that 'swapf' instructions are used to perform register moves without ; effecting the STATUS flags (this saves instruction cycles by=20 ; eliminating the need to temporarily save the STATUS register). ; ;************************************************************************= ************************************************* org 0x004 ; Interrupt vector location IntVector movwf TEMPW ; Temporary save W btfsc PORTB, PWM ; Was this a low cycle ?=20 goto PWMLow ; No... PWMHigh swapf OUTHIGH,W ; Yes...Load hi-time w/o affecting STATUS flags bsf PORTB, PWM nop ; Delay to equalize high/low TMR0 lload cycles movwf TMR0 ; Load next edge interrupt time bcf INTCON, T0IF ; Clear TMR0 overflow flag swapf TEMPW,F ; Swap saved W swapf TEMPW,W ; Restore W IntEndHi retfie ; Return from Interrupt PWMLow bcf PORTB, PWM swapf OUTLOW,W ; Load low time movwf TMR0 ; Load next edge interrupt time bcf INTCON,T0IF ; Clear TMR0 overflow flag swapf TEMPW,F ; Swap saved w swapf TEMPW,W ; Restore W IntEndLo retfie ; Return from Interrupt ;************************************************************************= ************************************************* ; Main Routine ;************************************************************************= ************************************************* Start clrf STATUS ; Initialize STATUS & select bank 0 bsf STATUS,RP0 ; Select register bank 1 movlw 0x88 movwf OPTION_REG ; 1:1 TMR0 prescaler, PORTB pull-ups disabled movlw 0xFF movwf TRISA ; Set Port_A as inputs clrf TRISB ; Set Port_B as outputs bcf STATUS,RP0 ; Select register bank 0 movwf PORTB ; PORT_B pins high clrf TMR0 ; Initialize TMR0 movlw 0xA0 movwf INTCON ; Enable TMR0 and global interrupt ResetStep movlw STEP# movwf STEPCOUNT ; Load counter for 32 steps StepLoop call Delay ; Software delay=20 movf STEPCOUNT,W ; Pass table offset via w call SineTable ; Get table value call SetPWM ; Set-Up low & high PWM values decfsz STEPCOUNT,F ; Next step goto StepLoop goto ResetStep ;************************************************************************= ************************************************* ; Set PWM Subrutine * ; The followin calculates the next low and high PWM time values. = * ; The two time values, OUTLOW and UOTHIGH, will be passed to the = * ; interrupt service routine. * ;************************************************************************= ************************************************* SetPWM bcf INTCON,GIE ; Disable interrupts to protect ISR from.... ; corrrupting OUTLOW & OUTHIGH values movwf OUTLOW ; Set PWM Duty Cycle comf OUTLOW,W addlw IntEndHi-IntVector ; Adjust for Int Service time movwf OUTHIGH movf OUTLOW,W addlw IntEndHi-IntVector ; Adjust for Int Service time movwf OUTLOW swapf OUTLOW,F ; Swap nibbles so that interrupt service... swapf OUTHIGH,F ; will not corrupt STATUS bsf INTCON, GIE ; Re-enable interrupts return ;************************************************************************= ************************************************ ; Lookup Table for Sine Wave ; This 32 entry table was generated to produce a 0.1*Vdd to=20 ; 0.9*Vdd (typicaly 0.5 to 4.5 volt) sine function. ;************************************************************************= ************************************************ SineTable addwf PCL,F ; Increment into table retlw .0 ; Dummy table value retlw .128 ; 0 degree, 2.5 volt retlw .148 retlw .167 retlw .185 retlw .200 retlw .213 retlw .222 retlw .228 retlw .230 ; 90 degree, 4.5 volt retlw .228 retlw .222 retlw .213 retlw .200 retlw .185 retlw .167 retlw .148 retlw .128 ; 180 degree, 2.5 volt retlw .108 retlw .89 retlw .71 retlw .56 retlw .43 retlw .34 retlw .28 retlw .26 ; 270 degree, 2.5 volt retlw .28 retlw .34 retlw .43 retlw .56 retlw .71 retlw .89 retlw .108 ;************************************************************************= ************************************************ ; Time Delay Sub-routine * ; The time delay is used to create the precisin 32 steps. The * ; 32 step times totaled together add up to a 60 Hz rate. Note that = * ; constants DELAYCNT# are used so that other frecuencies can easily = * ; be generated (example: FSINE equ .50 for a 50 Hz sinewave). * ;************************************************************************= ************************************************ TDELAY EQU FINST/FSTEP ; # of delay count cycles ADJTDELAY EQU TDELAY/3 - 55 ; Adjust for main routine cycles TDELAYHI EQU high ADJTDELAY ; Most Significant Byte of TDELAY TDELAYLO EQU low ADJTDELAY ; Lest Sig. Byte of TDELAY =20 Delay movlw TDELAYHI movwf DELAYCNT2 ; Load high byte delay counter clrf DELAYCNT1 LoopD1 decfsz DELAYCNT1,F ; Finished with 256 loops ? goto LoopD1 ; No...keep going decfsz DELAYCNT2,F ; Yes...Done with TDELAYHI loops ? goto LoopD1 ; No... movlw TDELAYLO ; Yes...Load low byte with adjust for... movwf DELAYCNT1 ; main routine cycles. LoopD2 decfsz DELAYCNT1,F ; Finished with TDELAYLO loops ? goto LoopD2 ; No...keep going return ; Yes...Finished END ; That's all Folks !=20 -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu