Mazda idle valve (code hacking question)

This is a forum for discussing the development and testing of alpha MS2/Extra code. Documentation
(Runs on MS2 and Microsquirt)

Moderators: jsmcortina, muythaibxr

matt_fulghum
Experienced MS/Extra'er
Posts: 167
Joined: Mon Sep 19, 2005 3:39 pm
Contact:

Mazda idle valve (code hacking question)

Post by matt_fulghum »

When I moved from the regular MS2 code over to MS2/Extra, the car ran better than ever, but I heard a terrible racket coming from the engine bay, and found that my idle valve was freaking out even at 158 Hz. Clearly this wasn't a high enough switching frequency to keep the idle valve at a constant position (it was shaking all over the place and clanking and eeeech :P)

Anyway, what I did was build a small circuit with an Atmel Atmega8 microprocessor that samples the output from the MS at around 158 kHz, and extracts the duty cycle from that, and then drives the idle valve at about 2 kHz, which is almost perfect (I'm going to go faster once I work out how to filter the voltage spiking that I'm getting from the valve).

What I was wondering was if it would be possible to lower the PWM frequency even lower in the code, like to 30 Hz, to get half step accuracy. Since my processor just hangs out on its own, updating the idle valve setting whenever it finishes counting a full PWM period, it's worth slowing down the output from the MS to get a higher accuracy on the MS end of it.

Does anything else run on the idle valve timer, or would it be possible to halve the speed on it again to get a bit better accuracy?
rb26dett
Master MS/Extra'er
Posts: 497
Joined: Tue May 24, 2005 11:34 pm
Location: Auckland New Zealand

Post by rb26dett »

smart thinking!! can you post your links/pics/schematics etc for this? seems like you are not along, i've read many posts not happy about that. lower configurable frequency and higher accuracy would be super useful for those that have a valve thats just too big on their small engines :-)
ms2,v3,cop,innovate,mazda fe3/fe-dohc 2l 4cyl with stock 10:1 pistons,4 stock coils,4 stock ignitors,rx7 550cc injectors maxed@6600rpm&17psi,custom everything,holset he351cw turbo,44mm ext gate,nis gtr bovs,nis gtr intercooler,70mm lexus throttle,chinese fpr,10may v2 ms2e alpha code
muythaibxr
Site Admin
Posts: 8230
Joined: Thu Oct 14, 2004 12:48 pm

Post by muythaibxr »

I plan on taking whatever they did in the standard code to allow higher frequencies as well, but I doubt it'll go as high as your setup.

It should be a big deal to drop the frequency a bit either... I'll take a look at doing that.. Not sure it'll get into 2.0 but it will probably get into a 2.0.x patch afterwards.

Ken
rb26dett
Master MS/Extra'er
Posts: 497
Joined: Tue May 24, 2005 11:34 pm
Location: Auckland New Zealand

Post by rb26dett »

ken, i thought with a rise in frequency the accuracy went down, or did b&g find a clever fix to work around that? it seems like this bloke is onto something good. let the information on duty come out of the ms box, and the actual drive come from a seperate simple box elsewhere. ideally we could have high frequency AND accuracy, but if the code/hardware cant do it for some reason, this seems like a good compromise for those that need it.

fred.
ms2,v3,cop,innovate,mazda fe3/fe-dohc 2l 4cyl with stock 10:1 pistons,4 stock coils,4 stock ignitors,rx7 550cc injectors maxed@6600rpm&17psi,custom everything,holset he351cw turbo,44mm ext gate,nis gtr bovs,nis gtr intercooler,70mm lexus throttle,chinese fpr,10may v2 ms2e alpha code
muythaibxr
Site Admin
Posts: 8230
Joined: Thu Oct 14, 2004 12:48 pm

Post by muythaibxr »

rb26dett wrote:ken, i thought with a rise in frequency the accuracy went down, or did b&g find a clever fix to work around that? it seems like this bloke is onto something good. let the information on duty come out of the ms box, and the actual drive come from a seperate simple box elsewhere. ideally we could have high frequency AND accuracy, but if the code/hardware cant do it for some reason, this seems like a good compromise for those that need it.

fred.
Yes, the accuracy goes down as the frequency goes up... However, I've used the PWM closed-loop algorithm for idle speed control, and it still seems able to adjust well enough.

Ken
racingmini_mtl
Super MS/Extra'er
Posts: 9130
Joined: Sun May 02, 2004 6:51 am
Location: Quebec, Canada
Contact:

Post by racingmini_mtl »

That's probably a crazy idea but there is an unused hardware PWM on the CPU that goes to the pin used for the bootloader jumper. Since the bootloader jumper is no longer used with the extra code, could this be used for this purpose (or any other needed fast PWM)?

