Switch on and off a PWM Digital output without using delay()

Hi guys,

Here's what i need to do with a Arduino Uno (and maybe a bit of electronics if necessary):

  • I need to produce a pulse train that will change both in amplitude and frequency, independently.
  • As the Arduino Uno does not have an analog output, i'm using analogWrite(9,value) where value is the amplitude of my signal that I want to be changing often and with a very good response time.
  • Now i want to be able to switch this PWM signal on and off with a specific frequency that is also changing often and i need a good response time.
  • For this i tried the delay() function, which does what i want except that when delay() increases my response time is impacted beyond what i can accept.

Is there a way to accomplish my goal without using any delay() function ?

I'm thinking of combining 2 analogWrite() functions on 2 different pins. Let's say pin 9 for the main signal, and pin 10 for the frequency. Then use a transistor or MOSFET so that pin 10 will switch on and off the signal of pin 9.

Would it work ? Is there a better way ? Is there a way to do this without using any extra hardware ?

The resulting signal will then be fed to the line-in of an amplifier which will drive a transducer.

thanks for your input.

Doing a bit mor research, i found this thread:
http://playground.arduino.cc/Code/AvoidDelay

it might be what i need.

Have a look at how millis() is used to manage timing without blocking in Several things at a time

...R