www.robowars.org

RoboWars Australia Forum Index -> Technical Chat

MicroControllers and Programming
Goto page 1, 2  Next

Post new topic   Reply to topic
  Author    Thread
Spockie-Tech
Site Admin


Joined: 31 May 2004
Posts: 3160
Location: Melbourne, Australia


 Reply with quote  

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

Post Sun Dec 06, 2009 11:29 am 
 View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
Valen
Experienced Roboteer


Joined: 07 Jul 2004
Posts: 4436
Location: Sydney


 Reply with quote  

sounds like you have a mixup in the mental processing.

you want a high speed PWM and then to vary the duty cycle of that PWM.

The PWM is there to drop the average coil current, not to turn the thing on and off.

so the normal cycle would be something like .something of a ms at 100% duty, then drop to 30% duty for the next x ms then turn off completely.
_________________
Mechanical engineers build weapons, civil engineers build targets

Post Sun Dec 06, 2009 12:13 pm 
 View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger ICQ Number
Spockie-Tech
Site Admin


Joined: 31 May 2004
Posts: 3160
Location: Melbourne, Australia


 Reply with quote  

I understand thats what PWM is *normally* used for.

But if you want precise repeatable on/off ratio control without using interrupts, then using a hardware PWM timer with programmable mark/space ratios will do that, IF the rate can be run slow enough.

So I know thats not what PWM timers are supposed to do, which is why the picaxe's doesnt go that slow. But off the cuff, couldnt think of a way to do precise on/off timing control without resorting to interrupt driven code.
_________________
Great minds discuss ideas. Average minds discuss events. Small minds discuss people

Post Sun Dec 06, 2009 12:22 pm 
 View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
Jtepper



Joined: 04 May 2009
Posts: 44


 Reply with quote  

why dont you just slow down the frequency of the whole chip in your code, o presume your using a chip without a resonator? then just put the appropriate code at the top of the program, i think it might be setfreq? then you can get the pwm as slow as you like.

Post Tue Dec 15, 2009 12:22 am 
 View user's profile Send private message
Spockie-Tech
Site Admin


Joined: 31 May 2004
Posts: 3160
Location: Melbourne, Australia


 Reply with quote  

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. Smile

thanks for the thought though.
_________________
Great minds discuss ideas. Average minds discuss events. Small minds discuss people

Post Tue Dec 15, 2009 9:27 am 
 View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
Knightrous
Site Admin


Joined: 15 Jun 2004
Posts: 8511
Location: NSW


 Reply with quote  

I avoid learning C by using BascomAVR to program my AVR's in Basic Smile
_________________
https://www.halfdonethings.com/

Post Tue Dec 15, 2009 11:01 am 
 View user's profile Send private message
Valen
Experienced Roboteer


Joined: 07 Jul 2004
Posts: 4436
Location: Sydney


 Reply with quote  

use bigger AVR's
run python?
_________________
Mechanical engineers build weapons, civil engineers build targets

Post Tue Dec 15, 2009 12:17 pm 
 View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger ICQ Number
Spockie-Tech
Site Admin


Joined: 31 May 2004
Posts: 3160
Location: Melbourne, Australia


 Reply with quote  

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) Wink 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

Post Tue Dec 15, 2009 12:39 pm 
 View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
Nick
Experienced Roboteer


Joined: 16 Jun 2004
Posts: 11802
Location: Sydney, NSW


 Reply with quote  

This thread need some loving!

Question: If I have an MCU board with three serial ports that can be configured as SPI, I2C or RS-232 (but not at the same time!), is there an interface chip that can expand the RS-232 ports to around 8? I know there are chips that will expand A/D or TTL ports, but I can't find anything to do the same for serial.

EDIT: I need more serial ports to drive the new antweight arena electronics: I am short of two serial ports already and most of the interesting parts I want to use are SPI or RS-232.

Post Fri Apr 01, 2011 6:53 pm 
 View user's profile Send private message
seanet1310



Joined: 08 Nov 2006
Posts: 1265
Location: Adelaide


 Reply with quote  

I do not know of any chips that act as a rs232 expander but i have never looked.

You could always do software RS-232 if you have enough free cycls and a timer. You will need a decent clockspeed. just a random link I have not checked it out as an expander
http://supp.iar.com/Support/?note=88469

Other links i found that may be of use
http://www.siliconbluetech.com/media/intellectual-property/1-to-4UART_Expansion.pdf

I am sure someone else will be of more help

RE SPI. if you are good enough and the all your spi allow it you can have multiple spi slaves connected to a single spi master(your MCU) via the daisy chain. This is not always possible. Some SPI interfaces have independent SPI's with a bunch of SSx lines one to each SPI device but i am sure you would have noticed if this was the case with yours.
If you are not interested in SPI recieving and only sending to SPI devices you can with little effort and code bitbash the output, you do not even need a timer just three I/O's. I have done this on more then one occasion.

If you have spare external interrupt pins you can also bash the receive if needed but you will need a clock output so i would use a timer in that case however you may not need one.
Thinking about it you probably do not need an interrupt and it may be best not to have one. I have never tried this and do not remember seeing anything about others doing it this way.


Again never checked this. http://www.siliconbluetech.com/media/intellectual-property/SPI_Slave.pdf

Here is also a uart to spi. I know you are short on UART but this looks like 7 ss lines for your spi.
_________________
Remember to trust me, I am an Engineer.

http://www.youtube.com/watch?v=rp8hvyjZWHs

Post Fri Apr 01, 2011 7:25 pm 
 View user's profile Send private message Send e-mail Yahoo Messenger MSN Messenger
Valen
Experienced Roboteer


Joined: 07 Jul 2004
Posts: 4436
Location: Sydney


 Reply with quote  

take a look at a multiplexer IC, they are designed for this kind of thing, cmos might handle the voltages.
(you may also want a demultiplexer if other stuff needs to answer back)

You sure the stuff your talking to is actually RS232 and not TTL level serial?
_________________
Mechanical engineers build weapons, civil engineers build targets

Post Fri Apr 01, 2011 11:02 pm 
 View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger ICQ Number
marto
Experienced Roboteer


Joined: 08 Jul 2004
Posts: 5459
Location: Brisbane, QLD


 Reply with quote  

Need a bit more info on exactly what you are trying to interface to. SPI and I2C buses are meant for multiple devices but it depends on what you have. Also do you need serial coms back and forth between everything.

Steve
_________________
Steven Martin
Twisted Constructions
http://www.botbitz.com

Post Fri Apr 01, 2011 11:51 pm 
 View user's profile Send private message Send e-mail MSN Messenger
Nick
Experienced Roboteer


Joined: 16 Jun 2004
Posts: 11802
Location: Sydney, NSW


 Reply with quote  

As people have probably guessed, I am looking at adding functions to the arena timer project. The dev board had just enough ports for the basic functions, but now I want to add control of several servos and that looks like a job for a serial server board.

The receiving end is always TTL level serial IE the Sparkfun serial LED displays. I don't recall anything sending back or even having handshaking. The MBED dev board I am using doesn't bring out every possible MCU pin, it allows you to have either SPI, I2C or serial on common groups of pins, here is a diagram of what I can get:



Several ideas have popped up:

* Hack the serial library to come out on a pair of general purpose TTL pins (any of the blue ones)

* Find an I2C chip to front-end the receiving devices and just use one I2C bus for everything. Its more work, but it could prove a long term winner. Sparkfun has this board that opens up many possibilities: http://www.sparkfun.com/products/9981 . I could use the spare i/o pins to read buttons and control LEDs as well - this looks like the best solution so far Smile

* use SPI to another dev board; seems like a waste of hardware, but it could involve the least coding.

Post Sat Apr 02, 2011 8:51 am 
 View user's profile Send private message
Valen
Experienced Roboteer


Joined: 07 Jul 2004
Posts: 4436
Location: Sydney


 Reply with quote  

can you not just drive the servos from i/o pins?

otherwise to drive your displays a demultiplexer IC will probably do what you want.
_________________
Mechanical engineers build weapons, civil engineers build targets

Post Sat Apr 02, 2011 9:54 am 
 View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger ICQ Number
Nick
Experienced Roboteer


Joined: 16 Jun 2004
Posts: 11802
Location: Sydney, NSW


 Reply with quote  

Yeah, there is a servo library for that so its dead easy. On the other hand, using a serial servo controller is only $15, just as easy and less wiring - I really like to keep the longer distance wiring as simple as possible and the more I think about it, I2C for everything is ideal - two data lines and power down a cheap & light cable going point to point. I haven't used i2C before but it looks simpler than SPI and interesting to learn.

EDIT: Also, a separate servo board allows 8 servos with no extra processing load

Post Sat Apr 02, 2011 10:29 am 
 View user's profile Send private message
  Display posts from previous:      

Forum Jump:
Jump to:  

Post new topic   Reply to topic
Page 1 of 2

Goto page 1, 2  Next

Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Last Thread | Next Thread  >
Powered by phpBB: © 2001 phpBB Group
millenniumFalcon Template By Vereor.