Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Thread

Re: [AVR-Chat] Why ADC result is not accurate in the ATtiny15L?

Re: [AVR-Chat] Why ADC result is not accurate in the ATtiny15L?

2004-02-08 by erikc

Erikc  - firewevr@airmail.net
///
"An Fhirinne in aghaidh an tSaoil."
"The Truth against the World."
        -- Bardic Motto

----- Original Message -----
From: Alireza Chiany <arch21558@yahoo.com>
To: <AVR-Chat@yahoogroups.com>
Sent: Sunday, February 08, 2004 04:49
Subject: [AVR-Chat] Why ADC result is not accurate in the
ATtiny15L?


> Hello,
> We have a project with ATtiny15L.
> We are using ADC in this project.
> We have a problem in the ADC result.
> We are using all noise reduction
> methods (Split ground,AREF capacitor,noise canceler,signal
filteration and etc) in this project
> but The ADC result is nonlinear and greater than real
value.
> We are using ATmega8 in the same circuit and same program.
> this circuit is without any noise reduction contrive but
the result is very accurate.
Show quoted textHide quoted text
> Question: Why ADC result is not accurate in the ATtiny15L?
> Regards.
>
>
> ---------------------------------
> Do you Yahoo!?
> Yahoo! Finance: Get your refund fast by filing online

Why ADC result is not accurate in the ATtiny15L?

2004-02-08 by Alireza Chiany

Hello,
We have a project with ATtiny15L.
We are using ADC in this project.
We have a problem in the ADC result.
We are using all noise reduction
methods (Split ground,AREF capacitor,noise canceler,signal filteration and etc) in this project
but The ADC result is nonlinear and greater than real value.
We are using ATmega8 in the same circuit and same program.
this circuit is without any noise reduction contrive but the result is very accurate.
Question: Why ADC result is not accurate in the ATtiny15L?
Regards.

Do you Yahoo!?
Yahoo! Finance: Get your refund fast by filing online

Re: [AVR-Chat] Why ADC result is not accurate in the ATtiny15L?

2004-02-08 by Dave VanHorn

What reference source are you using?
The onboard ref voltage has been rather dissapointing in my experience, 
sitting as high as 2.7V.
A bit off, for a 2.5V "precision" reference.

I've used various external band gap ref chips that output 2.49V or 4.096V 
depending on the application.

Sneaky Sram Subterfuge (Somewhat long and complicated)

2004-02-09 by Dave VanHorn

Having a persistent problem that is proving resistant to standard debugging 
tricks.
I'm hoping that talking it through here, will dredge up the problem.

I'd like to say that I've eliminated all the obvious problems, but I've 
been knocking on this for a while now, with no resolution.
Apologies for the lengthy explanation, but it's a dynamic problem, and 
requires some understanding of what's happening to debug.

Chip: Mega8, 8 MHz internal R/C osc.
Boot routine includes an explicit scrub of all registers, and all SRAM.
Tons of stack space, and there's a constant check for creeping stack,  or 
undesired ISRs, which never fires.
Emulation says the stack only goes down by about 6 calls, which is normal, 
there's over 100 bytes between the last ram var, and the lowest stack point.
The trap routine has been tested in sim, and in emulation, by corrupting 
the stack, or triggering unused ISRs, and it does work there.

I don't think the data reception is at fault, but I'll give a brief 
explanation here:

This system receives data from a master system, using a latch that I read, 
during the INT0 ISR.
If the host "blips" the int line, then it won't be high by the time that I 
look at it in the ISR, (Physically impossible) and so that is "data", which 
I count, and store using X as a pointer dedicated to this ISR.
If the host holds the int line low, then I read this data as a "command", 
and store it in a special SRAM slot, where it is acted on in the main 
routine.  There is more to the comms, like acking data and command, but I 
don't think it's relevant.

The ISR maintains a count of bytes received, in SRAM at 3A7h (Note, not on 
a boundary)