The nice thing is that there is already a pin header so connection to this pin would be easy. I haven't looked at that part of the code so I don't know what that would involve to make sure there is no reboot problem but the PWM handling would be very much simplified and the speed could be very high and the duty cycle very precise.

Jean
jbperf.com Main site . . . . . . . . . . . . . . . . . . . . . . jbperf.com Forum
Image
turboy
MS/Extra Newbie
Posts: 17
Joined: Thu Mar 29, 2007 9:16 am

Mazda idle valve (code hacking question)

Post by turboy »

Couple of years ago I changed the pwm idle code to increase resolution. Only way to do it was by using a timer. Since I don't need any injector pwm I figured why not use that one. I now have superfine resolution and high frequency. I don't know how the timers are used in the extra code but maybe it's possible to do the same......

Simon

That's probably a crazy idea but there is an unused hardware PWM on the CPU that goes to the pin used for the bootloader jumper. Since the bootloader jumper is no longer used with the extra code, could this be used for this purpose (or any other needed fast PWM)?

The nice thing is that there is already a pin header so connection to this pin would be easy. I haven't looked at that part of the code so I don't know what that would involve to make sure there is no reboot problem but the PWM handling would be very much simplified and the speed could be very high and the duty cycle very precise.

Jean



P&H Board - Signal Interceptor Board (breakout board) - JimStim - Dual VR Board
http://www.jbperf.com/






__________ NOD32 2453 (20070812) Informatie __________

Dit bericht is gecontroleerd door het NOD32 Antivirus Systeem.
http://www.nod32.nl
muythaibxr
Site Admin
Posts: 8230
Joined: Thu Oct 14, 2004 12:48 pm

Post by muythaibxr »

racingmini_mtl wrote:That's probably a crazy idea but there is an unused hardware PWM on the CPU that goes to the pin used for the bootloader jumper. Since the bootloader jumper is no longer used with the extra code, could this be used for this purpose (or any other needed fast PWM)?

The nice thing is that there is already a pin header so connection to this pin would be easy. I haven't looked at that part of the code so I don't know what that would involve to make sure there is no reboot problem but the PWM handling would be very much simplified and the speed could be very high and the duty cycle very precise.

Jean
We could potentially do this. We should talk that over with James and see if he can come up with any show-stopping problems with that idea. I can't come up with any.

Ken
rb26dett
Master MS/Extra'er
Posts: 497
Joined: Tue May 24, 2005 11:34 pm
Location: Auckland New Zealand

Post by rb26dett »

awesome news :-)
ms2,v3,cop,innovate,mazda fe3/fe-dohc 2l 4cyl with stock 10:1 pistons,4 stock coils,4 stock ignitors,rx7 550cc injectors maxed@6600rpm&17psi,custom everything,holset he351cw turbo,44mm ext gate,nis gtr bovs,nis gtr intercooler,70mm lexus throttle,chinese fpr,10may v2 ms2e alpha code
jsmcortina
Site Admin
Posts: 39614
Joined: Mon May 03, 2004 1:34 am
Location: Birmingham, UK
Contact:

Post by jsmcortina »

Using the bootload pin as a PWM output would work until you rebooted the chip, then it is likely that the circuit could pull it low enough to enter monitor mode.

Two options - make sure the output circuit doesn't do that. Might not be too hard - use a diode into the CPU and a pullup resistor "outside" it. The pullup is used to drive the power darlington (TIP122 etc.)

The other more complicated option is to rewrite the monitor not to use this pin and to use the mainboard H1 pins instead like MS1. The change to the monitor code itself would be fairly easy, but getting it onto your CPU without a BDM module might be.
It _may_ be possible to write some code that will re-programme the monitor from within RAM, but until I check the datasheet and/or try it, I can't remember if the chip lets you do a full-erase in circuit.
Re-doing the monitor like this would be a great way to screw your MS2 as well. While it is easy to fix by BDM, I'm sure we'd have lots of users with temporarily dead MS2s.

Either way, it would be great if we've "found" another pin on the MS2.

James
I can repair or upgrade Megasquirts in UK. http://www.jamesmurrayengineering.co.uk

My Success story: http://www.msextra.com/forums/viewtopic ... 04&t=34277
MSEXTRA documentation at: http://www.msextra.com/doc/index.html
New users, please read the "Forum Help Page".
jsmcortina
Site Admin
Posts: 39614
Joined: Mon May 03, 2004 1:34 am
Location: Birmingham, UK
Contact:

Post by jsmcortina »

Here's a schematic of what I was thinking of.

James
I can repair or upgrade Megasquirts in UK. http://www.jamesmurrayengineering.co.uk

My Success story: http://www.msextra.com/forums/viewtopic ... 04&t=34277
MSEXTRA documentation at: http://www.msextra.com/doc/index.html
New users, please read the "Forum Help Page".
muythaibxr
Site Admin
Posts: 8230
Joined: Thu Oct 14, 2004 12:48 pm

