Tim Nightingale
Posts: 1
Joined: Thu Sep 07, 2017 3:02 pm

Clock pulse generation using scratch

Thu Sep 07, 2017 3:45 pm

Hi Guys.
I am trying to create a stream of clock pulses at between 1MHz and 2.6MHz to drive some logic circuits.

This should give me a stream of things to input and play with

I am rubbish at software having not programmed anything for 20 years so Scratch seemed to be a good option.

I know that I can use a PWM output on a gpio pin but it only seems to run at about 1.5K.

I can only get this using scratch 1.4 and not scratch 2.

I have a shiney new pi3 with the latest noobs install.

Can anyone suggest anything for me.


Posts: 1241
Joined: Wed Jun 12, 2013 12:41 pm
Location: Stuttgart Germany
Contact: Website

Re: Clock pulse generation using scratch

Sun Sep 10, 2017 1:41 pm

Hello, MHz clock rates are far beyond the capabilities of scratch.
https://github.com/Guzunty/Pi/tree/master/src/gzlib/src, gz_clock.c
http://abyz.co.uk/rpi/pigpio/examples.h ... inimal_clk
for code which uses GPIO4 with the hardware clock generator.
I used this feature to drive external microcontroller with fixed clock ranges up to 8MHz.

Hope this helps,

Posts: 1151
Joined: Mon Oct 29, 2012 8:12 pm
Location: Vancouver Island
Contact: Website

Re: Clock pulse generation using scratch

Sun Sep 10, 2017 9:52 pm

I'm astonished you managed to get it that fast with Scratch - and I wrote the stuff :-)

GHP is right- use pigpio directly. Take a look at joan's site (abyss.co.uk/rpi/pigpoi) and see if that makes sense and do ask joan questions where needed.

Strictly speaking it would probably be possible to drive pigpio from Scratch to do what you want; that is after all how the gpioserver does things anyway. Wouldn't that be fun; if you can come up with a plausible set of requirements and post them here I might even do it just for fun.
Making Smalltalk on ARM since 1986; making your Scratch better since 2012

Return to “Scratch”