Hello,
Thank you, I could initialize the buzzer with your recommendations. But now the problem is that the "bip" sound is very slow, I tried to change the duty cycle and the PWM frequency as bigmac suggested but I can´t solve that problem. Do you have any other idea?
This is my code:
; Include derivative-specific definitions INCLUDE 'derivative.inc' ; export symbols XDEF _Startup, main ; we export both '_Startup' and 'main' as symbols. Either can ; be referenced in the linker .prm file or from C/C++ later on XREF __SEG_END_SSTACK ; symbol defined by the linker for the end of the stack; variable/data sectionMY_ZEROPAGE: SECTION SHORT ; Insert here your data definition org $1000ActualRatio DC.B 0MyCode: SECTIONmain:_Startup: LDHX #__SEG_END_SSTACK ; initialize the stack pointer TXS CLI ; enable interruptsmainLoop: ; SCGC1: TPM3=1,TPM2=1,TPM1=1,ADC=1,IIC=1,SCI2=1,SCI1=1 LDA #$FF STA SCGC1 ; SCGC2: DBG=1,FLS=1,IRQ=1,KBI=1,ACMP=1,RTC=1,SPI=1 LDA #$FF STA SCGC2 ; Common initialization of CPU registers ; PTBDD: PTBDD5=1 */ LDA #$20 STA PTBDD ; PTBD: PTBD5=0 */ CLRA STA PTBDD ; PTAPE: PTAPE3=1,PTAPE2=1 LDA PTAPE ORA #$0C STA PTAPE ; PTDPE: PTDPE3=1,PTDPE2=1 LDA PTDPE ORA #$0C STA PTDPE; PTASE: PTASE7=0,PTASE6=0,PTASE4=0,PTASE3=0,PTASE2=0,PTASE1=0,PTASE0=0 LDA PTASE AND #$20 STA PTASE; PTBSE: PTBSE7=0,PTBSE6=0,PTBSE5=0,PTBSE4=0,PTBSE3=0,PTBSE2=0,PTBSE1=0,PTBSE0=0 CLRA STA PTBSE ; PTCSE: PTCSE7=0,PTCSE6=0,PTCSE5=0,PTCSE4=0,PTCSE3=0,PTCSE2=0,PTCSE1=0,PTCSE0=0 CLRA STA PTCSE ; PTDSE: PTDSE7=0,PTDSE6=0,PTDSE5=0,PTDSE4=0,PTDSE3=0,PTDSE2=0,PTDSE1=0,PTDSE0=0 CLRA STA PTDSE ; PTESE: PTESE7=0,PTESE6=0,PTESE5=0,PTESE4=0,PTESE3=0,PTESE2=0,PTESE1=0,PTESE0=0 CLRA STA PTESE ; PTADS: PTADS7=1,PTADS6=1,PTADS5=0,PTADS4=1,PTADS3=1,PTADS2=1,PTADS1=1,PTADS0=1 LDA #$DF STA PTADS ; PTBDS: PTBDS7=1,PTBDS6=1,PTBDS5=1,PTBDS4=1,PTBDS3=1,PTBDS2=1,PTBDS1=1,PTBDS0=1 LDA #$FF STA PTBDS ; PTCDS: PTCDS7=1,PTCDS6=1,PTCDS5=1,PTCDS4=1,PTCDS3=1,PTCDS2=1,PTCDS1=1,PTCDS0=1 LDA #$FF STA PTCDS ; PTDDS: PTDDS7=1,PTDDS6=1,PTDDS5=1,PTDDS4=1,PTDDS3=1,PTDDS2=1,PTDDS1=1,PTDDS0=1 LDA #$FF STA PTDDS ; PTEDS: PTEDS7=1,PTEDS6=1,PTEDS5=1,PTEDS4=1,PTEDS3=1,PTEDS2=1,PTEDS1=1,PTEDS0=1 LDA #$FF STA PTEDS PWM1_Init:; TPM1SC: TOF=0,TOIE=0,CPWMS=0,CLKSB=0,CLKSA=0,PS2=0,PS1=0,PS0=0 */ CLRA STA TPM1SC ; Disable device; TPM1C1SC: CH1F=0,CH1IE=0,MS1B=1,MS1A=1,ELS1B=1,ELS1A=1,??=0,??=0 */ LDA #$3C ; HERE I change the level but anything happens! STA TPM1C1SC ; Set up PWM mode ; TPM1MOD: BIT15=0,BIT14=0,BIT13=0,BIT12=1,BIT11=0,BIT10=0,BIT9=0,BIT8=0,BIT7=0,BIT6=1,BIT5=1,BIT4=0,BIT3=0,BIT2=0,BIT1=0,BIT0=1 */ LDA #$80 STA TPM1MOD ; PWM frequency; TPM1SC: TOF=0,TOIE=0,CPWMS=0,CLKSB=0,CLKSA=1,PS2=0,PS1=0,PS0=0 */ LDA #$08 STA TPM1SC ; Run the counter (set CLKSB:CLKSA)