0

I tried to generate a 40khz pulse to the GPIO pin of my ultrasonic sensor in raspberry pi. I used the pulse generator instrumentation, but the pulse is not accurate: the oscilloscope displays only 10khz.

I modified configuration parameters:

fixed-step
sample time is auto/1e-08
solver is auto/discrete

I also have tried various ways to create a square pulse: function sign(sin(2*pi*40000t)), PLL block, repeating sequence, signal generator combined with sum, compare to zero, etc. All of these display correctly on the scope, but do not deploy accurately.

I doubted the raspberry pulse generatior, so I used python to drive the GPIO pin; results are very accurate. I worry that the Simulink complier doesn't properly support raspberry or the sample time.

Any suggestions?

This is the model I used to generate 40khz pulse.

enter image description here

with period is 0.000025s,pulse width 50%, Solver type is fixed-step.

https://i.stack.imgur.com/QP9Hx.png

The oscilloscope display as the following figure:

Prune
  • 76,765
  • 14
  • 60
  • 81
  • Cleaned up wording. – Prune Aug 25 '16 at 21:52
  • I couldn't see the oscilloscope figure. Is it a pulse as expected, but with the period out by a factor of x4? If so have you tried setting the period to 160kHz to see if that results in 40kHz in hardware? This isn't a solution but would help with trouble shooting. – kabdulla Aug 27 '16 at 15:31
  • What do you mean by `sample time is auto/1e-08`? Does that imply that your model step function runs with 100 MHz? And the Raspberry Pi itself even has a much higher clocking frequency? – Matthias W. Aug 30 '16 at 21:00

0 Answers0