Reply by Ulf Samuelsson March 15, 20062006-03-15
"David Brown" <david@westcontrol.removethisbit.com> skrev i meddelandet 
news:4417c7b5$1@news.wineasy.se...
> Ulf Samuelsson wrote: >>> 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. >>> >> >> 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. > > The HPC has more than just a few MIPs - can't they run at up to 40 MHz?
Only the HPC46100, the others were limited to 16-20 Mhz, and it was an accumulator based architecture with a few address register.
> (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?
Nope, the memory to memory address mode helped a lot.
> >> When there is a will, there is a way.
-- Best Regards, Ulf Samuelsson This is intended to be my personal opinion which may, or may bot be shared by my employer Atmel Nordic AB
Reply by David Brown March 15, 20062006-03-15
Ulf Samuelsson wrote:
>> 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. >> > > 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.
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?
> When there is a will, there is a way. >
Reply by diggerdo March 14, 20062006-03-14
"George Orwell" <nobody@mixmaster.it> wrote in message 
news:82b6bab376ccf0dcec34b9f0b41ca655@mixmaster.it...
> > 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.
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 by Ulf Samuelsson March 14, 20062006-03-14
> 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. >
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 This is intended to be my personal opinion which may, or may bot be shared by my employer Atmel Nordic AB
Reply by Spehro Pefhany March 14, 20062006-03-14
On Tue, 14 Mar 2006 11:24:46 +0100 (CET), the renowned George Orwell
<nobody@mixmaster.it> wrote:

> >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'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 Embedded software/hardware/analog Info for designers: http://www.speff.com
Reply by David Brown March 14, 20062006-03-14
Bob White wrote:
> George Orwell wrote: > >> 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. >
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 by John B March 14, 20062006-03-14
On 14/03/2006 the venerable George Orwell etched in runes:

> > 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.
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 by Meindert Sprang March 14, 20062006-03-14
"Bob White" <bwhite06@xs4all.nl> wrote in message
news:1142333475.032460.37170@v46g2000cwv.googlegroups.com...
> George Orwell wrote: > > > 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.
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 by Alan March 14, 20062006-03-14
On Tue, 14 Mar 2006 11:24:46 +0100 (CET), George Orwell
<nobody@mixmaster.it> wrote:

> >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.
why not just modify your board with a cut and a piece of wire - much easier all round! -- Sell your surplus electronic components at http://ozcomponents.com Search or browse for that IC, capacitor, crystal or other component you need.
Reply by Bob White March 14, 20062006-03-14
George Orwell wrote:

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