A FREE frequency generator if you have a Raspberry Pi

The Raspberry Pi as a frequency generator

I was experimenting with the Pifm code, and wanted to know what sort of frequencies I could get from the GIPO_4 pin 7.

So I wrote some test code, the program is very simple, and only outputs a square wave. No extra things needed... BUT the frequency range is from 130 kHz to 250 MHz. I have only tested to 250 MHz, I think this is the limit. Some defines in the code for the PLL frequency are likely wrong. Missing a factor 2, anyways the calculation of the fractional divider is really close.

A free signal generator from 130 kHz to 250 MHz when you have a Pi is nice thing to have.

formatting link

Compile that code with: gcc -Wall -O4 -o freq_pi freq_pi.c -std=gnu99 -lm

Install it with: sudo cp freq_pi /usr/local/sbin/

Connect your frequency counter to GPIO header pin 7.

Run it like this for 130 kHz: freq_pi -f 130000 error on my frequency counter 3 Hz.

Run it like this for 107.2 MHz: freq_pi -f 107200000 dunno the error, but it wipes out my FM station at 107.2

Run it like this for 250 MHz: freq_pi -f 25000000

Error is a few kHz on xpsa spectrum analyzer, but that could as well be the 30 kHz LO offset from the Elonics 4000 tuner..

Nice to test LC circuits, filters, and the 3.3V amplitude is more than enough for most things, will even drive 3.3V and 5 V logic.

Reply to
Jan Panteltje
Loading thread data ...

The Raspberry Pi as a frequency generator Version 0.2 is on my site:

formatting link

130 kHz to 250 MHz output

Functionality is basically the same, but added some info on phase noise. When using a fractional divider and when the fractional part is not zero, then the frequency will wobble around the requested one. freq_pi -v -f 1000001 will show the fractional part, so you are warned. For simple testing this is probably not important, but gets very important if you drive some modulator or something.

Next project :-)

No it is not a V3. Did the Aliens take my precision screwdriver ??? More in the NEXT issue of ....

!
Reply to
Jan Panteltje

In freq_pi.c I see struct GPCTL defined in a way that doesn't look right. Why aren't all structure fields on unsigned int instead of char? I guess you know this works. I'll have to experiment some to prove what gcc does on RPi.

Reply to
mscottbarnes

On a sunny day (Tue, 9 Sep 2014 11:11:56 -0700 (PDT)) it happened snipped-for-privacy@gmail.com wrote in :

That structure definition is part of Pifm.c, I did not write it. But it works, Look at the Broadcom chip I/O document, can't remember what is is called, on my system BCM2835-ARM-Peripherals.pdf IIRC I checked that and it matches the registers. If you find something peculiar let me know.

Reply to
Jan Panteltje

hello sir . i need to generate a frequency of 14.318mhz with an RPI , is that possible with your code ?

Reply to
abir.bayoudh

OMG, I totally want a ~200 MHz sig gen. (Well really 1/2 of 385 MHz. If I frequency mod our diode laser there, the side bands, as imaged in our Fabry-Perot cavity, will overlap. It would be a nice way to measure the length.)

Am I going to have to learn linux to run the Raspberry Pi?

George H.

Reply to
George Herold

The length of the FP cavity. The cavity is 20 cm. It's confocal. a tutorial link...

formatting link

Geo

Reply to
George Herold

On a sunny day (Fri, 12 Jun 2015 17:28:40 -0700 (PDT)) it happened snipped-for-privacy@gmail.com wrote in :

milli Hertz, I think not.

MHz (Mega) yes, but there is a wobble around that frequency caused by the changing division factor. So it depends on what you want to do with it. Also the output is a square wave, so without further filtering you get a lot of harmonics.

If you download the source code this is explained there. It refers to BCM2835-ARM-Peripherals.pdf that you can find with google, and should read.

Reply to
Jan Panteltje

On a sunny day (Fri, 12 Jun 2015 19:12:10 -0700 (PDT)) it happened George Herold wrote in :

See my reply to other poster about the DDS wobble around the specified frequency.

Absolutely :-)

Reply to
Jan Panteltje

Ok, have compiled this, but when I try to run it I get can't open dev/mem

I'm assuming it's a permission thing. but did you have this problem and what did you do to workaround. Thanks in advance.

Reply to
bcasey

I don't see the article you are referring to, but the usual solution to permission problems on the Raspberry Pi is to type "sudo" in front of the command. You should be familiar with this if you have done some little admin things on the Pi.

Reply to
Rob

for obvious security reasons only root can open /dev/mem

sudo or being logging an as root should be the answer

-Lasse

Reply to
Lasse Langwadt Christensen

pin 7.

a square wave.

s really close.

ice thing to have.

ner..

enough for most things,

They have Windows 10 on the Raspberry Pi, but if you are going to do this s ort of stuff I would DEFINATELY learn linux...you can make a USB with a "li ve linux" that you can run from your normal computer with windows or whatev er you use. And run it off the USB to test it - it's called Live Linux

The RPi uses Raspbian...a variant of Linux Debian

If you want to get Linux Debian onto a USB to try out for free on any compu ter let me know I will instruct you fully

Reply to
raserppsprograms

Please help me get this running

I compiled it as instructed and it brought up a few errors - little things in the source code.

I'm not efficient in the art of C and have tried to sort the little things - I am thinking it is dependancies on my Pi - maybe Im using a different something or other

Reply to
raserppsprograms

You will need to provide more information. What errors are you getting?

Reply to
DemonicTubes

Try comp.lang.c

Reply to
Cursitor Doom

What does the flowchart for this code look like?

Reply to
overlordjosh13

pin 7 doesn't give any output at all

compile gives the following error

pi@raspberrypi:~/freq_pi $ gcc -Wall -O4 -o freq_pi freq_pi-0.2.c -std=gn u99 -lm freq_pi-0.2.c: In function ?start_rf_output?: freq_pi-0.2.c:183:1: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] ACCESS(CM_GP0CTL) = *((int*)&setupword); ^

anyone an ideas?

thanks

Reply to
sohbay

The obvious thing seems to be to just use a different output pin and edit the source code accordingly.

Reply to
Cursitor Doom

gnu99 -lm

k strict-aliasing rules [-Wstrict-aliasing]

Its a warning? Otherwise it compiles and works?

What happens if you remove the -Wall?

Owen

Reply to
Owen Cook

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.