<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Buzzer code example in CodeWarrior for MCU</title>
    <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Buzzer-code-example/m-p/148917#M3489</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I checked the example but it&amp;nbsp;demonstrates interrupts from the timer&amp;nbsp;and uses general purpose timeouts, but it doesn't show how to configure or use the buzzer of the microcontroller. Do you know where can I find another example?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 28 Mar 2012 21:09:23 GMT</pubDate>
    <dc:creator>EducaFree</dc:creator>
    <dc:date>2012-03-28T21:09:23Z</dc:date>
    <item>
      <title>Buzzer code example</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Buzzer-code-example/m-p/148915#M3487</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN&gt;Hi,&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm trying to configure the buzzer of my microcontroller&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;(MC9S08QE128) in CodeWarrior using the assembly language,&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;but I can't find any example or documentation about this topic.&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I hope you can give me an example in order to configure the&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;buzzer.&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you for your help.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 27 Mar 2012 01:46:43 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Buzzer-code-example/m-p/148915#M3487</guid>
      <dc:creator>EducaFree</dc:creator>
      <dc:date>2012-03-27T01:46:43Z</dc:date>
    </item>
    <item>
      <title>Re: Buzzer code example</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Buzzer-code-example/m-p/148916#M3488</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you are using CodeWarrior for MCUs V10.2, a pure assembly-language example program for the &lt;SPAN&gt;MC9S08QE128 can be found at:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;{CodeWarrior installation directory}\MCU\CodeWarrior_Examples\HC_Examples\mc9s08qe128_demo\.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;For documentation, look under&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;{CodeWarrior installation directory}\MCU\Help\PDF&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;for the HCS08-RS08_Assembler_MCU_Eclipse.pdf manual.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Hope this helps,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;---Tom&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 27 Mar 2012 19:20:51 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Buzzer-code-example/m-p/148916#M3488</guid>
      <dc:creator>J2MEJediMaster</dc:creator>
      <dc:date>2012-03-27T19:20:51Z</dc:date>
    </item>
    <item>
      <title>Re: Buzzer code example</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Buzzer-code-example/m-p/148917#M3489</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I checked the example but it&amp;nbsp;demonstrates interrupts from the timer&amp;nbsp;and uses general purpose timeouts, but it doesn't show how to configure or use the buzzer of the microcontroller. Do you know where can I find another example?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 28 Mar 2012 21:09:23 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Buzzer-code-example/m-p/148917#M3489</guid>
      <dc:creator>EducaFree</dc:creator>
      <dc:date>2012-03-28T21:09:23Z</dc:date>
    </item>
    <item>
      <title>Re: Buzzer code example</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Buzzer-code-example/m-p/148918#M3490</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I do not have any assembly code.&amp;nbsp; However, if I assume that you are using the DEMOQE board, and with a jumper installed at the J19 position, the buzzer device is&amp;nbsp;effectively connected between PTB5 and ground.&amp;nbsp; This is also the pin associated with TPM1CH1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The simplest way to operate the buzzer is to set the TPM channel for edge-aligned PWM operation,&amp;nbsp;with a frequency of 4kHz, the resonant frequency of the buzzer, and 50 percent duty.&amp;nbsp; For PWM mode, channel interrupts are not necessary.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;TPM1MOD register setting will determine the PWM frequency, taking into account the bus clock you are using&amp;nbsp;and the TPM prescaler.&amp;nbsp; TPM1C1V register will determine the duty, and should be set to (TPM1MOD + 1) / 2 for 50 percent.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Mac&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 30 Mar 2012 22:14:45 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Buzzer-code-example/m-p/148918#M3490</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2012-03-30T22:14:45Z</dc:date>
    </item>
    <item>
      <title>Re: Buzzer code example</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Buzzer-code-example/m-p/148919#M3491</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you, I could initialize the buzzer with your recommendations. But&amp;nbsp;now the problem is that the "bip" sound is very slow, I tried to change the duty cycle and the PWM&amp;nbsp;frequency as bigmac suggested but I can´t solve that problem. Do you have any other idea?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is my code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;; 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)&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Oct 2020 08:50:47 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Buzzer-code-example/m-p/148919#M3491</guid>
      <dc:creator>EducaFree</dc:creator>
      <dc:date>2020-10-29T08:50:47Z</dc:date>
    </item>
    <item>
      <title>Re: Buzzer code example</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Buzzer-code-example/m-p/148920#M3492</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Since you have not initialised the ICS module (nor trimmed the internal reference), the power up default bus frequency will lie within the range 4.4 MHz +/-25 percent.&amp;nbsp; This will dictate the frequency accuracy of the generated tone.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can see some problems with your code -&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;The TPM1C1SC value of $33 seems inappropriate.&amp;nbsp; I might have expected a value of $38 or $3C.&lt;/LI&gt;&lt;LI&gt;You have not taken into account that the TPM1MOD register is 16-bit.&amp;nbsp; You are setting the high byte only.&amp;nbsp; For a nominal 4.4 MHz bus with TPM prescale of 1, I would expect a 16-bit value of 1100 decimal.&lt;/LI&gt;&lt;LI&gt;You have not initialised TPM1C1V 16-bit register - the duty will be uncontrolled (and could even be 100 percent, i.e no output).&lt;/LI&gt;&lt;/OL&gt;&lt;PRE&gt;TPMMODVAL  EQU 1099      ; Period of 1100 TPM clock periodsPWMDUTY    EQU (TPMMODVAL+1)/2...     CLR   TPM1SC        ; Disable TPM1 module     MOV   #$38,TPM1C1SC ; Edge aligned PWM mode     LDHX  #TPMMODVAL    ; Nominal 4kHz TPM overflow rate     STHX  TPM1MOD     LDHX  #PWMDUTY      ; 50 percent duty     STHX  TPM1C1SC     MOV   #$08,TPM1SC   ; Enable TPM1, prescale 1&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note that the value of TPMDUTY automatically changes should&amp;nbsp;TPMMODVAL be altered, perhaps to adjust the&amp;nbsp;for a different bus frequency.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Once initialised, you&amp;nbsp;might also use some macros to control the buzzer.&amp;nbsp; In this case, you would probably not enable the TPM1 module within the initialisation code above.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;BUZZ_ON: MACRO         MOV  #$08,TPM1SC  ; Enable TPM1 module         ENDMBUZZ_OFF:MACRO         CLR  TPM1SC       ; Disable TPM1 module         ENDM&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Mac&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Oct 2020 08:50:49 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Buzzer-code-example/m-p/148920#M3492</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2020-10-29T08:50:49Z</dc:date>
    </item>
  </channel>
</rss>

