Yahoo Groups archive

AVR-Chat

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

Thread

What is your suggestion?

What is your suggestion?

2006-12-07 by Reza

Hi all;

1st excuse me for poor english;

I'm working with AVR micros more than three years. Working in a 
company in Automation department. I use Code Vision AVR compiler for 
test perposes and WinAVR with AvrStudio 4 for final project. but 
there are some problems in all projects:

1- In some cases i need a software environment to test entire model 
as completely as possible. I tested proteus for simulation but is is 
a powerfull but bad designed program. AvrStudio has no capability to 
write plugins for.
in some cases I need to define harware for my model. I tested using a 
simulator working in DOS/Windows for my applications but having a 
great simulation software needs great time to spend.

2- In some cases, specially defining a serial port protocol, I need 
to use state machine, rather than using multi-task kernels. but 
defining and implementation of a state machine is a time consuming 
task. and when you want to change any logic you may need to review 
all work. is there any tools which could be customized to generate 
AVR assembly or C code in help of state machine design?

3- in C when you want to access a variable in both main code and 
interrupt handlers, you have to declare it as volatile to avoid 
memory access optimization using registers. but if variable be of 
type int, or something larger than one byte in size, bcz access made 
in more than one instruction you may get invalid results. consider 
this:

volatile short n;

SIGNAL(...)
{
   n++;
}

main()
{
   int t = n;
   ....
}

in main() function assembler code looks like this:

    lds r24,n
    lds r25,n+1

if an interrupt happens between two lds instructions and if <n>
have a value of 255 before first lds, you will get 511. in these cases
i may use cli/sei to block interrupts, but is there another way to 
notify the compiler to generate code for me? accessing to data types 
other than byte is not atomic.

4- some compilers have an ability to use near calls when possible 
rather than long calls to reduce code size. is there any way in GCC 
to declare a function as <near> or something? by now I use assembly 
code to reduce code size, using rcalls, instead of call instructions.

Thanks for any suggestion;

Re: [AVR-Chat] What is your suggestion?

2006-12-07 by David Kelly

On Thu, Dec 07, 2006 at 03:22:42PM -0000, Reza wrote:
> 
> 3- in C when you want to access a variable in both main code and 
> interrupt handlers, you have to declare it as volatile to avoid 
> memory access optimization using registers. but if variable be of 
> type int, or something larger than one byte in size, bcz access made 
> in more than one instruction you may get invalid results. consider 
> this:
> 
> volatile short n;
> 
> SIGNAL(...)
> {
>    n++;
> }
> 
> main()
> {
>    int t = n;
>    ....
> }
> 
> in main() function assembler code looks like this:
> 
>     lds r24,n
>     lds r25,n+1
> 
> if an interrupt happens between two lds instructions and if <n>
> have a value of 255 before first lds, you will get 511. in these cases
> i may use cli/sei to block interrupts, but is there another way to 
> notify the compiler to generate code for me? accessing to data types 
> other than byte is not atomic.

All the compiler could do is wrap the variable modifications in cli/sei
exactly the same as you have to do manually. Worse actually as the
compiler doesn't know whether interrupts are enabled so it has to push,
clear, pull, as is used in many library routines.

Might as well manually wrap the critical sections with cli/sei.

-- 
David Kelly N4HHE, dkelly@HiWAAY.net
========================================================================
Whom computers would destroy, they must first drive mad.

RE: [AVR-Chat] What is your suggestion?

2006-12-07 by larry barello

#3 - wrap your variable access in a cli(), sei() to prevent interrupts.
Here is a fast method that also preserves the interrupt state:

{
	char sreg = SREG;
	...
	cli()
	// variable access
	SREG = sreg;
}

#4 there is a command line option to force near calls "-mshort-calls".  I
don't know if external routines are accessed with near calls or not.  It
would be nice if the near calls were on a source file basis with far calls
between source file modules.  AFAIK there is no short/long attribute for
procedures.

These questions might be better answered in the avr-gcc-list@nongnu.org
group

