Waveform Generator

Mad Professor

Senior Member
Good Day All.

Can anyone please tell me if I can use my PicAxe 18x or any other PicAxe chip as a Waveform Generator.

Let me try and explain what it is I would like to try and do.

I do alot of work with Engine Management ECU's, And I need some way of feeding a Crank and or Cam sensor signal into the ECU's.

Most cars that I have worked on to date, seem happy to have a Square or Triangle waveform signal feed into them to work.

If possible I would like to be able to change waveform from, Square, Triangle, Sine or Sawtooth, at a push of a button.

I also know that there are loads of trigger pattens out there.

But there is only three types that I use with my type of Engine Management, witch are
Ford (36-1), 36 Teeth minus one, 10 Deg per tooth. < Click Link For Picture.
Bosch (60-2) 60 Teeth minus two. 6 Deg per tooth. < Click Link For Picture.
Rover (36-1-1).

So can anyone please tell me if this is possible, and if so how hard it will be, and what would be the best way about doing it.

Thanks for your time.
 
Last edited:

Tom2000

Senior Member
It all depends upon the cleanliness of the signal that your ECU needs, and the maximum speed.

Square wave generation is pretty simple.

You can generate your triangle wave from an expression.

For a sine wave, you'll probably have to synthesize the waveform from a table, limiting both your maximum speed and signal cleanliness.

Here's a sine table you might use for your synthesis. Depending upon your cleanliness requirements, you might want to shorten it up.

Code:
#rem  
  '128 byte sin table (addr 0->127, vals 0->254)
  
  symbol tblsize = 127
  
  eeprom 0,(127,133,139,146,152,158,164,170)
  eeprom 8,(176,181,187,192,198,203,208,212)
  eeprom 16,(217,221,225,229,233,236,239,242)
  eeprom 24,(244,247,249,250,252,253,253,254)
  eeprom 32,(254,254,253,253,252,250,249,247)
  eeprom 40,(244,242,239,236,233,229,225,221)
  eeprom 48,(217,212,208,203,198,192,187,181)
  eeprom 56,(176,170,164,158,152,146,139,133)
  eeprom 64,(127,121,115,108,102,96,90,84)
  eeprom 72,(78,73,67,62,56,51,46,42)
  eeprom 80,(37,33,29,25,21,18,15,12)
  eeprom 88,(10,7,5,4,2,1,1,0)
  eeprom 96,(0,0,1,1,2,4,5,7)
  eeprom 104,(10,12,15,18,21,25,29,33)
  eeprom 112,(37,42,46,51,56,62,67,73)
  eeprom 120,(78,84,90,96,102,108,115,121)
#endrem
For your timing, investigate the pulsout command. You can set delays by sending a pulsout command to a dummy pin.

For sine and triangle generation, you can either generate your signal using PWM and filtering, or send each value to a DAC chip in parallel, using a number of processor lines.

That should get you started. Go forth and punch calculator buttons!

Have fun,

Tom
 

Dominic B

New Member
As far as the switching between different wave types goes, that's very simple. You can just use something like:

Code:
main:
	if pin0 = 1 then square
	if pin1 = 1 then triangle
	if pin2 = 1 then sawtooth
	if pin6 = 1 then sine
	goto main
square:
	if pin7 = 1 then main
	high 0
	pause 1000
	low 0
	pause 1000
	goto square
Just stick a PTM to each of the inputs and it's done.

The only disadvantage is it's not very easy to reset once in a wave form, but you can just put a PTM to reset it on pin 4 of the 18X instead. No idea how to do the other wave lengths, so left them out

Good luck with the other waveforms though!
 

Dippy

Moderator
What sort of frequencies are you wanting? What sort of resolution?
PICAXE won't be able to do anything really high.
 

gengis

New Member
If your aim is to learn, programming or just to make a silk purse from a sow's ear (and slow speed is good enough) you can do it with a picaxe.

There are lots of "function generator" chips that already do what you want with better resolution and frequency range. You'd be better off with one of those - and perhaps - control the generator chip with an 'axe.

State the resolution you need and frequency - square waves are easy, triangle waves only a little bit harder, sine waves are harder by an order of magnitude.
 

hippy

Technical Support
Staff member
At 3600 RPM that's a revolution every 16ms, not a lot of time to bang out any waveform and harder if you need a waveform per cyclinder, and it gets harder as the RPM goes up.

Not sure why you need a selection of waveforms or what you're ultimately trying to achieve. It will probably be advantageous to specify what the problem you're trying to solve is. Others have done ECU projects so a forum search may also help.
 

moxhamj

New Member
The good old XR2206 has been around forever and is great for square, triangle and sine. Goes up to 1Mhz.

I do wonder though if there could be a hybrid picaxe solution, with the picaxe reading the keypresses and then changing pins, resistors etc on a XR2206. Eg with 4016 gates. You could then program the frequency and the waveform. You could even measure the actual frequency using a picaxe with pulsin, and then display this on an LCD. And you could tweak the frequency with switched resistors or capacitors, all under picaxe control.

Tom2000's code will work fine for slow sine.
 
Last edited:

Mad Professor

Senior Member
Thanks for eveyones replys so far.

I was hoping to have a working RPM range of 500-5000rpm, I know the higher the rpm the less time I have to work with.

