calculate average

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

Hi all,

 

I calculate the average of 16 number with the following code in a attiny24A. This code works fine in a atmega328.

The input voltage is constant so the average must be constant too, but the average drops to zero and I can't find out why.

 

I take a new sample (from a steady voltage) everytime the interrupt is executed. Than I just put SumV1 (the average value) to a PWM output. This goes to zero.

 

I don't think I use anything that is not possible inside the attiny24A.

Hopefully somebody can give me a clue.

Greetings, Patrick

 

Attachment(s): 

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

It would help if you posted a complete small program that demos the problem.   Can you run it the simulator and duplicate your problem? 

One more question, are interrupts enabled anywhere in your program, if so, how have you protected the data registers used by your ave() function?

 

Jim

 

 

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"

 

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

That's half a program. It mentions variables and labels that are not shown.

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

I will make a total program and will comeback on this issue.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
		ldi		ZH,high(Voltmes1)	;Set the pointer at the start of the averaging table 
		ldi		ZL,low(Voltmes1)

Should that not be (Voltmes1<<1) to make it a byte address?

Regards,
Steve A.

The Board helps those that help themselves.

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

Koshchi wrote:

		ldi		ZH,high(Voltmes1)	;Set the pointer at the start of the averaging table 
		ldi		ZL,low(Voltmes1)

Should that not be (Voltmes1<<1) to make it a byte address?

No.  SRAM addresses are byte addresses.

The byte/word problem comes from flash addresses in which gnu believes in bytes and the processor believes in words.

In such cases one should >>1 or gs .

Iluvatar is the better part of Valar.