| -----Original Message-----
| From: AVR-Chat@yahoogroups.com [mailto:AVR-Chat@yahoogroups.com] On Behalf
| Of Reza
| Sent: Thursday, December 07, 2006 7:23 AM
| To: AVR-Chat@yahoogroups.com
| Subject: [AVR-Chat] What is your suggestion?
| 
| Hi all;
| 
| 1st excuse me for poor english;
| 
| I'm working with AVR micros more than three years. Working in a
| company in Automation department. I use Code Vision AVR compiler for
| test perposes and WinAVR with AvrStudio 4 for final project. but
| there are some problems in all projects:
| 
| 1- In some cases i need a software environment to test entire model
| as completely as possible. I tested proteus for simulation but is is
| a powerfull but bad designed program. AvrStudio has no capability to
| write plugins for.
| in some cases I need to define harware for my model. I tested using a
| simulator working in DOS/Windows for my applications but having a
| great simulation software needs great time to spend.
| 
| 2- In some cases, specially defining a serial port protocol, I need
| to use state machine, rather than using multi-task kernels. but
| defining and implementation of a state machine is a time consuming
| task. and when you want to change any logic you may need to review
| all work. is there any tools which could be customized to generate
| AVR assembly or C code in help of state machine design?
| 
| 3- in C when you want to access a variable in both main code and
| interrupt handlers, you have to declare it as volatile to avoid
| memory access optimization using registers. but if variable be of
| type int, or something larger than one byte in size, bcz access made
| in more than one instruction you may get invalid results. consider
| this:
| 
| volatile short n;
| 
| SIGNAL(...)
| {
|    n++;
| }
| 
| main()
| {
|    int t = n;
|    ....
| }
| 
| in main() function assembler code looks like this:
| 
|     lds r24,n
|     lds r25,n+1
| 
| if an interrupt happens between two lds instructions and if <n>
| have a value of 255 before first lds, you will get 511. in these cases
| i may use cli/sei to block interrupts, but is there another way to
| notify the compiler to generate code for me? accessing to data types
| other than byte is not atomic.
| 
| 4- some compilers have an ability to use near calls when possible
| rather than long calls to reduce code size. is there any way in GCC
| to declare a function as <near> or something? by now I use assembly
| code to reduce code size, using rcalls, instead of call instructions.
| 
| Thanks for any suggestion;
| 
| 
| 
| 
| 
| Yahoo! Groups Links
| 
| 
|

Re: [AVR-Chat] What is your suggestion?

2006-12-07 by John Samperi

At 02:22 AM 8/12/2006, you wrote:
>AvrStudio has no capability to
>write plugins for.

Well you can get a SDK for Studio from Atmel if you want to
and then you can write your own plug ins. You will need to sign
an NDA.

Regards

John Samperi

********************************************************
Ampertronics Pty. Ltd.
11 Brokenwood Place Baulkham Hills, NSW 2153 AUSTRALIA
Tel. (02) 9674-6495       Fax (02) 9674-8745
Email: john@ampertronics.com.au
Website  http://www.ampertronics.com.au
*Electronic Design * Custom Products * Contract Assembly
********************************************************

Re: [AVR-Chat] What is your suggestion?

2006-12-07 by Richard Reeves

Reza:
> 1- In some cases i need a software environment to test entire model as
> completely as possible. I tested proteus for simulation but is is a
> powerfull but bad designed program. 
In what way is Proteus a badly designed program?



Richard
---
"Sve je bilo tako tiho a nemirno..."
   http://www.musicvangogh.com/

Re: [AVR-Chat] What is your suggestion?

2006-12-07 by Ned Konz

Reza wrote:

> 2- In some cases, specially defining a serial port protocol, I need 
> to use state machine, rather than using multi-task kernels. but 
> defining and implementation of a state machine is a time consuming 
> task. and when you want to change any logic you may need to review 
> all work. is there any tools which could be customized to generate 
> AVR assembly or C code in help of state machine design?