Post by muythaibxr »

If someone wants to try building that circuit and wiring it all up, I'd be happy to do a quick test code (bit-banging like now at first, just to see if it works alright) for it.

Ken
racingmini_mtl
Super MS/Extra'er
Posts: 9130
Joined: Sun May 02, 2004 6:51 am
Location: Quebec, Canada
Contact:

Post by racingmini_mtl »

jsmcortina wrote:Using the bootload pin as a PWM output would work until you rebooted the chip, then it is likely that the circuit could pull it low enough to enter monitor mode.
After my post, I looked at it again and came to the same conclusion. And I checked the monitor code after to see if the pin was using the internal pullup. If it didn't, it wouldn't be a problem but it does.

However, the circuit you propose should work nicely and it only requires a couple of additional diodes compare to what a "normal" pin would require. I think that's not a bad compromise to gain an additional pin that can have a hardware PWM on it.

I'll see if I can breadboard a quick test circuit to validate that it works.

Cheers,
Jean
jbperf.com Main site . . . . . . . . . . . . . . . . . . . . . . jbperf.com Forum
Image
matt_fulghum
Experienced MS/Extra'er
Posts: 167
Joined: Mon Sep 19, 2005 3:39 pm
Contact:

Post by matt_fulghum »

actually, I've completely redone the circuit :)

the valve is ACTUALLY a solenoid which rotates the little vane inside the idle speed controller, so ideally, it's best to have a constant voltage source going to the valve.

So I made one.

What I'm using now is an 8 bit R-2R ladder out of my processor which goes into op amp A from an LM412, with a 2.4x gain. This takes the signal from 5V max to 12V max at the output. Then I stick that output into op amp B on the chip. The output from op amp B goes into a TIP120, and that sources current to the idle valve. For feedback, I use the drain from the transistor going through a 1k resistor into op amp B. This gives a good, strong, variable output, with no current to speak of required from the microprocessor, which avoids the problem of needing enough current to drive the transistor.

At low PWM time from the microprocessor, there wasn't quite enough juice to crank over the transistor until about 60% duty cycle, but with the new setup, it's pretty much perfectly linear from about 10 to 250 or so on the R-2R ladder outputs.

8 bit resolution on the R-2R ladder should do it I think. That gives up to 256 bits of resolution (while the MS only works at 1% increments anyway).

What I have YET to test, however, is how the op amps will respond to the voltage spiking and stuff on the car's 12V rail. What I'll likely do is build a DC-DC regulator that will always put a constant 15V on the positive side of the op amp. That'll make sure that it's linear, too.

I'll draw up some schematics in a minute. I just got home.

EDIT:
Oh, and one reason why I'm using a co-processor is because I'm designing my own version of the megasquirt board, and I want everything to be absolutely perfect for when I finally get around to it. The MS-II main processor just doesn't have enough extra I/O for everything that I plan to do with it, so I'm practicing communicating with the main chip.

Does anyone know if the MS-II chip supports the Two-Wire Interface (aka I2C)?

My plan for the board I'm designing is to use an Atmel AT90CAN128 as a co-processor, talking through the CAN bus, and then any extra stuff I need to add on top of that if that by itself still isn't enough, I can talk to using the TWI, which is fast enough to handle ~4800 baud or so, plenty for basic peripherals.

DOUBLE EDIT:
On the other hand, so long as you run the PWM output fast enough, and you sufficiently filter it, you don't NEED an R-2R ladder. So it WOULD be possible to do this cleanly on the MS. I'll test both tomorrow and see which setup works better.
matt_fulghum
Experienced MS/Extra'er
Posts: 167
Joined: Mon Sep 19, 2005 3:39 pm
Contact:

Post by matt_fulghum »

alright, I've got my schematic all done up... lemme know what you all think...

Image

INT0 is the external interrupt that figures out the duty cycle from the megasquirt, OC1A is the 16-bit PWM output.

This goes into an active low pass in the first half of the LF412, to get rid of the junk from the PWM switching and cleans it up for the actual motor driver stage. This low pass filter also has a gain of about 2.47, which should take 5V from the regulated 5V rail and jack it up to ~12.5V when the engine's running (I'll try driving the op amp off of the car's 12V rail. It'll probably need a filter cap of some sort though.

This then goes into the motor driver circuit itself, which I've tested pretty thoroughly by now, and it works great.

One thing I forgot to add to this schematic is a trimpot to put an offset voltage onto the op-amp. The motor driver needs about 1V on it from the input, or else it goes wacky. Hooray analog circuit design :P

EDIT: btw, that's a tilde at the gain of ~2.47, but when I scaled the image down it didn't do nice things to the text :P
racingmini_mtl
Super MS/Extra'er
Posts: 9130
Joined: Sun May 02, 2004 6:51 am
Location: Quebec, Canada
Contact:

