analogRead() seems to be fast enough. ... But we're drifting off topic...
-My sample clock wants to be 125us which I think will be another timer interrupt (I'll write that part tomorrow).
There must be a slick way to turn interrupts on and off individually with minimal avr register writes.
TIMSK1 &= ~(1<<OCIE1B); // Turn off timer interrupt :TIMSK1 |= (1<<OCIE1B); // Turn timer interrupt back on
Quote from: vvmvbb on Jan 04, 2013, 04:31 amanalogRead() seems to be fast enough. ... But we're drifting off topic...Well, not really, because timing seems to be important to you.Quote from: vvmvbb on Jan 04, 2013, 02:14 am-My sample clock wants to be 125us which I think will be another timer interrupt (I'll write that part tomorrow).A normal analogRead (save fidding with registers) will take 104 uS. So most of your 125 uS is gone in doing the analogRead alone. I'm drawing that to your attention in case you think it is instant, and that you have something like 110 uS over between reads.One possible thing you could do which would remove the worry about interrupt latency, and also whether or not another interrupt was active, would be to use the external ADC trigger (page 252 and 266 of the datasheet). You could start the conversion highly reliably on a timer compare match event, and then just use an interrupt to gather the ADC results, when available. This also means you don't wait 104 uS doing nothing. Win win!
Avoiding other issues...QuoteThere must be a slick way to turn interrupts on and off individually with minimal avr register writes.Why do you have this "minimal avr register writes" desire? To turn off an INDIVIDUAL interrupt, you typically have to change a single bit setting in one register:Code: [Select]TIMSK1 &= ~(1<<OCIE1B); // Turn off timer interrupt :TIMSK1 |= (1<<OCIE1B); // Turn timer interrupt back onThose should run about 3 Instructions each, and this isn't some multi-GHz chip where accessing an IO register might be unusually "expensive" because it stalls the pipeline and invalidates caches or something. If you want control of the individual interrupts, I don't think that you can get any "slicker." Now do you need to.Note that you do NOT need to reinitialize the rest of the timer just to turn interrupts on and off, but that may mean that you will get an interrupt as soon as you re-enable it...
Please enter a valid email to subscribe
We need to confirm your email address.
To complete the subscription, please click the link in the
email we just sent you.
Thank you for subscribing!
via Egeo 16