Look at QP-Nano at http://www.quantum-leaps.com ; it's been ported to 
AVR using another compiler, but I ported the full version to avr-gcc easily.

It provides all the infrastructure for multiple state machines; your 
state machines are implemented as a single function per state which 
typically has a switch on the event type.

I don't think that a code generator would do any better than you could 
do with this framework, and it's not been my experience that maintenance 
of such programs is at all difficult.
-- 
Ned Konz
MetaMagix
Camano Island, WA
http://bike-nomad.com

Re: [AVR-Chat] What is your suggestion?

2006-12-08 by np np

I never test using simulations.
  I get stuck into the real hardware and software and debug incrementally.
   
  http://www.ckp-railways.talktalk.net/pcbcad21.htm

Richard Reeves <r_reeves@blueyonder.co.uk> wrote:
          Reza:
> 1- In some cases i need a software environment to test entire model as
> completely as possible. I tested proteus for simulation but is is a
> powerfull but bad designed program. 
In what way is Proteus a badly designed program?

Richard
---
"Sve je bilo tako tiho a nemirno..."
http://www.musicvangogh.com/



         

 Send instant messages to your online friends http://uk.messenger.yahoo.com 

[Non-text portions of this message have been removed]

Re: [AVR-Chat] What is your suggestion?

2006-12-09 by Reza

Hi;

thanks for all suggestions;

- I tested proteus for one or two models, but it is
not as easy as OrCAD or something to work with.

if you want to use a FPGA or something in hardware
model, there is no way (atleast I dont know how) to
use it in model.

- working with real hardware is a time consuming
process. about 3 or 4 years ago, I worked on an ink
jet printer hardware based on Xaar heads. I reduced
software test phase of model to less than a week. but
in my first try, it takes about 2 months w/o good
answer.

at the other hand, you have to ensure your code is
safe to execute then pay attention to hardware design
problems.

this kind of design and implementation is a very time
consuming process for big applications. which i guess,
software must help better to minimize the time you
need to find your software/hardware bugs.

thanks again;



 
____________________________________________________________________________________
Any questions? Get answers on any topic at www.Answers.yahoo.com.  Try it now.

Re: [AVR-Chat] What is your suggestion?

2006-12-10 by Jim Wagner

On Thu, 07 Dec 2006 12:36:06 -0800
 Ned Konz <ned@bike-nomad.com> wrote:
> Reza wrote:
> 
> > 2- In some cases, specially defining a serial port
> protocol, I need 
> > to use state machine, rather than using multi-task
> kernels. but 
> > defining and implementation of a state machine is a
> time consuming 
> > task. and when you want to change any logic you may
> need to review 
> > all work. is there any tools which could be customized
> to generate 
> > AVR assembly or C code in help of state machine design?
> 

I have a hard time imagaining that some sofware framework
could help very much to save time. You still have to define
the states, what occurs in each, and what the events are
that cause state transitions. I can't see how "tools" will
help you with any of that. 

I say that from experience of having built some fairly
complex  state machines on both 8051's and AVRs. Also, the
key, in my mind, to maintenence is "Comments". Comment,
comment, comment. Put descriptive headers with written
descriptions of your state machine in the source code.
 Describe what is supposed to happen in each state, what it
represents, and the logic behind the state transition
logic. The written description can take more lines than the
executed code, but its worth it a year later.

Jim

---------------------------------------------------------------
The Think Different Store
http://www.thinkdifferentstore.com/
For All Your Mac Gear
---------------------------------------------------------------

Re: [AVR-Chat] What is your suggestion?

2006-12-13 by Reza

Hi;

Thanks specially for suggestions made by "Ned Konz".
Thats seems to be helpfull. i'l try it.

Thanks for commenting hints from Jim, also.

but about using cli/sei pairs programatically in code,
using this style of coding, may make some problems bcz
of forgetting to write such codes. the main problem
is:

is there any way to customize code generation schema
of GCC and adding new properties or attributes to
cover our needs. I dont want to loose GCC and switch
to another compiler.