The ISR decides it has a full packet when the byte count reaches 104, and 
it then increments a count of packets received, which is stored in a low 
register. (I've tried moving the byte count to SRAM, no diff).  Receiving a 
command with < 104 bytes received terminates a packet early, and this is 
normal, and desired. Sim and emulation say this is working fine.

Whenever we get a full packet, then I check for buffer wrap, and if so, 
reset X to the beginning of the buffer space.
I also do a "full" check, based on packet count, and signal the master to 
hold off when I'm full (appears to work fine)

Data is stored in a number of 104 byte packets, starting at a fixed address 
in SRAM, and rolling over when full.
It's more or less a standard circular buffer, except that the data is in 
104 byte records, and each is used multiple times before discarding it, 
which involves paving it to zeroes, and incrementing the tail pointer.

Ok, so we have lots of packets in SRAM, and we're wrapping properly, 
detecting full when we should, and all that fun stuff.

I have run this in sim, including simulaitng the ints, and there is never a 
problem.
Unfortunately, I can't sim the command reception.

Also, the diag version runs fine in real hardware, producing endless 
perfect output.

In the diag version, the int0 ints can only happen at one point, when all 
the other tasks have run, so it's not a "real" test.
Because the ints are faked by code in the target system, they can only 
occur at one point in the code, and they "slam" a full packet in before 
returning to the main program flow. Making this more scattered would be 
extremely problematic.

So, the ISR code, when examined, hand-flown, and run in the sim, works 
fine, for hours.
In real life, in the ICE-50 or real chip, it appears to loose it's place 
occasionally.
Unfortunately, telling exactly what happens is next to impossible because 
the ice has no facility for break on write to RAM/REG.

When running for real, the system appears to think it has received a 
command, after some number of packets and commands have been transferred. 
Sometimes it fails in the first packet, sometimes it runs for 100-200 
packets or more before failure.

When I breakpoint on receiving a bogus command, (Check of Master_Command in 
SRAM is <>0) the master and I both agree on the number of bytes 
transferred, and a scope trace proves that the master is not sending me a 
command at that time. So, it's not that a byte is getting misinterpreted.

When I break on receiving a command in the ISR, I only see valid commands, 
so apparently the ISR is not the source of the problem.

The system decides it has a command to process whenever Master_Command in 
SRAM is <>0. This is a very simple test.
Commands of 00H are illegal, and the ISR traps those and converts them to 
FFh which I can see, and is harmlessly discarded.
The ice tells me this never happens, which is good.

It appears that the SRAM var Master_Command at 3B1h is getting corrupted.
I had the same symptoms when Master_Command was in a low register.

Clearing Master_Command whenever I receive a data byte appears to help the 
problem, but does not solve it.
Nor should this be necessary.. It is simply masking the problem.  The 
system checks for commands relatively infrequently, 10-400uS depending on 
what tasks need to run in the scheduler, and when the command byte is stored.

There are no STD's in the code, and I strongly believe that all pointer 
writes (ST X etc) are done with initialized pointers.
I moved Master_Command to SRAM thinking that this would isolate an improper 
write to low ram space, which overlaps the registers, but the symptoms are 
the same, which eliminates that possibility.

If I turn off the command mechanism, then I get very occasional bad data 
lines, where it appears that I thought that I had one more packet than I 
really had, or that a packet terminated very early, which would be hard to 
tell from one "extra" packet.
This could be cases of "false command" happening, it happens at roughly the 
same frequency, and the results are consistent with that happening.  This 
never happens during sim, only in emulation, or on the real chip.

The tasks each preserve the global int enable/disable status, and they 
locally disable ints while they are checking flags.
When they have decided not to run, they restore the int status and exit.
If they decide to run, then they may enable or disable ints as appropriate, 
but the int status is always restored on exit.
There are many points where ints are no problem, and only a few where I 
disable the ints for short periods.
During flag manipulation or checking, ints are disabled, to prevent 
problems if an ISR changes a flag bit in the middle of a decision.
This is also apparently unrelated, but...


Examining and simming/emulating all the data manipulation routines says 
they are fine.

To sum it up, I guess I'm looking for what could corrupt a value stored in 
low register, or high SRAM, apparently identically, when that value is 
relocated.

Any ideas on how to isolate this?  It's a complex system, so turning things 
on and off is pretty much impractical.
There are many tasks, each waiting on flags from other tasks that they have 
completed, before they run, and they in turn set/clear flags appropriately 
to signal other tasks.  That mechanism works, and is apparently unrelated 
to the problem.  If that portion was having problems, the results would be BAD.

So, I think I've talked it out pretty thoroughly, and unfortunately, the 
light bulb is still dark..

Re: Sneaky Sram Subterfuge (Somewhat long and complicated)

2004-02-09 by fnatmed

--- In AVR-Chat@yahoogroups.com, Dave VanHorn <dvanhorn@c...> wrote:
> 
> Having a persistent problem that is proving resistant to standard 
debugging 
> tricks.
> I'm hoping that talking it through here, will dredge up the problem.
 
These are the worst kinds of problems to diagnose.  It's like taking 
the car in for service, and *swearing* to the service manager 
that "it was making that noise as I drove here, and it stopped when I 
entered the parking lot.  Honestly !"

With complex systems like this, I've always found tracer tags to be 
very useful, proving that it's operating the way I think it is.  In 
this case, if you have a spare port, or even just a pin, use it to 
indicate where in the code things are.

For example, dedicate a pin to the act of writing to 0x3b1.  In code 
set the pin, write the sram, clear the pin.  If you have spare pins, 
use them to indicate an ID code for each write.  Set the ID code, set 
the debug pin, write the sram, clear the debug pin.

Then logic analyzer it to death.  Run it, see the error, then spend 
evenings scrolling through the pulse data from the debug pins.  The 
only hassle with this is that it really only finds programming/logic 
errors - writes happening when you didn't expect them.  It won't find 
erroneous writes from buffer overflows etc.  If there's some bizarre 
error somewhere - bad pointer etc - it won't catch those.

If that doesn't work, then expand the logic analyzer.  Keep the debug 
pin operation as above, but track the address/data lines to the 
sram.  Flag every time a write happens to 0x3b1, and verify that the 
debug pin is being toggled around it.  This will prove that the 
writes are or aren't happening at places in code where you expect 
them to be happening.

If every write has an appropriate debug pulse, then it's in the 
code/state-machine somewhere.  If not, then there's a rogue unplanned 
write happening, and that's when things really begin to suck.

Dean.

Re: [AVR-Chat] Re: Sneaky Sram Subterfuge (Somewhat long and complicated)

2004-02-09 by Dave VanHorn

>
>With complex systems like this, I've always found tracer tags to be
>very useful, proving that it's operating the way I think it is.  In
>this case, if you have a spare port, or even just a pin, use it to
>indicate where in the code things are.

We've done a bit of this, unfortunately, it's probably a bad pointer.


>If that doesn't work, then expand the logic analyzer.  Keep the debug
>pin operation as above, but track the address/data lines to the
>sram.  Flag every time a write happens to 0x3b1, and verify that the
>debug pin is being toggled around it.  This will prove that the
>writes are or aren't happening at places in code where you expect
>them to be happening.

Did I mention that it's internal SRAM?

Re: Sneaky Sram Subterfuge (Somewhat long and complicated)

2004-02-09 by fnatmed

--- In AVR-Chat@yahoogroups.com, Dave VanHorn <dvanhorn@c...> wrote:
> 
> >If that doesn't work, then expand the logic analyzer.  Keep the 
debug
> >pin operation as above, but track the address/data lines to the
> >sram.  Flag every time a write happens to 0x3b1, and verify that 
the
> >debug pin is being toggled around it.  This will prove that the
> >writes are or aren't happening at places in code where you expect
> >them to be happening.
> 
> Did I mention that it's internal SRAM?

Argh - dang.  You probably did.  I was commiserating too much to 
notice.  That makes things a little tougher :)

