On Tue, 16 Feb 2010 17:59:14 +0000, "Cristiano Cesaretto" said: > In one of my projects I am using a 18F14K50 to create a square wave. I > use a > timer interrupt to switch the signal on and off. > The wave frequency is set sending data to the PIC through the USB port. > > Now I would like to generate 4 or 5 of these signals, with different > frequencies that change over time. I don't think I can keep using timer > interrupts, because the PIC hasn't got enough timers and also I have got > the > feeling it is not good spending most of the CPU time handling interrupt > routines. > > Signals change from 0V to 5V, and frequency from 0Hz to 3KHz. > If anybody has a good idea, I would be very grateful. Hi Cristiano, I did a project with a 16F627 that made 4 different square waves plus their complements. It used DDS(direct digital synthesis) whereby you have a large accumulator for each output, the hi bit for each being shadowed out to pins for the actual output. At regular intervals you add something to the accumulator. So the bigger the add number the higher the frequency. Making only square waves there is some jitter but at 3KHz it would be minimal. If you need more details I can dig up the code. As I recall I did two versions, one using the timer interrupt and the other using tight code to get higher frequencies. Cheerful regards, Bob -- http://www.fastmail.fm - Choose from over 50 domains or use your own -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist