|
Spockie-Tech
Site Admin
Joined: 31 May 2004
Posts: 3160
Location: Melbourne, Australia
|
On PWM driving a fuel injector with a picaxe...
I just made a prototype PicAxe based PWM Injector driver for Gary to test with Pyrobot, and ran into a small snag during the coding.
The PicAxes hardware based PWM function is not easily useable because its *lowest* operating frequency is too fast for a fuel injector. It wont go much lower than about a 3Khz cycle frequency, where the fuel injector wants to work down in the low hundreds of Hz.
It might be possible to have the hardware timer trigger an interrupt routine, which runs a counter and effectively divides the too-fast frequency down to something useable by an injector.
Given that this was a simple unit that didnt have any other functions to handle in its main loop though, i just did it with manual turn-output-on, time delay, turn-output-off loops.
This worked reasonably, but did exhibit a few small undesireable artifacts ...
while the software was running in its PWM-time-delay-loop, it isn't watching the RC inputs, so the next time it came to read the RC control input, the time taken to decode the RC pulse was fairly variable (depending whether an RC pulse was just starting or finishing while the micro was in the delay loop).
Since this time was variable, the software-controlled OFF time of the PWM was also variable, which showed up as some jittering in the PWM output at some combinations of "RPM"/Mark-Space Ratio.
So, while the PicAxe Can do it, if precise smooth control of the injector is important, then both the PWM delays and the RC servo reading need to be done in the background by interrupts or by using hardware with a PWM output that can run slower.
Possibly the Arduino PWM function will have a broader range at low frequency, I'll look into that soon. _________________ Great minds discuss ideas. Average minds discuss events. Small minds discuss people
|
Sun Dec 06, 2009 11:29 am |
|
|
|
|
|
Spockie-Tech
Site Admin
Joined: 31 May 2004
Posts: 3160
Location: Melbourne, Australia
|
Interesting idea, but the 18pin PicAxe runs on its internal clock at only 4 or 8 mhz IIRC. Also, if you change the oscillator speed, the pulsein command (used for decoding the RC Servo Inputs) doesnt work, since the time measurement is tied to the clock.
I've been doing a lot more work with the AVR based Arduino's recently, but havent had to use its PWM capabilties yet, however, even if its hardware PWM doesnt go slow enough, it has useful nice millis() and micros() background timer functions that would allow accurate software-controlled timer loops..
so if a version 2 is required, I'll probably use Arduino rather than a PicAxe next time. PicAxes are a bit easier to program being in Basic, but I've been polishing up my C skills recently and I've reached a reasonably competent level there again.
thanks for the thought though. _________________ Great minds discuss ideas. Average minds discuss events. Small minds discuss people
|
Tue Dec 15, 2009 9:27 am |
|
|
|
|
Spockie-Tech
Site Admin
Joined: 31 May 2004
Posts: 3160
Location: Melbourne, Australia
|
That would be nice, since I'm moderately comfortable with Python now but since Python is a fairly high level language with dynamic typing and other conventions that don't seem to fit well into Micro-Land, I havent seen a *functional* version of it for a small micro yet.
There was someone who had a go at it, but the limitations of a low power Micro forced him to only be able to implement such a limited-subset of Python's features that it didnt seem worth it to me.
Besides, I have found that Arduino's C-Like code (Wiring) is actually not that different from Python in many ways, and is much more pleasant to learn and work with than raw C was when I had a few stabs at it in the past.
My first major Arduino coding project was the Rent-a-Bot Controller I did for Sidetracked recently, and it came together surprisingly easily. I wrote I2C communications, 20x2 LCD control, background state machines, multiple parallel timers and all sorts of fairly deep coding on my first go with practically no bugs.
Pretty good for a first go I thought, so I'm now working on my prototype "Karr-Kontrol"(tm) modules in it. Its definitely worth a look if you are finding Basic is limiting you doing any clever stuff which it can on occasion.
I was going to post a block of example code here from the project to query the status and parameters and decode from The Megajolt ignition controller, but the forum munged the formatting, so I wont bother making it look nice, unless anyone particularly wants to see it. _________________ Great minds discuss ideas. Average minds discuss events. Small minds discuss people
|
Tue Dec 15, 2009 12:39 pm |
|
|
|
|
|
|
|
|
|
|