Hrm.  I suppose really all you can do is start instrumenting each 
routine, one at a time.  Pepper the code with diagnostic port 
outputs, before every section that can write *anywhere* to sram.  
Output an ID code, then the current value of 0x3b1, do the 
operation/loop/whatever, then output 0x3b1 again.

Logic analyzer on the debug port, and watch for 0x3b1 to change when 
it shouldn't.  Do it one or two routines at a time, to keep the scope 
of the reams of debug data at least a little bit manageable.  Also 
lets you put a ticky mark next to each one as you eliminate them, to 
narrow the search down.

You have to put that debug code around everything though, even stuff 
you think is pretty simple and obvious.  I've been bitten by slap-the-
forehead things an embarrasing number of times :(

Dean.

Re: [AVR-Chat] Sneaky Sram Subterfuge (Somewhat long and complicated)

2004-02-10 by Brian Dean

On Mon, Feb 09, 2004 at 04:36:30AM -0500, Dave VanHorn wrote:

> This system receives data from a master system, using a latch that I read,
> during the INT0 ISR.
> If the host "blips" the int line, then it won't be high by the time that I
> look at it in the ISR, (Physically impossible) and so that is "data", which
> I count, and store using X as a pointer dedicated to this ISR.

Are you 100% sure about this?  What do you mean by "blip" - how long
is the pulse?  And is it _possible_ that sometimes the "blip" is a
little longer than you expect?  What generates the pulse?

> If the host holds the int line low, then I read this data as a "command",
> and store it in a special SRAM slot, where it is acted on in the main
> routine.

I would home in on this part and see if sometimes the host's data blip
is sometimes being interpretted as a command blip.

> Also, the diag version runs fine in real hardware, producing endless
> perfect output.
> 
> In the diag version, the int0 ints can only happen at one point, when all
> the other tasks have run, so it's not a "real" test.
> Because the ints are faked by code in the target system, they can only
> occur at one point in the code, and they "slam" a full packet in before
> returning to the main program flow. Making this more scattered would be
> extremely problematic.

Is there anywhere in the code where a multibyte pointer variable is
updated or used in both interrupt routines as well as non-interrupt
routines?  Perhaps you have a classic atomic update problem - it works
when you can control when the int0 interrupt occurs, but fails when
the int0 interrupt can occur at any point.  I would also focus on this
as a possibility.  Check every where you load or change the pointer
value.  If the pointer can change inside an interrupt routine, then
double check that interrupts are disabled when the pointer is
dereferenced outside of the interrupt routine.

BTW, this reminds me of once when I struggled with weird memory
corruption bugs for week and the eventual solution was solved by the
setting of a single bit flag!

-Brian
-- 
Brian Dean, bsd@bdmicro.com
BDMICRO - Maker of the MAVRIC ATmega128 Dev Board
http://www.bdmicro.com/

Re: [AVR-Chat] Sneaky Sram Subterfuge (Somewhat long and complicated)

2004-02-10 by Dave VanHorn

At 07:24 PM 2/9/2004 -0500, Brian Dean wrote:
>On Mon, Feb 09, 2004 at 04:36:30AM -0500, Dave VanHorn wrote:
>
> > This system receives data from a master system, using a latch that I read,
> > during the INT0 ISR.
> > If the host "blips" the int line, then it won't be high by the time that I
> > look at it in the ISR, (Physically impossible) and so that is "data", which
> > I count, and store using X as a pointer dedicated to this ISR.
>
>Are you 100% sure about this?

99%... :)
The pulse is just longer than the minimum that will give a guaranteed int 
on the M8 at 8 MHz.
In theory, I couldn't possibly get into the ISR at all, before it goes away.
I also do about 8 instructions before I test, to make it difficult to false.
However, I'm wondering if the host slips me a second, I could be seeing 
that strobe pulse as the long pulse for command.

