stm32f407 discovery board as a 100MHz FM transmitter using crystal feedback trick

Hi All,
     It's been a long time I haven't updated my blog coz it is hard to get some free time.  Anyways, I have a small hack to share now.

This is a very simple hack, the aim of this project is to transmit a song stored in STM32F407 flash memory over air by FM at 100MHz. At first you can have a look at the below video, a weird demo taken through my mobile phone. A fixed song is repeatedly transmitted from the stm32f407 discovery and it received on a mobile phone FM radio which is tuned at 100MHz.

 




How it works?

 A song + voice in wav format is saved in the flash memory from an offset after application code.
The *.wav can be directly dumped into the flash say from address 0x08005000 after renaming the file as *.bin.  This can be done directly by using ST-LINK utility in windows.

Now a small application code is written which starts at 0x08000000 which will read the song file at location 0x08005000 and throws the bytes to a PWM pin. This is done repeatedly in an infinite loop by a timer interrupt which is configured according to the sampling rate of song+voice wav. It can be done by DMA as well.

Now one more thing, the system clock is derived from 8MHz external crystal oscillator. Using the internal PLL, the system clock is set to 100MHz. Now the Master Clock Output option is enabled to toggle a pin (PA8) at 100MHz. So the carrier frequency for FM is ready!

Now if we run the code, the PWM pin (PE9) will get the song data in a pulse width modulated format. An RC filter is connected to this pin to demodulate it and thus we will get a decent analog song signal. If we connect a earphone or an amplifier over here, we should be able to hear the song.

 Fine, now how to transmit the song over air?

"Crystal feedback hack"

The trick over here is to disturb the crystal oscillator according to the song data. For this a 22K resistor is connected from the analog song signal to one of the crystal PIN. This setup will load the crystal circuitry according to the instantaneous amplitude of song signal. The frequency of the crystal is getting affected by this. In simple words, frequency modulation is happening over here. The song data is getting modulated over 8MHz.

We already set the MCO pin to toggle at 100MHz. Since the 100MHz is generated from the 8MHz crystal clock, the modulation will be observed in the 100MHz signal also (obviously magnified). The feedback resistor 22K is selected in such a way that it won't affect the working of the crystal circuitry and won't do over modulation. We can play with these values later.


Done!

Sorry, need to connect an antenna on pin PA8 to transmit the signal properly over air.
For time being, I connected a small female jumper wire which was more than enough for the demo.


Yes, now it is done. :)

I am getting range of around 30 meters with this simple 20 cm wire antenna. If we connect a proper quarter wave length wire/telescopic antenna, the range may increase beyond 100meters as well.


(In below photo you can see a 22K resistor connected from RC filter output to crystal pin.
That is the only external hardware modification for FM modulation)



RC filter:
 R = 100 ohms
 C = 0.1 uF


Feedback resistor:
  R = 22K. (Remove R24 and short those contacts and connect feedback resistor from filter output to R24 pin as in the above photo)

The same experiment can be done by connecting an SD card and can transmit the song over the air the same way...... May be we can use helix mp3 decoder to play mp3 files from sd card and can do the same crystal feedback hack...


Thanks to ST for providing a nice GUI tool called stm32CubeMX which generates the initialization code for clock, MCO settings, timer settings etc. This makes the development process much easier and no need to dig into the datasheet to configure the registers.



Source Code:
https://github.com/vinodstanur/stm32f407-fm-transmitter 


Hex file with audio:
STM32F407_FLASH_HEX.hex


Disclaimer:
  Try it under your own risk.
 This project is for educational purposes only and is not intended to interfere with any radio channels in restricted/commercial bands. Neither site nor I, am liable for careless actions. Please check for the legality before attempting the project within your area. Since the GPIO toggling is not sinusoidal, higher harmonics will be there in the transmitted signal, so be careful while trying it out as it can transmit harmonics in restricted band.

9 comments :

  1. Cool hack! I wonder if we can hack this up into a super cheap RF transmitter/receiver:D

    ReplyDelete
    Replies
    1. This will not be cheap coz MCU is expensive, also the audio quality will not be that good compared to a proper FM transmitter. This is just a hack for fun, thats all :)

      Delete
    2. true, unless we use the STM32f030 and transmit at 48MHz frequency. I was thinking of transmitting data instead of audio to another STM32F030 MCU. the receiver circuit might be too much of a hassle though. haha. :D

      Delete
  2. Hi can you tell me the fuse settings for the atmega16 voice echo.Thsnks..
    Is it
    L-ef
    H-d9

    ReplyDelete
  3. Hy I tried replicating your project.
    I get sound going to crystal (checked with speaker) but on output pin PA8 I get only currier 100MHz without modulation. I do not have oscilloscope to check but on my radio when I start STM32 I get a change from static to silent. I believe it is emitting only 100MHz currier without modulation. Can Someone help?
    I rechecked everything and it is all connected like you did it.
    In summary 22k resistor is connected to R24 witch is shorted.R25 is left as is because it already a short. capacitor is connected to GND and 100R resistor is connected to PE9. Also have antenna like you. Have I missed something?

    ReplyDelete
    Replies
    1. Let me check and will get back to you soon..

      Delete
    2. I made some photos of how I connected it and schematics.

      https://postimg.org/image/l1xmwdh93/
      https://postimg.org/image/9bjpezogn/

      Thanks


      Delete
    3. Hi,
      Your schematic seems fine. Have you tried the .hex file https://raw.githubusercontent.com/vinodstanur/stm32f407-fm-transmitter/master/HEX_FILE_WITH_AUDIO/STM32F407_FLASH_HEX.hex ?

      Delete
  4. Hi
    I want to know how modulated frequency ?(how work FM in this project)

    ReplyDelete