Resolved: [ASM] tiny13 ADC not triggering on timer overflow

Go To Last Post
6 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi there!

I'm trying to get the ADC on an ATtiny13 (@1MHz) working with the timer triggering a conversion every 1/25 sec (i.e. 25 conversions per second).

What I have:

Timer0 in CTC mode, prescaler 1024
TCCR0A=0b00000010
TCCR0B=0b00000101

top value set to 40 (1024/41=25)
OCR0A=40

interrupt "output compare a" activated
TIMSK0=0b00000100

ADC using Vcc as reference, value right-adjusted, ADC1 used
ADMUX=0b00000001

AD-Conversion enabled, interrupt on conversion end enabled, prescaler 8 (1MHz/8=125kHz)
ADCSRA=0b10101011

Conversion start on above interrupt
ADCSRB=0b00000011

In the current AVR Studio Simulator, the counter does run, the output compare interrupt does fire but a conversion doesn't start. If I manually start a conversion by setting the ADSC bit (ADCSRA bit 6), it does convert, it does fire the "conversion finished" interrupt and it does return to the main loop.

So I guess there is a bit set to the wrong value in the above registers and I can't find it. Can anyone help me here with this?

Background:

I'm trying to build a light barrier using a photoresistor, pulsed for ambient light compensation. The photoresistor is fast enough (says the datasheet), it'll be a reflecting light barrier (photoresistor and IR-LED on one side, a reflector on the other one).

First, the LED is switched on, the photoresistor gets its time to set the voltage right (approx. 40ms), the brightness is measured and compared to the internal "1" value. Then, the LED is switched off, the photoresistor gets time again, again measurement and comparison to the internal "0" value. On each measure, the "1" or "0" value (depending on the LED being on or off) is adjusted by 4 into the right direction. So adaption to ambient light can take up to 10 seconds. This will be tweaked to a shorter time (without misfiring) as soon as it's running on hardware.

Thanks a lot for any hints!

Markus

Markus

Last Edited: Sun. Feb 7, 2010 - 08:50 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

...

Last Edited: Wed. Feb 17, 2010 - 11:27 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
interrupt "output compare a" activated
TIMSK0=0b00000100

Why are you doing this? What do you do in the interrupt?

My guess is that you are enabling the interrupt, but not providing an ISR for it. You do not need to enable the timer interrupt to use the timer compare match to trigger the ADC.

Regards,
Steve A.

The Board helps those that help themselves.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi there!

I was using AVR Simulator 1 instead of 2 - and that one didn't go into the conversion done ISR. Using Simulator 2, my code works, unaltered.

I set the output compare match a interrupt because I understood it that way: the interrupt starts the conversion, so the interrupt has to be enabled (a not-enabled interrupt can't trigger anything, right?). The datasheet said nothing about _not_ enabling the interrupt and still using it for ADC start. And yes, you were right, I had no ISR for that interrupt (just RETI).

The issue seems solved, thanks a lot for your input! So today, I'll build the thing and test it in hardware.

so long,
Markus

Markus

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

The datasheet said nothing about _not_ enabling the interrupt and still using it for ADC start.

Quote:
Note that an Interrupt Flag will be set even if the specific interrupt is disabled or the Global Interrupt Enable bit in SREG is cleared. A conversion can thus be triggered without causing an interrupt. However, the Interrupt Flag must be cleared in order to trigger a new conversion at the next interrupt event.

Search the datasheet for ADATE.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

oops, seems like I didn't notice that at the end of the page - you're absolutely right. But still, it didn't work with simulator1 - and the problem is solved now.

Well, the circuit doesn't work in hardware yet because the LDR I bought isn't sensitive to IR light. Silly me. Barely fast enough, but not detecting much at all. It's 0.02V more if the IR LED is on and within 5cm of the LDR. So I ordered some phototransistors (substantially faster and those I bought are definitively made for IR), should be here by tomorrow.

Markus