>What do you mean by "blip" - how long
>is the pulse?  And is it _possible_ that sometimes the "blip" is a
>little longer than you expect?  What generates the pulse?

I think it's inside a cli/sei, but I need to verify that.


>Is there anywhere in the code where a multibyte pointer variable is
>updated or used in both interrupt routines as well as non-interrupt
>routines?

Possible, I'll check.

>  Perhaps you have a classic atomic update problem - it works
>when you can control when the int0 interrupt occurs, but fails when
>the int0 interrupt can occur at any point.  I would also focus on this
>as a possibility.

That's what it feels like.


>  Check every where you load or change the pointer
>value.  If the pointer can change inside an interrupt routine, then
>double check that interrupts are disabled when the pointer is
>dereferenced outside of the interrupt routine.
>
>BTW, this reminds me of once when I struggled with weird memory
>corruption bugs for week and the eventual solution was solved by the
>setting of a single bit flag!

Did I mention that I have a raging case of the flu as well?

Re: [AVR-Chat] Sneaky Sram Subterfuge (Somewhat long and complicated)

2004-02-10 by Dave VanHorn

>
>Is there anywhere in the code where a multibyte pointer variable is
>updated or used in both interrupt routines as well as non-interrupt
>routines?

Just double-checked, X is reserved for INT0, so no problem there.
Z is used in one timer int, but it's pushed and popped. (the right way!)

Re: Sneaky Sram Subterfuge (Somewhat long and complicated)

