I need to generate 21KHz frequency sine wave using a 8051 MCU. Can any one help where in I can find refrence source about generation of of sine wave
Hy, i adapted my programm to your needs :-)
;**************************************************************************** ;Digital Frequency-generator ;assuming XTAL = 40MHz ;**************************************************************************** Timer0_repeat_cycles: EQU 40 ;cycle's between Timer_interrupts ;Frequency = 21000 * 65536 * Timer0_repeat_cycles / XTAL Frequency: EQU 1376 ;value to be computed by hand! ;**************************************************************************** ISEG ORG 30H ;behind bit-adressable-area Phase_low: DS 1 Phase_high: DS 1 RAM_end: ;**************************************************************************** CSEG ORG 0 AJMP Main ;**************************************************************************** ORG 0BH AJMP Timer0_int ;**************************************************************************** ORG 080H Timer0_int: PUSH ACC PUSH PSW PUSH DPH PUSH DPL ;save all used register MOV A,Phase_low ADD A,#low Frequency MOV Phase_low,A MOV A,Phase_high ADDC A,#high Frequency MOV Phase_high,A ;16 bit phase-accumulator MOV DPTR,#My_sintab MOVC A,@A+DPTR MOV P5,A ;assuming 8-bit-DA-converter on P5 POP DPL POP DPH POP PSW POP ACC ;restore all used registers RETI ;**************************************************************************** Main: MOV SP,#RAM_end-1 ACALL T0_int_init Loop: SJMP Loop ;My user programm ;**************************************************************************** T0_int_init: ANL TMOD,#11110000B ;clear TMOD(0) ORL TMOD,#00000010B ;Timer0 now 8Bit Reload MOV TH0,#-Timer0_repeat_cycles SETB TR0 ;Timer0 is running SETB ET0 ;Timer0 interrupt is enabled SETB EA ;general interrupt is enabled RET ;**************************************************************************** My_sintab: DB 080H,083H,086H,089H,08CH,08FH,092H,095H DB 098H,09CH,09FH,0A2H,0A5H,0A8H,0ABH,0AEH DB 0B0H,0B3H,0B6H,0B9H,0BCH,0BFH,0C1H,0C4H DB 0C7H,0C9H,0CCH,0CEH,0D1H,0D3H,0D5H,0D8H DB 0DAH,0DCH,0DEH,0E0H,0E2H,0E4H,0E6H,0E8H DB 0EAH,0ECH,0EDH,0EFH,0F0H,0F2H,0F3H,0F5H DB 0F6H,0F7H,0F8H,0F9H,0FAH,0FBH,0FCH,0FCH DB 0FDH,0FEH,0FEH,0FFH,0FFH,0FFH,0FFH,0FFH DB 0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FEH,0FEH DB 0FDH,0FCH,0FCH,0FBH,0FAH,0F9H,0F8H,0F7H DB 0F6H,0F5H,0F3H,0F2H,0F0H,0EFH,0EDH,0ECH DB 0EAH,0E8H,0E6H,0E4H,0E2H,0E0H,0DEH,0DCH DB 0DAH,0D8H,0D5H,0D3H,0D1H,0CEH,0CCH,0C9H DB 0C7H,0C4H,0C1H,0BFH,0BCH,0B9H,0B6H,0B3H DB 0B0H,0AEH,0ABH,0A8H,0A5H,0A2H,09FH,09CH DB 098H,095H,092H,08FH,08CH,089H,086H,083H DB 07FH,07CH,079H,076H,073H,070H,06DH,06AH DB 067H,063H,060H,05DH,05AH,057H,054H,051H DB 04FH,04CH,049H,046H,043H,040H,03EH,03BH DB 038H,036H,033H,031H,02EH,02CH,02AH,027H DB 025H,023H,021H,01FH,01DH,01BH,019H,017H DB 015H,013H,012H,010H,00FH,00DH,00CH,00AH DB 009H,008H,007H,006H,005H,004H,003H,003H DB 002H,001H,001H,000H,000H,000H,000H,000H DB 000H,000H,000H,000H,000H,000H,001H,001H DB 002H,003H,003H,004H,005H,006H,007H,008H DB 009H,00AH,00CH,00DH,00FH,010H,012H,013H DB 015H,017H,019H,01BH,01DH,01FH,021H,023H DB 025H,027H,02AH,02CH,02EH,031H,033H,036H DB 038H,03BH,03EH,040H,043H,046H,049H,04CH DB 04FH,051H,054H,057H,05AH,05DH,060H,063H DB 067H,06AH,06DH,070H,073H,076H,079H,07CH ;****************************************************************************
i would recomand you a forth order butterworth-filter at the output of your DA-Converter.
Thanks A lot for your post