Re: Are 4000 interrupts per second a problem for AVR?

My microcontroller project has a small design mistake: I'm driving a small

> buzzer but I accidentally connected it to the wrong pin. It should have > been connected to the OC0 pin which allows me to simply set the Timer0 > register and it will produce a PWM output with a certain frequency. > Connecting the buzzer to the wrong pin forces me drive the buzzer 'manually.' > > So I'm planning to generate an timer interrupt and toggle the pin there > but this will mean that the number of interrupts will equal the buzzer > frequency, about 4000 hz in my case. The ISR (interrupt service routine) > should be very small but I'm wondering if the AVR will be up to the task. > Has anyone done something similar? BTW I'm driving the Mega-AVR with a > 8Mhz crystal but I can upgrade it to 16Mhz if needed.

I once did a 10000 Hz ISR that does an update for 4 stepper motors, and sends the drive signals out on a 32 bit SPI chain. This was on an atmega128 using a 16MHz xtal. All code written in C. So, 4000 Hz with a simpler ISR should be fairly easy.. assuming of course you don't have too many other things going on.

Reply to
Bob White
Loading thread data ...

why not just modify your board with a cut and a piece of wire - much easier all round!

-- Sell your surplus electronic components at

formatting link
Search or browse for that IC, capacitor, crystal or other component you need.

Reply to
Alan

small

'manually.'

task.

This should not be a problem. I am running an ISR at 19200Hz which reads 4 input lines and runs 4 software uarts. No sweat.

Meindert

Reply to
Meindert Sprang

On 14/03/2006 the venerable George Orwell etched in runes:

Actually to produce a 4kHz signal you're looking at an 8kHz ISR rate. One ISR for each transition. With an 8MHz crystal that's 1000 clock cycles per ISR.

If you can't change the pin then you might be able to change the buzzer to a self-oscillating one that only needs to be switched on and off. Seems like a better solution to me.

--
John B
Reply to
John B

I've also had 10 kHz interrupt routines on an AVR, running at 8 MHz. But I think the tightest challenge was running a 38.4 kbaud software UART with 4 times sampling (153.6 kHz interrupts) on a 7.37 MHz AVR, giving precisely 48 clock ticks between each interrupt.

So 4000 Hz is no problem. If you want to minimise the overhead, write the ISR in assembly. Figure out how many (if any) registers you need, and reserve them from use by your compiler. That way you don't need any context saving or restoring, except perhaps for the status register, and all your ISR-critical data is in registers when the code starts.

Reply to
David Brown

I've done a 2kHz piezo using a 4MHz '05 (1MHz bus rate) (interrupt every 250usec), with enough time left over to do 32-bit PID control,

15-bit slope ADC and scan displays/keyboard, so I don't think you'll have any problems with an 8Mhz AVR 'less'n you do something silly like write the ISR in C.

Best regards, Spehro Pefhany

--
"it's the network..."                          "The Journey is the reward"
speff@interlog.com             Info for manufacturers: http://www.trexon.com
 Click to see the full signature
Reply to
Spehro Pefhany

My record for real time response is 250,000 context switches per seconds on an HPC16083

32 tasks, each running 4 us (including the context switch)

Not too bad for a CPU with just a few MIPS. When there is a will, there is a way.

--
Best Regards,
Ulf Samuelsson
 Click to see the full signature
Reply to
Ulf Samuelsson

To produce 4000hz you would actually need 8000 interrupts a second if you intend to make a square wave.

Whether you can do this depends on your other timing requirements. If you can afford to only do only the buzzer, no problem.

Reply to
diggerdo

The HPC has more than just a few MIPs - can't they run at up to 40 MHz? (Our HPC apps never used more than 10 MHz.) About 15 years ago, they were one of the fastest microcontrollers available. Still, at 250,000 context switches a second, there can't have been much left cpu time left after the context switch overhead?

Reply to
David Brown

Only the HPC46100, the others were limited to 16-20 Mhz, and it was an accumulator based architecture with a few address register.

Nope, the memory to memory address mode helped a lot.

--
Best Regards,
Ulf Samuelsson
 Click to see the full signature
Reply to
Ulf Samuelsson

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.