2004-02-10 by jtvolpe

--- In AVR-Chat@yahoogroups.com, Dave VanHorn <dvanhorn@c...> wrote: 
>  
> > 
> >Is there anywhere in the code where a multibyte pointer variable 
is 
> >updated or used in both interrupt routines as well as 
non-interrupt 
> >routines? 
>  
> Just double-checked, X is reserved for INT0, so no problem there. 
> Z is used in one timer int, but it's pushed and popped. (the right 
way!) 
 
I've come into the conversation late so feel free to wack me on the 
back of the head if this has been asked before.   
 
What compiler are you using ? 
Is the application a mix of 'C' and assembler ? 
 
If you are using GCC, X is used as a general register (r26,r27) by 
the compiler.  A function, 'C' or assembler, called by 'C' is 
allowed to clobber it, but an ISR MUST push/pop X. 
 
Again, sorry if the road is already traveled.

Re: [AVR-Chat] Sneaky Sram Subterfuge (Somewhat long and complicated)

2004-02-11 by Brian Dean

Hi Dave,

On Tue, Feb 10, 2004 at 09:36:14AM -0500, Dave VanHorn wrote:

> >Is there anywhere in the code where a multibyte pointer variable is
> >updated or used in both interrupt routines as well as non-interrupt
> >routines?
> 
> Just double-checked, X is reserved for INT0, so no problem there.
> Z is used in one timer int, but it's pushed and popped. (the right way!)

Please do let us know what the culprit turns out to be if / when you
nail it!

-Brian
-- 
Brian Dean, bsd@bdmicro.com
BDMICRO - Maker of the MAVRIC ATmega128 Dev Board
http://www.bdmicro.com/

RE: [AVR-Chat] Sneaky Sram Subterfuge (Somewhat long and complicated)

2004-02-12 by Larry Barello

You are describing a classic race condition.  I think Brian Dean is right on
the money where the problem is.  Race conditions are very hard to smoke out.
You need a reliable trigger - or, if that isn't possible, then a repeatable
test case (which is the same thing).  Since you have two CPUs the only way
to get it repeatable is to synchronies the clocks & reset.

Good luck...
Show quoted textHide quoted text
-----Original Message-----
From: Dave VanHorn

Having a persistent problem that is proving resistant to standard debugging
tricks.
I'm hoping that talking it through here, will dredge up the problem.

...

RE: [AVR-Chat] Sneaky Sram Subterfuge (Somewhat long and complicated)

2004-02-12 by Dave VanHorn

At 07:16 AM 2/12/2004 -0800, Larry Barello wrote:
>You are describing a classic race condition.  I think Brian Dean is right on
>the money where the problem is.  Race conditions are very hard to smoke out.
>You need a reliable trigger - or, if that isn't possible, then a repeatable
>test case (which is the same thing).  Since you have two CPUs the only way
>to get it repeatable is to synchronies the clocks & reset.

At this point, I'm going to head home, take a couple days off, and then 
attack it again fresh.

It is proving a challenge to find.

Re: Sneaky Sram Subterfuge (Somewhat long and complicated)

2004-02-26 by fnatmed

--- In AVR-Chat@yahoogroups.com, Dave VanHorn <dvanhorn@c...> wrote:
> At this point, I'm going to head home, take a couple days off, and 
then 
> attack it again fresh.
> 
> It is proving a challenge to find.

So, whatever happened with this ?  Is Dave still alive, or are his 
brains spattered all over the keyboard from banging his head on it ?

Inquiring minds wanna know !

D.

Re: [AVR-Chat] Re: Sneaky Sram Subterfuge (Somewhat long and complicated)

2004-02-27 by David VanHorn

At 05:09 PM 2/26/2004 +0000, fnatmed wrote:

>--- In AVR-Chat@yahoogroups.com, Dave VanHorn <dvanhorn@c...> wrote:
>> At this point, I'm going to head home, take a couple days off, and 
>then 
>> attack it again fresh.
>> 
>> It is proving a challenge to find.
>
>So, whatever happened with this ?  Is Dave still alive, or are his 
>brains spattered all over the keyboard from banging his head on it ?
>
>Inquiring minds wanna know !

We found a workaround, but have not found the root problem yet. 
Other fish to fry, etc. 

I will get back on it as soon as possible.

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.