PWM pins

Can the PWM pins and/or function on a Duemilanove be used to generate a one shot?

Art

I was hoping for a function similar to Intel's 8253/54 or Motorola's 6840 PIT. I was hoping to be able to get my hands on them but Mouser nor Digikey carry them. I remember building one from 74191s or 193s a lifetime ago. I am pouring over my Signetics book to see if I remember how I did it. I need this to be stand-alone so the MPU can do other things. There is going to be 4 or 6 of these running and software wise there is too much of a chance they could run into each other.

Could you tell us a little bit about the puls width (ns? us? ms? s?) and the required accuracy? That makes all the difference :slight_smile:

A good hardware solution is always a cap buffered by a Schmitt trigger ...

For a one off fixed width pulse you can always use a monostable. There are two in TTL logic 74LS121, and the dual 74LS123.

What I want to do is to control 4 large DC motors. These motors have a locked rotor rating of 100+A each. This whole project is going to be powered by two rather large 12V very deep cycle batteries. Sears has a new battery that I recently found out about. It uses a very dense lead plate system that is very heavy, I need that, and the most power per lb. The motors will be run on a standard 20KHz frequency. Each motor will fire sequentially within that time period. In other words the second motor will fire 0.0125ms after the first motor. The third motor fires 0.025ms after the first motor. The forth motor fires .0325ms after the first motor. At .05ms the whole things starts over. As the pulse width starts to widen the current should start to drop drastically so the battery should not see a current draw of more than 100A. As the pulse width widens to its full period all the pulses will cross over each other. Also if a motor stars to free wheel its pulse width will need to be narrowed until it gets it's footing back. If I were to allow PWMs to run all Nellie Wily there could be a chance that all PWMs fire at the same demanding 400A from the battery. The batteries, rightly, will say screw you and go away. Technically the batteries internal resistance will degrade performance drastically, seriously heating up the battery. And the last thing you want is to have a lead acid boil. Two cascaded 74HC193s w/ a nand or nor gate feed back to shut it off will do the job. I'm still a bit of a hardware guy and I realize that the Arduino's boards are fast; I am having difficulties wrapping my head around all the software issues. One thing I started to think about is to use one of Arduino's teeny winy boards to control each motor. The baby Arduino would control all the speed issues with the motor and the Duemilanove, or another baby Arduino, will just orchestrate.

How much are the batteries and motors? Cheap? I doubt it. Yet, you are looking for a $20 controller. I don't get it.

Batteries $250 ea
Motors (dependind on tourqu) $100-$400 ea
H bridge $180 ea but I plan to roll my own

I don't conceder the Duemilanove a toy. In the right environment it's a serious tool. Besides this is for a hobby. Take a look at http://adirondacklivesteamers.org/index.html click on event photos. :slight_smile:

All right, let me summarize:
There have to be four pulses equally distributed in a cycle of 50us.
The pulse width should be less 12.5 us. It can be shorter, though it is not made clear how this is to become controlled.

The structure of the problem is the same as PPM in RC servos; there is a library for this, however in servos we are talking about 100Hz, not 20kHz.

So your problem is 200 times more demanding, and the library is out :cry:

To start the pulses, interrupts can be used (Timer1). However you might encounter a race condition, as Arduino manipulation of I/O is slow.

It is possible to do it on the processor, but you most likely have to retreat to basic I/O operations, programming the AVR registers directly....

H bridge $180 ea but I plan to roll my own

Is this something you are capable of?

Four motors will run you a minimum of $400. Add a single battery and the components to build your own H-bridges, and you are looking at close to $1000.

What are these motors going to be doing?

Is a $20 Arduino really in the right league?

I had edited my post above please look at it again

$20 is absolutely sufficient for that kind of applications. I can make your program in 1,5 hours for the Parallax Propeller, if you like (my hourly rate is around $60 BTW)

The difference is, that the $10 Propeller is made for high (well...) speed signal processing ("bit banging") whereas the AVRs are not...

Another constructive solution:
As the global structure is a sequencer, you can easily use MSI chips.
(1) 160 kHz oscillator (or a multiple of that), devide by a 74HC4040 counter or such

(2) a 74HC138 3:8 decoder, connected to 3 appropriate pins of the 4040

(3) you can use every other of the outputs to have 6.25us pulses, or combine two adjacent pins ("OR") to have full 12.5us pulses. By cascading 2 decoders you can double the resolution.

Edit

Ooops... The '138 is active low ...you might want a '238 (active high)...

Thank you deSilva but I had done professional programming my self years ago. This project started with a 68HC11A0 and 6840's it's just that the motor technology wasn't there at that time. The h bridge plans I have use 4 high current MOSFETS each leg, one motor I am looking at has neodymium magnets. 4HP in a 3”dia x 5”long package. I took a look at the propeller. It this point in time I just don't get them. I just got the Duemilanove. I just haven't gotten the chance to print out the 440-page data sheet. So I sprinkle some baby Arduinos around. That call distributed processing or delegating.

I don't conceder the Duemilanove a toy.

There is a difference between being a hobby product and being a toy.

So I sprinkle some baby Arduinos around.

Now, who's belittling the Arduino?

The h bridge plans I have

Got a link to those plans?

@Philliart
I do not want you to do anything with the Propeller :slight_smile:
I just wanted to make my point that $10 is enough to solve your problem, when tackeled in the correct way.
I also gave you some hints WRT to restrictions on the Arduino.
Furthermore I gave you a complete working hardware solution ...

And no, I don't want money for it:-)

There is a difference between being a hobby product and being a toy.

The only thing different between a man and a boy is the size (price) of their toys.

Now, who's belittling the Arduino?

No at all
Tiny = baby
I am very new to the Arduino line of micro controllers and I know that tiny is in one of their board names. I did not want someone to think I was talking about a specific board.

I used this opportunity to check the digital...Fast routines.
This here is around the limit

#define ledPin 13
 Timer1.initialize(12);         // called every 12 us

 Timer1.attachInterrupt(callback); 
 pinMode(ledPin, OUTPUT);

 int i;
 int pWidth = 0;
 void callback() {
   digitalWriteFast(ledPin, HIGH);   // set the LED on
   i = pWidth; 
   while (i>0)  --i;
   pWidth +=4; //delay is 0, 4, 8, or 12 loops = 1.5, 3, 4.5, or 6us
   if(pWidth>12) pWidth=0; 
   digitalWriteFast(ledPin, LOW);  
}

This uses nearly half of the processor time. It was not possible to make much faster interrupts; around those 83kHz seems to be the limits.
Pulses generated are 1.5, 3, 4.5, and 6us long, a much better fine tuning is possible here; my delay code is a little bit clumsy...

Remember that the pins for digital...Fast have to be constants!!

Thank you for the code. I have printed it out and will look over it. There are a few things I don't understand yet.

Is there a way or a function to output a byte to port D, pins 0-7? It seems that the Duemilanove only manipulates bits.

Manipulation of "bits only" is a feature of the Arduino HAL. You can of course use the register layer below, as with any AVR chip!


You have to change my code in at least two ways

  • the pulse must be output to four different lines during four succeding interrupts.
  • each fourth interrupt must be delayed for 2 us to make exact 20kHz.

However it should be possible to change the timer initialization (prescaler) to have 12.5us interrupts

It seems that the Duemilanove only manipulates bits.

No see:-

http://www.arduino.cc/en/Reference/PortManipulation