Sharing Timer 0 ? (Just to be sure)

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

Hi

I wish to share the "Timer/Counter 0" Compare Match "A" IRQ

One IRQ Handler will do a Warning beep "Sound"..and the Other to Move a "Servo"

These would be Two independent "IRQ Handlers"

With the labels

Sound:
Code
.
.
ECT
.
.
RETI
;******************
Servo:
Code
.
.
ECT
.
.
RETI

How do I change the IRQ's Jump Vector address ?? (Using ASM)

I just want to be sure.

Would It be as easy as this ??

----------- Code Snip Samples

LDI R16,(Sound)  ; Get Memory Location and output this
OUT OC0Aaddr,R16 ; 0x000A Timer/Counter0 Compare Match

LDI R16,(Servo)  ; Get Memory Location and output this
OUT OC0Aaddr,R16 ; 0x000A Timer/Counter0 Compare Match

"We look for things.. Things that make us go."

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

Quote:

How do I change the IRQ's Jump Vector address ?? (Using ASM)

You cannot. The vector table is in flash and unchangeable at run time.

What you can do is have a generic handler that then uses a RAM based pointer to IJMP/ICALL to the "current" handler.

Of course you can just have a single handler:

ISR:
  cpi r16, 1
  breq servo

sound:
  ...
  reti

servo:
  ...
  reti

Set r16=1 when you want the servo handling code. Otherwise it'll do sound:.

But are these things really mutually exclusive? Or are there times when you might want to do both sound and servo in the ISR? If so:

ISR:
  cpi do_servo, 1
  brne try_sound
  rcall servo_handler
try_sound:
  cpi do_sound, 1
  brne finished
  rcall sound_handler
finished:
  reti

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

Quote:
What you can do is have a generic handler that then uses a RAM based pointer to IJMP/ICALL to the "current" handler.
I've done this before. In a video app, I had the ISR vector do an IJMP. On a live scan line it was pointing to the video out routine. On vertical blanking lines it would point to various other routines (one line might be read the X or Y of the joystick, another might be to update button debounce, another update the sound, etc.). It worked quite well. One of the advantages of doing asm.

Regards,
Steve A.

The Board helps those that help themselves.

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

clawson wrote:
You cannot. The vector table is in flash and unchangeable at run time.

Ya.. Thanks.. Didn't think of that.. :oops:
--------
I'll do that "Flag" BRNE stuff.. that will work.

Thanks again Guys

"We look for things.. Things that make us go."

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

But, often what you describe (overloaded vector) can be done in other way(s).

I assume you are "out of timers". What AVR model? What mode is the timer running?

One alternative is to use the overflow interrupt. Depending on the timer mode this would fire with the same frequency as the compare match in steady-state.

Another alternative is to use CompareB if available.

All speculation until you tell more.

As you mentioned "warning" and "move", it sounds like these two application states are mutually exclusive?

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

As for out of timers yes and no..
I'm just using (playing) with the ATtiny25

I don't need the Beeps.. But that would be no fun.
also Got-a have a blinking LED 1Hz rate.. (Timer 1)
The AVR project would not be complete without it.

My Jazzy blinking LED (if it stops blinking) I messed up my code.
With an endless loop or something.

The timer mode is just a simple "Compare Match"

Come to think of it.. Guess I could "Set things up"
For Timer 0
for a Compare match using "B".. and use that IRQ
for the "Servo"

And use Compare match "A" IRQ for the Sound Beep.

They aren't running at the same time..

So I could alternate the IRQ enables

All sorts of ways.. (experience helps)

Getting fancy with the code helps learn..

That’s all this project is about.. (just playing to learn)

5 switches (and resistors for different) voltage drops on ADC3

Each time I move a switch

(1) Beep for 1'st switch

(2) Beeps for 2'nd switch

(3) Beeps for 3'rd switch

ETC..

This in turn will position the Servo

0 degrees with first switch
45 degrees with second switch
90 degrees with third switch
135 degrees with forth switch
180 degrees with fifth switch

Why all this.. ??

Just to learn how to set up the Analog to digital converter
And Learn about Timers..

The ADC is working and the beeps..
Now comes the servo (I hope)

As long as I Mind my P's & Q's (Ports and IRQ's)

All should be fine.

"We look for things.. Things that make us go."