at last, thanks again for your great suggestions.
Thanks so much;
reza.



 
____________________________________________________________________________________
Cheap talk?
Check out Yahoo! Messenger's low PC-to-Phone call rates.
http://voice.yahoo.com

Re: [AVR-Chat] What is your suggestion?

2006-12-13 by Cat C

I have another suggestion:

I'm thinking it would be nice if the "Subject" field would be worded such 
that looking at it one can tell what it's about, rather than generic 
sentences that don't give a clue.

For example "Timer 1 Troubles" is pretty good, "Tiny24 Timer 1 Troubles in 
AVRStudio Simulator" might be even better.

"What is your suggestion"... not so hot.

Just my 2 cents.

Cat

----Original Message Follows----
Show quoted textHide quoted text
From: Reza <reza_agha@yahoo.com>
Reply-To: AVR-Chat@yahoogroups.com
To: AVR-Chat@yahoogroups.com
Subject: Re: [AVR-Chat] What is your suggestion?
Date: Wed, 13 Dec 2006 06:14:36 -0800 (PST)

Hi;

Thanks specially for suggestions made by "Ned Konz".
Thats seems to be helpfull. i'l try it.
....

_________________________________________________________________
Download now! Visit http://www.telusmobility.com/msnxbox/ to enter and see 
how cool it is to get Messenger with you on your cell phone.  
http://www.telusmobility.com/msnxbox/

Re: [AVR-Chat] using cli/sei pairs

2006-12-13 by Ned Konz

Reza wrote:
> Hi;
> 
> Thanks specially for suggestions made by "Ned Konz".
> Thats seems to be helpfull. i'l try it.
> 
> Thanks for commenting hints from Jim, also.
> 
> but about using cli/sei pairs programatically in code,
> using this style of coding, may make some problems bcz
> of forgetting to write such codes. the main problem
> is:
> 
> is there any way to customize code generation schema
> of GCC and adding new properties or attributes to
> cover our needs. I dont want to loose GCC and switch
> to another compiler.

You can use C++ and make "atomic guard" objects whose constructors and 
destructors do the work. You can also make objects whose read/write 
access is guarded.

-- 
Ned Konz
ned@bike-nomad.com
http://bike-nomad.com

Re: [AVR-Chat] What is your suggestion?

2006-12-13 by np np

I left one group because the rules for messages became intolerable.

I found in the end I could not be botherd to forward my valuable advice because it was simply too much effort !

A little tolerance is called for.

http://www.ckp-railways.talktalk.net/pcbcad21.htm




Cat C <catalin_cluj@hotmail.com> wrote:                                  I have another suggestion:
 
 I'm thinking it would be nice if the "Subject" field would be worded such 
 that looking at it one can tell what it's about, rather than generic 
 sentences that don't give a clue.
 
 For example "Timer 1 Troubles" is pretty good, "Tiny24 Timer 1 Troubles in 
 AVRStudio Simulator" might be even better.
 
 "What is your suggestion"... not so hot.
 
 Just my 2 cents.
 
 Cat
 
 ----Original Message Follows----
Show quoted textHide quoted text
 From: Reza <reza_agha@yahoo.com>
 Reply-To: AVR-Chat@yahoogroups.com
 To: AVR-Chat@yahoogroups.com
 Subject: Re: [AVR-Chat] What is your suggestion?
 Date: Wed, 13 Dec 2006 06:14:36 -0800 (PST)
 
 Hi;
 
 Thanks specially for suggestions made by "Ned Konz".
 Thats seems to be helpfull. i'l try it.
 ....
 
 __________________________________________________________
 Download now! Visit http://www.telusmobility.com/msnxbox/ to enter and see 
 how cool it is to get Messenger with you on your cell phone.  
 http://www.telusmobility.com/msnxbox/
 
 
     
                       

 		
---------------------------------
 All new Yahoo! Mail "The new Interface is stunning in its simplicity and ease of use." - PC Magazine

[Non-text portions of this message have been removed]

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.