As for frequency that is a very good point I have not looked into that yet, as frequency's go over my head, can anyone please tell me how I can work out what I would need.

As square waves are the easest to work with I think it would be best to start there, and work on up.

I will edit my 1st post shortly with a few pictures of the Trigger Pattens I am wanting to make.

Thanks again for your time and help.
 

Dippy

Moderator
Do they really have those bits missing at the top, or is that just your drawing?

What's the sensor? Optical, magnetic ??
Why do you need sine wave? Is the output anything other than proper (or rounded-off) square wave?
I have never fiddled with this sort of stuff (and never will) so it's a genuine question.

Anyway, bottom line, you'll need a function generator for anything other than square wave with a PICAXE for your suggested RPMs.

PS. If you have to make additional notes it's easier just to add to the thread rather than going back and editing - otherwise all the thousands of people looking at this thrad will have to keep scrolling back and forth. They will get dizzy and fed up :)
 

BCJKiwi

Senior Member
@Dippy,
Those new diagrams are the standard text book pics of the disk on the cam/crankshaft. The missing tooth/teeth indicate TDC or some known offset from it, and the others give the speed/timing/position information.

@Mad Prof
Assuming the sensors are hall effect types (what else would they use?), the raw waveform arriving down the wire from the sensor to the ECU would be a close approximation to a square wave. If it's anything else by the time the ECU gets to work with it, it most likely has undergone some shaping along the way - there is a possibility that the sensor has some on board signal shaping but its hard to visualise why.

Access to the proper technical info from the manufacturers and/or at least a scope on the sensor output would, I'd have thought, be essential before undertaking mods of this type.
 

Dippy

Moderator
Good advice BCJ.
So the raw sensor signal is a slightly rounded-off square wave then. So a lightly R-C'd PWM, for example, could emulate that?

Have you 'scoped these signals Mad Prof?
 

Tom2000

Senior Member
The problem with PWM, Dippy, is that you couldn't insert the missing (sync) pulse. Well, you could, using external hardware, but if you went that route, it would probably be best to implement the whole magilla in hardware. That might not be a bad approach, anyway. A 555 timebase would give you infinite resolution.

Maybe a hybrid approach, with an analog timebase and a micro doing the pulse swallowing and frequency counting...

I'm taking myself well off topic. This isn't what I wanted to discuss.

For a 36 tooth wheel at 5000 RPM, you're talking something like 3000 pulses per second. For a 60 tooth wheel, 5000 pps. I think both are well outside the capabilities of a Picaxe to handle, even as a pulse swallower, much less a signal generator.

I think the op needs to find a different solution to this particular problem.

One man's opinion...

Tom
 

Tom2000

Senior Member
Thinking about this a little more, I think that I might be wrong. Pulsin is probably fast enough for 5000 pps, and there wouldn't be much computation involved in implementing pulse swallowing. A quick breadboard test with simple software would provide the answer quickly, and with not much effort.

So here's what I propose:

A 555 timebase, configured to generate pulses between 300 and 5000 pps, with some sort of independent calibration.

Edited: I forgot about camshaft timing, at 1/2 the crankshaft speed. So your timebase would be built for 150-5000 pps.

The 555 drives a Picaxe running at an 8 MHz clock speed. (Or, if you're using a 28X1 or 40X1, a 20 MHz clock.)

Using the simplest, tightest pulsin code possible, have the Picaxe either repeat the 555's pulses to an output line, or swallow the appropriate pulse(s).

If the ECU can't directly handle the Picaxe's pulse output, provide external signal conditioning circuitry.

A quick breadboard test using an external 5000 pps source and a scope on the Picaxe's output pin, as the Picaxe swallows every 36th pulse, will let you know, right away, whether this is a viable approach. You can investigate the possibility without much investment in time or without having to construct any custom hardware.

Good luck!

Tom


Edited to add:

I'm guessing that the ECU isn't fussy about a symmetrical square wave. It's probably just timing from one of the pulse edges. It probably doesn't care whether it's receiving a symmetrical square wave or if it's just receiving a pulse.

So, to make your life easier, try writing your code using a pulsout command to send pulses to the ECU, rather than trying to repeat the 555's waveform with 100% fidelity.

Tom
 
Last edited:

Dippy

Moderator
Tom, good point re: missing synch pulse.

Though I think he wants the PICAXE to emulate a sensor outputnrather than use the PICAXE to detect (??????).

I've never done this sort of thing so I don't know whether ECU is looking at times-between-edge or pulse length or ...?

I was really wondering why non-squarish pulses were required. e.g. sines, triangles etc. Hence sggestion/question about 'scoping sensor o/p.

I'll leave you to it, it's beyond my little brain.
 

Tom2000

Senior Member
Yeah, same here. I don't have any intention of dragging my scope out to my car and digging into the ECU.

But, as I understand the problem, Mad Professor wants to "dummy in" the signal produced by the crankshaft position sensor. That's what I was shooting for.

I, also, don't understand the need for the other waveforms. But then again, I don't know much about ECUs, other than a general idea of what they do, and what to do if one fails. (Have your car towed in to the shop for an ECU replacement :) ) I was just doing an Occam's Razor analysis of the problem.

Tom
 
Last edited:
Top