Skip to main content
Visitor II
June 21, 2024
Solved

Low Voltage for High Logic Level while using timer pin as pwm

  • June 21, 2024
  • 3 replies
  • 3542 views

Problem Statement: Amplifying Low-Amplitude Audio Signal on STM32 Nucleo64 Board

Hello STM community! I'm new here and seeking some guidance. I'm working on a project using the STM32 Nucleo64 board to create an announcement maker. My setup involves using an interrupt to handle an 8kHz frequency sampled audio, which is converted into an array. This array is then outputted from a PWM pin.

However, I'm facing an issue with the audio amplitude. The output signal amplitude is very low, less than 3.3V, which is insufficient to trigger the amplifier circuit and effectively broadcast the audio.

Is there a way to internally amplify the signal output coming from the STM32 board? Any suggestions or guidance would be greatly appreciated!

    This topic has been closed for replies.
    Best answer by mƎALLEm

    The PCM data ranges from 0-255 that is it's 8bit data

     

    Yato_0-1718962672311.png

     


    Indeed, very low data range scale vs the full scale of the timer counter/CCR which are 16-bit.. If you multiply these values by 256 (to amplify the values)? what happens?

    You can also see this video starting from 3:27. I think you can start by generating a sine wave before moving to generate audio signals to validate the theory and the HW!

    3 replies

    Technical Moderator
    June 21, 2024

    Welcome, @Yato, to the community!

    An STM32 can be operated with a maximum of 3.6V, from which the internal DAC is also operated. For this reason, no higher voltage can be output in principle.

    However, you can amplify the signal, whereby the choice of amplifier depends on the load to be driven, e.g. a loudspeaker with which parameters?

    Regards
    /Peter

    YatoAuthor
    Visitor II
    June 21, 2024

    I am using a 8ohm speaker. I know that the stm32 has limitation of 3.3V and I am using two stage amplifier (you may see the circuit in the other comment I have replied to). I am using GPIO pin PA0

     

    Technical Moderator
    June 21, 2024

    Hello and welcome to the community?

    Not sure what do you mean by "I'm facing an issue with the audio amplitude. The output signal amplitude is very low, less than 3.3V". Do you mean the GPIO pin voltage level? how much? which GPIO pin?

    As you generating an audio signal using PWM, did you add an external filter? do you mean the low voltage is on the filter output?

    You can also refer to these articles:

    Custom Signal generation using PWM and DMA

    How to generate a sine wave using PWM and RC filter with the STM32 Part1

    How to generate a sine wave using PWM and RC filter with the STM32? Part2

    YatoAuthor
    Visitor II
    June 21, 2024

    Yato_0-1718960126155.png

    I am using tim2 ch1 for pwm generation , the pin I am using is PA0 but I also tried with PC6 that is tim8 ch1. The main issue is that I am getting less then 1V on signal output (GPIO Output) and after this circuit that i attached , The audio is audible but the loudness is way less than my requirement. Just for references I tried the same algorithm with another Microcontroller (not STM) with 5V output voltage using the same data the loudness was excellent. I mean even if we go by the logic that STM32 has 3.3V output Voltage I can understand that the level of loudness will be slightly low but actually it way less. The STM 32 audio sound can be heard for the distance of 100cm  around 3 feets but with that different microcontroller the whole room is covered even in slightly noisy environment.

     

    Technical Moderator
    June 21, 2024

    I am using tim2 ch1 for pwm generation , the pin I am using is PA0 but I also tried with PC6 that is tim8 ch1. The main issue is that I am getting less then 1V on signal output (GPIO Output)



    Just for references I tried the same algorithm with another Microcontroller (not STM) with 5V output voltage using the same data the loudness was excellent. I mean even if we go by the logic that STM32 has 3.3V output Voltage

    Sorry, but how you did measure the IO pin voltage? during the PWM generation? I think your data does not reach the full scale of your 16 bit timer as you are using the same data from a 5V MCU. You need to adapt your data according the STM32 timer.  Maybe you need to amplify your signal in your lockup table.

     

    Technical Moderator
    June 21, 2024

    In addition to that: your amplifier circuit is a simple double inverter, where you can omit the second stage and connect the speaker directly to Q1. Q2 has no advantage, only the disadvantage that you permanently connect the speaker to 5V when the PWM output is inactive, which dynamic speakers don't like at all.

    To remove the DC offset of the PWM signal, you should provide a capacitive coupling and also connect a real audio amplifier, e.g. the TS4871. In its data sheet you will find an example schematic that already contains the capacitive coupling mentioned above.