Post by racingmini_mtl »

Well, James' circuit works as intended. I had a LED driven by the NPN transistor for testing purposes and with a small modification to the code I had the LED blinking together with the injector 1 LED on the JimStim (I used one of the other available LEDs on the JimStim).

But there is a problem that will make the option of using this pin a no go. The monitor doesn't like this. If the pin is configured as an output, the monitor takes that as if the bootloader jumper is on and that means it wants to go in debug mode when you use the serial port. So with my modified program everything seems to be going well with the LED flashing as intended until I want to go in Megatune. Then the serial port is used and the MS2 goes into debug mode which effectively freezes the MS2.

Since this would involve modifying the monitor code, this is not a good idea for the reasons James mentioned above.

Cheers,
Jean
jbperf.com Main site . . . . . . . . . . . . . . . . . . . . . . jbperf.com Forum
Image
rb26dett
Master MS/Extra'er
Posts: 497
Joined: Tue May 24, 2005 11:34 pm
Location: Auckland New Zealand

Post by rb26dett »

sure you had the diodes installed as james does in his pic? that would prevent it being pulled high in the eyes of the cpu. just a thought. if you did? then i'm all out of naive ideas :-)
ms2,v3,cop,innovate,mazda fe3/fe-dohc 2l 4cyl with stock 10:1 pistons,4 stock coils,4 stock ignitors,rx7 550cc injectors maxed@6600rpm&17psi,custom everything,holset he351cw turbo,44mm ext gate,nis gtr bovs,nis gtr intercooler,70mm lexus throttle,chinese fpr,10may v2 ms2e alpha code
racingmini_mtl
Super MS/Extra'er
Posts: 9130
Joined: Sun May 02, 2004 6:51 am
Location: Quebec, Canada
Contact:

Post by racingmini_mtl »

rb26dett wrote:sure you had the diodes installed as james does in his pic? that would prevent it being pulled high in the eyes of the cpu. just a thought. if you did? then i'm all out of naive ideas :-)
Yes, I'm sure but that's a good idea.

The circuit works and I could reboot the MS and it would still work, it wasn't going in bootloader mode when starting as intended. The only problem is when using the serial port. I looked at the monitor code and the monitor actually intercepts the interrupt and looks at the pin value. If the value is zero (such as when the jumper is in place) then it goes in debug mode, if not, the interrupt is passed to the main program. The problem is that the monitor doesn't look at the pin direction to see if the pin is an output so if the pin is set to 0 then it goes into debug mode. The problem is not the circuit it's the monitor which has a debug function that is not needed in our case.

If you want to see the same behaviour, power on your MS, put the bootloader pin and then connect to the MS either with Megatune or hyperterminal. As soon as one character is sent you'll see the MS freeze. To undo this, just power down the MS, remove the jumper, and power on the MS and you're back to the normal behaviour.

Cheers,
Jean
jbperf.com Main site . . . . . . . . . . . . . . . . . . . . . . jbperf.com Forum
Image
rb26dett
Master MS/Extra'er
Posts: 497
Joined: Tue May 24, 2005 11:34 pm
Location: Auckland New Zealand

Post by rb26dett »

good explanation... thats a shame :-( though, i guess you could put up with no idle control while the tuning software was connected it could work? or am i confused?
ms2,v3,cop,innovate,mazda fe3/fe-dohc 2l 4cyl with stock 10:1 pistons,4 stock coils,4 stock ignitors,rx7 550cc injectors maxed@6600rpm&17psi,custom everything,holset he351cw turbo,44mm ext gate,nis gtr bovs,nis gtr intercooler,70mm lexus throttle,chinese fpr,10may v2 ms2e alpha code
racingmini_mtl
Super MS/Extra'er
Posts: 9130
Joined: Sun May 02, 2004 6:51 am
Location: Quebec, Canada
Contact:

Post by racingmini_mtl »

Possibly but you'd need a way to tell the firmware you want to disable the pin before connecting through the serial port. So you'd need an input. So to gain this output, you would need to waste an input and there's already not a lot of them. Also, when you activate this input, you'd have to disable the idle valve because the circuit above defaults to activating the valve.

Also, that would mean that you would never be able to tune the idle region "live" or with the help of a log because the idle valve cannot coexist with any serial communication. So I don't think that this is a realistic setup.

As I'm writing this, I realize that there would be a workaround but that would also mean some work on the firmware side and some additional hardware. If the CAN bus is used for tuning and logging then the problem would be avoided. A small board with another CPU, a serial port and a CAN bus could be used. Or the upcoming CAN-enabled boards would also work. But the problem is that the MS2/extra is not CAN-ready just yet.

Jean
jbperf.com Main site . . . . . . . . . . . . . . . . . . . . . . jbperf.com Forum
Image
Post Reply