twister1970 Inserito: 8 ottobre 2023 Segnala Share Inserito: 8 ottobre 2023 Premetto che ho iniziato da poco a programmare e per questo uso programmi come Great Cow Basic che permettono di creare il codice in modo visuale. Ho creato un codice che tramite un loop fa variare la frequenza audio da 700 a 1000 hz. Il loop funziona e il suono viene riprodotto ma sull'uscita oltre al suono desiderato è presente un ticchettio. Da cosa dipende? Secondo voi è risolvibile? codice asm ;Program compiled by Great Cow BASIC (0.99.01 2022-01-27 (Windows 64 bit) : Build 1073) for Microchip MPASM ;Need .? See the GCBASIC forums at http://sourceforge.net/projects/gcbasic/forums, ;check the documentation or email w_cholmondeley at users dot sourceforge dot net. ;******************************************************************************** ;Set up the assembler options (Chip type, clock source, other bits and pieces) LIST p=16F84, r=DEC #include <P16F84.inc> __CONFIG _CP_OFF & _WDTE_OFF & _FOSC_XT ;******************************************************************************** ;Set aside memory locations for variables DELAYTEMP EQU 12 SND EQU 25 SND_H EQU 26 SYSBYTETEMPX EQU 12 SYSDIVLOOP EQU 16 SYSDIVMULTA EQU 19 SYSDIVMULTA_H EQU 20 SYSDIVMULTB EQU 23 SYSDIVMULTB_H EQU 24 SYSDIVMULTX EQU 14 SYSDIVMULTX_H EQU 15 SYSFORLOOPABSVALUE1 EQU 27 SYSFORLOOPABSVALUE1_H EQU 28 SYSFORLOOPSTEP0 EQU 29 SYSFORLOOPSTEP0_H EQU 30 SYSTEMP1 EQU 31 SYSTEMP1_H EQU 32 SYSTEMP2 EQU 33 SYSWAITTEMP10US EQU 17 SYSWORDTEMPA EQU 17 SYSWORDTEMPA_H EQU 18 SYSWORDTEMPB EQU 21 SYSWORDTEMPB_H EQU 22 SYSWORDTEMPX EQU 12 SYSWORDTEMPX_H EQU 13 TONEDURATION EQU 34 TONEDURATION_H EQU 35 TONEFREQUENCY EQU 36 TONEFREQUENCY_H EQU 37 TONELOOP EQU 38 TONELOOP2 EQU 40 TONELOOP2_H EQU 41 TONELOOP_H EQU 39 TONEPERIOD EQU 42 TONEPERIOD_H EQU 43 ;******************************************************************************** ;Vectors ORG 0 pagesel BASPROGRAMSTART goto BASPROGRAMSTART ORG 4 retfie ;******************************************************************************** ;Start of program memory page 0 ORG 5 BASPROGRAMSTART ;Call initialisation routines call INITSYS call INITSOUND ;Start of the main program ;Chip Settings ;Defines (Constants) ;#define SoundOut PORTA.0 ;Variables ;Dim snd As word START ;For snd = 700 To 1000 step 20 movlw 188 movwf SND movlw 2 movwf SND_H SysForLoop1 ;#0 Init SysForLoopStep0 movlw 20 movwf SysForLoopStep0 clrf SysForLoopStep0_H ;Tone snd, 5 movf SND,W movwf TONEFREQUENCY movf SND_H,W movwf TONEFREQUENCY_H movlw 5 movwf TONEDURATION clrf TONEDURATION_H call TONE ;Next ;Integer negative Step Handler in For-next statement btfss SYSFORLOOPSTEP0_H,7 goto ELSE1_1 ;Set SysForLoopABsValue to -StepValue#1 comf SYSFORLOOPSTEP0,W movwf SysForLoopABsValue1 comf SYSFORLOOPSTEP0_H,W movwf SysForLoopABsValue1_H incf SysForLoopABsValue1,F btfsc STATUS,Z incf SysForLoopABsValue1_H,F ;#1n IF ( SND - 1000) } [WORD]SysForLoopABsValue1 THEN movlw 232 subwf SND,W movwf SysTemp1 movf SND_H,W movwf SysTemp1_H movlw 3 btfss STATUS,C movlw 3 + 1 subwf SysTemp1_H,F movf SysTemp1,W movwf SysWORDTempA movf SysTemp1_H,W movwf SysWORDTempA_H movf SYSFORLOOPABSVALUE1,W movwf SysWORDTempB movf SYSFORLOOPABSVALUE1_H,W movwf SysWORDTempB_H call SYSCOMPLESSTHAN16 comf SysByteTempX,F btfss SysByteTempX,0 goto ENDIF2 ;Set LoopVar to LoopVar + StepValue where StepValue is a negative value movf SysForLoopStep0,W addwf SND,F movf SysForLoopStep0_H,W btfsc STATUS,C incfsz SysForLoopStep0_H,W addwf SND_H,F goto SysForLoop1 ;END IF ENDIF2 goto ENDIF1 ELSE1_1 ;Integer positive Step Handler in For-next statement ;#1p IF ([WORD]1000 - [WORD]SND) } [WORD]SysForLoopStep0 THEN movf SND,W sublw 232 movwf SysTemp1 movf SND_H,W btfss STATUS,C incfsz SND_H,W sublw 3 movwf SysTemp1_H movf SysTemp1,W movwf SysWORDTempA movf SysTemp1_H,W movwf SysWORDTempA_H movf SYSFORLOOPSTEP0,W movwf SysWORDTempB movf SYSFORLOOPSTEP0_H,W movwf SysWORDTempB_H call SYSCOMPLESSTHAN16 comf SysByteTempX,F btfss SysByteTempX,0 goto ENDIF3 ;Set LoopVar to LoopVar + StepValue where StepValue is a positive value movf SysForLoopStep0,W addwf SND,F movf SysForLoopStep0_H,W btfsc STATUS,C incfsz SysForLoopStep0_H,W addwf SND_H,F goto SysForLoop1 ;END IF ENDIF3 ;END IF ENDIF1 SysForLoopEnd1 ;Goto start goto START BASPROGRAMEND sleep goto BASPROGRAMEND ;******************************************************************************** Delay_10US D10US_START movlw 2 movwf DELAYTEMP DelayUS0 decfsz DELAYTEMP,F goto DelayUS0 decfsz SysWaitTemp10US, F goto D10US_START return ;******************************************************************************** ;Source: sound.h (60) INITSOUND ;dir SoundOut out banksel TRISA bcf TRISA,0 banksel STATUS return ;******************************************************************************** ;Source: system.h (156) INITSYS ;asm showdebug _For_selected_frequency_-_the_external_oscillator_has_been_selected_by_compiler ChipMHz ;asm showdebug _Complete_the_chip_setup_of_BSR,ADCs,ANSEL_and_other_key_setup_registers_or_register_bits ; ;'Turn off all ports ;PORTA = 0 clrf PORTA ;PORTB = 0 clrf PORTB return ;******************************************************************************** ;Source: system.h (3023) SYSCOMPEQUAL16 ;dim SysWordTempA as word ;dim SysWordTempB as word ;dim SysByteTempX as byte ;clrf SysByteTempX clrf SYSBYTETEMPX ;Test low, exit if false ;movf SysWordTempA, W movf SYSWORDTEMPA, W ;subwf SysWordTempB, W subwf SYSWORDTEMPB, W ;btfss STATUS, Z btfss STATUS, Z ;return return ;Test high, exit if false ;movf SysWordTempA_H, W movf SYSWORDTEMPA_H, W ;subwf SysWordTempB_H, W subwf SYSWORDTEMPB_H, W ;btfss STATUS, Z btfss STATUS, Z ;return return ;comf SysByteTempX,F comf SYSBYTETEMPX,F return ;******************************************************************************** ;Source: system.h (3332) SYSCOMPLESSTHAN16 ;dim SysWordTempA as word ;dim SysWordTempB as word ;dim SysByteTempX as byte ;clrf SysByteTempX clrf SYSBYTETEMPX ;Test High, exit if more ;movf SysWordTempA_H,W movf SYSWORDTEMPA_H,W ;subwf SysWordTempB_H,W subwf SYSWORDTEMPB_H,W ;btfss STATUS,C btfss STATUS,C ;return return ;Test high, exit true if less ;movf SysWordTempB_H,W movf SYSWORDTEMPB_H,W ;subwf SysWordTempA_H,W subwf SYSWORDTEMPA_H,W ;btfss STATUS,C btfss STATUS,C ;goto SCLT16True goto SCLT16TRUE ;Test Low, exit if more or equal ;movf SysWordTempB,W movf SYSWORDTEMPB,W ;subwf SysWordTempA,W subwf SYSWORDTEMPA,W ;btfsc STATUS,C btfsc STATUS,C ;return return SCLT16TRUE ;comf SysByteTempX,F comf SYSBYTETEMPX,F return ;******************************************************************************** ;Source: system.h (2780) SYSDIVSUB16 ;dim SysWordTempA as word ;dim SysWordTempB as word ;dim SysWordTempX as word ;dim SysDivMultA as word ;dim SysDivMultB as word ;dim SysDivMultX as word ;SysDivMultA = SysWordTempA movf SYSWORDTEMPA,W movwf SYSDIVMULTA movf SYSWORDTEMPA_H,W movwf SYSDIVMULTA_H ;SysDivMultB = SysWordTempB movf SYSWORDTEMPB,W movwf SYSDIVMULTB movf SYSWORDTEMPB_H,W movwf SYSDIVMULTB_H ;SysDivMultX = 0 clrf SYSDIVMULTX clrf SYSDIVMULTX_H ;Avoid division by zero ;if SysDivMultB = 0 then movf SYSDIVMULTB,W movwf SysWORDTempA movf SYSDIVMULTB_H,W movwf SysWORDTempA_H clrf SysWORDTempB clrf SysWORDTempB_H call SYSCOMPEQUAL16 btfss SysByteTempX,0 goto ENDIF12 ;SysWordTempA = 0 clrf SYSWORDTEMPA clrf SYSWORDTEMPA_H ;exit sub return ;end if ENDIF12 ;Main calc routine ;SysDivLoop = 16 movlw 16 movwf SYSDIVLOOP SYSDIV16START ;set C off bcf STATUS,C ;Rotate SysDivMultA Left rlf SYSDIVMULTA,F rlf SYSDIVMULTA_H,F ;Rotate SysDivMultX Left rlf SYSDIVMULTX,F rlf SYSDIVMULTX_H,F ;SysDivMultX = SysDivMultX - SysDivMultB movf SYSDIVMULTB,W subwf SYSDIVMULTX,F movf SYSDIVMULTB_H,W btfss STATUS,C incfsz SYSDIVMULTB_H,W subwf SYSDIVMULTX_H,F ;Set SysDivMultA.0 On bsf SYSDIVMULTA,0 ;If C Off Then btfsc STATUS,C goto ENDIF13 ;Set SysDivMultA.0 Off bcf SYSDIVMULTA,0 ;SysDivMultX = SysDivMultX + SysDivMultB movf SYSDIVMULTB,W addwf SYSDIVMULTX,F movf SYSDIVMULTB_H,W btfsc STATUS,C incfsz SYSDIVMULTB_H,W addwf SYSDIVMULTX_H,F ;End If ENDIF13 ;decfsz SysDivLoop, F decfsz SYSDIVLOOP, F ;goto SysDiv16Start goto SYSDIV16START ;SysWordTempA = SysDivMultA movf SYSDIVMULTA,W movwf SYSWORDTEMPA movf SYSDIVMULTA_H,W movwf SYSWORDTEMPA_H ;SysWordTempX = SysDivMultX movf SYSDIVMULTX,W movwf SYSWORDTEMPX movf SYSDIVMULTX_H,W movwf SYSWORDTEMPX_H return ;******************************************************************************** ;Source: sound.h (34) TONE ;dim ToneLoop as word ;dim ToneLoop2 as word ;dim TonePeriod as Word ;If ToneFrequency = 0 Then Exit Sub movf TONEFREQUENCY,W movwf SysWORDTempA movf TONEFREQUENCY_H,W movwf SysWORDTempA_H clrf SysWORDTempB clrf SysWORDTempB_H call SYSCOMPEQUAL16 btfsc SysByteTempX,0 return ;TonePeriod = 50000 / ToneFrequency movlw 80 movwf SysWORDTempA movlw 195 movwf SysWORDTempA_H movf TONEFREQUENCY,W movwf SysWORDTempB movf TONEFREQUENCY_H,W movwf SysWORDTempB_H call SYSDIVSUB16 movf SysWORDTempA,W movwf TONEPERIOD movf SysWORDTempA_H,W movwf TONEPERIOD_H ;ToneFrequency = ToneFrequency / 100 movf TONEFREQUENCY,W movwf SysWORDTempA movf TONEFREQUENCY_H,W movwf SysWORDTempA_H movlw 100 movwf SysWORDTempB clrf SysWORDTempB_H call SYSDIVSUB16 movf SysWORDTempA,W movwf TONEFREQUENCY movf SysWORDTempA_H,W movwf TONEFREQUENCY_H ;For ToneLoop = 1 to ToneDuration movlw 1 movwf TONELOOP clrf TONELOOP_H SysForLoop2 ;For ToneLoop2 = 1 to ToneFrequency movlw 1 movwf TONELOOP2 clrf TONELOOP2_H SysForLoop3 ;Set SoundOut ON bsf PORTA,0 ;SysToneDelay movf TONEPERIOD,W movwf SysWaitTemp10US call Delay_10US ;Set SoundOut OFF bcf PORTA,0 ;SysToneDelay movf TONEPERIOD,W movwf SysWaitTemp10US call Delay_10US ;Next ;#4p Positive value Step Handler in For-next statement movf TONELOOP2,W subwf TONEFREQUENCY,W movwf SysTemp1 movf TONEFREQUENCY_H,W movwf SysTemp1_H movf TONELOOP2_H,W btfss STATUS,C incfsz TONELOOP2_H,W subwf SysTemp1_H,F movf SysTemp1,W movwf SysWORDTempA movf SysTemp1_H,W movwf SysWORDTempA_H clrf SysWORDTempB clrf SysWORDTempB_H call SYSCOMPEQUAL16 comf SysByteTempX,F btfss SysByteTempX,0 goto ENDIF8 ;Set LoopVar to LoopVar + StepValue where StepValue is a positive value incf TONELOOP2,F btfsc STATUS,Z incf TONELOOP2_H,F goto SysForLoop3 ;END IF ENDIF8 SysForLoopEnd3 ;Next ;#4p Positive value Step Handler in For-next statement movf TONELOOP,W subwf TONEDURATION,W movwf SysTemp1 movf TONEDURATION_H,W movwf SysTemp1_H movf TONELOOP_H,W btfss STATUS,C incfsz TONELOOP_H,W subwf SysTemp1_H,F movf SysTemp1,W movwf SysWORDTempA movf SysTemp1_H,W movwf SysWORDTempA_H clrf SysWORDTempB clrf SysWORDTempB_H call SYSCOMPEQUAL16 comf SysByteTempX,F btfss SysByteTempX,0 goto ENDIF10 ;Set LoopVar to LoopVar + StepValue where StepValue is a positive value incf TONELOOP,F btfsc STATUS,Z incf TONELOOP_H,F goto SysForLoop2 ;END IF ENDIF10 SysForLoopEnd2 return ;******************************************************************************** END Link al commento Condividi su altri siti More sharing options...
max.bocca Inserita: 8 ottobre 2023 Segnala Share Inserita: 8 ottobre 2023 Secondo me ti manca un filtro in uscita, lo schema hardware??? Link al commento Condividi su altri siti More sharing options...
twister1970 Inserita: 8 ottobre 2023 Autore Segnala Share Inserita: 8 ottobre 2023 non ho inserito nessun filtro in uscita perchè ho visto che qualcuno ci è riuscito senza usarne. I file hex che ho trovato in rete li ho testati con proteus e simulide e funzionano. vorrei capire da cosa dipende il problema. Link al commento Condividi su altri siti More sharing options...
click0 Inserita: 8 ottobre 2023 Segnala Share Inserita: 8 ottobre 2023 ma l'hardware? come è composto? Link al commento Condividi su altri siti More sharing options...
twister1970 Inserita: 8 ottobre 2023 Autore Segnala Share Inserita: 8 ottobre 2023 pic 16f84 e uscita diretta su port A0 Link al commento Condividi su altri siti More sharing options...
twister1970 Inserita: 8 ottobre 2023 Autore Segnala Share Inserita: 8 ottobre 2023 pic 16f84 e uscita diretta su port A0 Link al commento Condividi su altri siti More sharing options...
Gennar0 Inserita: 8 ottobre 2023 Segnala Share Inserita: 8 ottobre 2023 (modificato) 5 ore fa, twister1970 ha scritto: sull'uscita oltre al suono desiderato è presente un ticchettio. Sembrano i classici ticchettii che senti se applichi un ampli audio ai piedini di un micro. Secondo me è un disturbo dato da errata impedenza, visto che nello schema non vedo componenti attivi che amplificano. Prova anche a mettere un condensatore in serie da 10/22 µf e una resistenza. Modificato: 8 ottobre 2023 da Gennar0 Link al commento Condividi su altri siti More sharing options...
twister1970 Inserita: 9 ottobre 2023 Autore Segnala Share Inserita: 9 ottobre 2023 Avevo già provato a inserire i componenti citati. Non vorrei che i file che vedo in rete utilizzino una sorta di pwm software per generare il suono. Rallentando l'esecuzione tipo mettendo lo step a 1 e il quarzo a 1mhz il difetto si nota maggiormente. Non credo che derivi dai vari salti di frequenza ma sembra essere qualcosa collegato al clock del processore. Link al commento Condividi su altri siti More sharing options...
Messaggi consigliati
Crea un account o accedi per commentare
Devi essere un utente per poter lasciare un commento
Crea un account
Registrati per un nuovo account nella nostra comunità. è facile!
Registra un nuovo accountAccedi
Hai già un account? Accedi qui.
Accedi ora