ranib
Posts: 5
Joined: Sun Nov 03, 2019 8:18 am

Re: Generate 100Khz amplitude modulated signal

Tue Nov 05, 2019 11:51 am

Thank you everybody for your responses and lively discussion.

It seems after reading your posts that my needs require more than software-based solution or to use something other than the raspberry pi.

Best,
Rani

User avatar
Gavinmc42
Posts: 4556
Joined: Wed Aug 28, 2013 3:31 am

Re: Generate 100Khz amplitude modulated signal

Wed Nov 06, 2019 12:05 am

Analog signals are hard to make with digital devices.
But it can and has been done with a few external parts.
Something that just came to mind was the Parallax Propeller and it's Sigma Delta method of generating analog.

The Pi's have Digital audio hardware, will it go as high as 100KHz?
Alternatively a SPI based DAC and DMA.
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

gordon77
Posts: 5133
Joined: Sun Aug 05, 2012 3:12 pm

Re: Generate 100Khz amplitude modulated signal

Wed Nov 06, 2019 2:29 pm

I was interested in the pwm to am idea. So I did a bit more computing.

Figure 1. Full Spectrum of modulated pwm, 10kHz carrier with 100Hz modulation
Figure 2. Spectrum around 10kHz carrier
Figure 5. Phase of above. As far as I can see both sidebands are in same sense.
Figure 3. 10kHz filter
Figure 4. Input (pwm) and Output(am).

I may get around to try and build it for real.

Maybe not what the Op wanted.
Attachments
plots2.jpg
plots2.jpg (83.24 KiB) Viewed 1030 times

User avatar
Gavinmc42
Posts: 4556
Joined: Wed Aug 28, 2013 3:31 am

Re: Generate 100Khz amplitude modulated signal

Thu Nov 07, 2019 2:34 am

How fast can the PWM go?
Audio range is up to 20KHz.
Manual says it can take a 100MHz nominal clock.
That is more than a few bits to play with.
100KHz is not that fast for digiatl circuits.

Could the PWM do it?
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

User avatar
joan
Posts: 15001
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Generate 100Khz amplitude modulated signal

Thu Nov 07, 2019 9:00 am

The PWM peripheral can easily generate 100 kHz. It can use the normal on-board clock sources, in particular the 19.2 MHz crystal and the 500 (750 BCM2711) MHz PLLD.

http://abyz.me.uk/rpi/pigpio/pigs.html#HP

If all you need is a square wave you could just use one of the GPIO connected to the clock.

http://abyz.me.uk/rpi/pigpio/pigs.html#HC

N.B. The BCM2711 clock 2 channel behaves differently to earlier Pis. Details not known.

User avatar
Gavinmc42
Posts: 4556
Joined: Wed Aug 28, 2013 3:31 am

Re: Generate 100Khz amplitude modulated signal

Thu Nov 07, 2019 11:11 am

100KHz sin wave.
PWM has a 16 x 32bit fifo.
Plenty of resolution in 32bits, but a 16 word FiFo buffer, is that enough?
Or will DMAing more values be needed?
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

gordon77
Posts: 5133
Joined: Sun Aug 05, 2012 3:12 pm

Re: Generate 100Khz amplitude modulated signal

Thu Nov 07, 2019 11:33 am

Note all my workings above are on a data file which represents a pwm signal sampled.

Anyone got an oscilloscope to see what this produces ?

Code: Select all

import RPi.GPIO as GPIO
from time import sleep
import math

pin = 32				
GPIO.setwarnings(False)			
GPIO.setmode(GPIO.BOARD)		
GPIO.setup(pin,GPIO.OUT)
pi_pwm = GPIO.PWM(pin,40000)		
pi_pwm.start(0)				
while True:
    for deg in range(0,361,1):
        am_signal = 10 + (1 + math.sin(deg/6.29)) * 40
        pi_pwm.ChangeDutyCycle(am_signal)
        sleep(0.003)

User avatar
joan
Posts: 15001
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Generate 100Khz amplitude modulated signal

Thu Nov 07, 2019 12:00 pm

http://abyz.me.uk/rpi/pigpio/piscope.html may show if it is capable of producing a first approximation.

gordon77
Posts: 5133
Joined: Sun Aug 05, 2012 3:12 pm

Re: Generate 100Khz amplitude modulated signal

Thu Nov 07, 2019 4:15 pm

Thanks.

Can you modulate the pwm signal generated with pigpio?

User avatar
joan
Posts: 15001
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Generate 100Khz amplitude modulated signal

Thu Nov 07, 2019 5:18 pm

pigpio only supports hardware timed PWM.

To generate a 40 kHz signal using pigpio you would have to use one of the GPIO capable of being connected to the PWM peripheral (12/13/18/19).

http://abyz.me.uk/rpi/pigpio/python.html#hardware_PWM

E.g. pi.hardware_PWM(40000, 500000) for a 40 kHz square wave.

The modulation

Code: Select all

for deg in range(361):
   am_signal = int(10000 * (10 + (1 + math.sin(deg/6.29)) * 40))
   pi.hardware_PWM(40000, am_signal)
   time.sleep(0.003)
The weak link will be the 3 millisecond delay. pigpio Python has a client/server model so that will be heavily perturbed by any network delays.

Return to “Beginners”