CC wrote:> msg wrote: > >> Tim Wescott wrote: >> >> <snip> >> >>> >>> My question is: Does anyone know a good tutorial that covers all of >>> this, or at least techniques for implementing the task loop/state >>> machine method? >> >> >> Believe it or not, LaBrosse's book covers each topic you cited with >> example (pseudo) code and is quite tutorial in its approach in my >> opinion. > > > Considering that Jean LaBrosse appears to have 4 books in print: > > http://www.amazon.com/s/ref=nb_ss_b/002-3183383-0799266?url=search-alias%3Dstripbooks&field-keywords=LaBrosse%2C+jean&x=0&y=0 > > > Could you tell us to which one you are referring? > > > Thanks. >There is a section in the 2nd book (uC/OS-II) that is pretty good; I also recommend the online tutorial at FreeRTOS.org. Michael
Embeded Tutorial?
Started by ●February 10, 2008
Reply by ●March 3, 20082008-03-03
Reply by ●March 3, 20082008-03-03
Matthias Arndt schrieb:> Lanarcam schrieb: >> http://www.le.ac.uk/engineering/mjp9/pes1ohp_a4.pdf > > That's very interesting! I'll keep this as a generic tutorial in case I > meet someone who is interested in such a course. It supplemented my > knowledge on Embedded stuffs as well :)Hm... from page 29 of the pdf: > Problem > > How do you create a simple delay without > using any hardware (timer) resources? > > Solution: > > Loop_Delay() > { > unsigned x,y; > for (x=0; x<65536; x++) > { > y++; > } > } I don't have any experience with the 8051, but I would expect that any c-compiler that has been updated during the last 10 years would optimize this function away. The only reliable way to create a delay using such a for-loop is to declare y as volatile. Old and obsolete stuff is you ask me.. For beginners this may do more harm than good. Nils
Reply by ●March 3, 20082008-03-03
Nils wrote:> Matthias Arndt schrieb: >> Lanarcam schrieb: >>> http://www.le.ac.uk/engineering/mjp9/pes1ohp_a4.pdf >> >> That's very interesting! I'll keep this as a generic tutorial in case I >> meet someone who is interested in such a course. It supplemented my >> knowledge on Embedded stuffs as well :) > > Hm... from page 29 of the pdf: > > > Problem > > > > How do you create a simple delay without > > using any hardware (timer) resources? > > > > Solution: > > > > Loop_Delay() > > { > > unsigned x,y; > > for (x=0; x<65536; x++) > > { > > y++; > > } > > } > > > I don't have any experience with the 8051, but I would expect that any > c-compiler that has been updated during the last 10 years would optimize > this function away. > > The only reliable way to create a delay using such a for-loop is to > declare y as volatile. > > Old and obsolete stuff is you ask me.. For beginners this may do more > harm than good. > > Nils > > >Why would this be specific to 8051 ?? Any C compiler would compile this code. Old and obsolete, I take that personally !!! ;-) donald
Reply by ●March 3, 20082008-03-03
donald schrieb:> > Any C compiler would compile this code. >Sure it will compile, but why write such a null-code at all? This is what GCC 4.2.2 makes out of the code. Compiled with -O1 for x86, but I'm sure it'll look similar for other architectures and compilers: > _delay LABEL NEAR > push ebp ; 0000 _ 55 > mov ebp, esp ; 0001 _ 89. E5 > pop ebp ; 0003 _ 5D > ret ; 0004 _ C3 Not much delay there if you ask me..> Old and obsolete, I take that personally !!! ;-):-) Nils
Reply by ●March 3, 20082008-03-03
Nils wrote:> donald schrieb: > >> >> Any C compiler would compile this code. >> > > Sure it will compile, but why write such a null-code at all? > > This is what GCC 4.2.2 makes out of the code. Compiled with -O1 for x86, > but I'm sure it'll look similar for other architectures and compilers: > > > _delay LABEL NEAR > > push ebp ; 0000 _ 55 > > mov ebp, esp ; 0001 _ 89. E5 > > pop ebp ; 0003 _ 5D > > ret ; 0004 _ C3 > > > Not much delay there if you ask me.. > >> Old and obsolete, I take that personally !!! ;-) > > :-) > > NilsTry making x and y static. donald
Reply by ●March 3, 20082008-03-03
donald schrieb:> Try making x and y static. > > donaldDoesn't makes it better :-) This code: > void delay () > { > static unsigned x,y; > for (x=0; x<65536; x++) > { > y++; > } > } Compiles into: > _delay LABEL NEAR > mov eax, dword ptr [_y.1526] > push ebp > mov ebp, esp > pop ebp > add eax, 65536 > mov dword ptr [_x.1525], 65536 > mov dword ptr [_y.1526], eax > ret Still not much of a delay (and not much of clever code either...) If you want the compiler to not optimize the loop away y must be declared as volatile. No other way around it. I see such delay-loop b*shit way to often. Last time it was in a DSP example code for some init-code to wait some moment after powering on a piece of hardware. Good idea in principle. I don't know what the engineer was smoking while he wrote that code though. The code even had comments and gave hints how many iterations would give what kinds of delays. How stupid is that? All compilers removes redundant loops unless you compile without optimizations or force them via volatiles.
Reply by ●March 3, 20082008-03-03
Nils wrote: <snip>> I don't know what the engineer was smoking while he wrote that code > though. The code even had comments and gave hints how many iterations > would give what kinds of delays. How stupid is that? All compilers > removes redundant loops unless you compile without optimizations or > force them via volatiles.Not true, for example certain versions of Hi-Tech C would compile that code into a delay loop correctly without any special command line switches. No need for 'volatile' declarations. Michael
Reply by ●March 4, 20082008-03-04
In message <13sp9ivef4avidf@corp.supernews.com>, msg <msg@_cybertheque.org_> writes>Nils wrote: > ><snip> >> I don't know what the engineer was smoking while he wrote that code >>though. The code even had comments and gave hints how many iterations >>would give what kinds of delays. How stupid is that? All compilers >>removes redundant loops unless you compile without optimizations or >>force them via volatiles. > >Not true, for example certain versions of Hi-Tech C would compile >that code into a delay loop correctly without any special command line >switches. No need for 'volatile' declarations. > >MichaelAs you say "certain versions" of some compilers will do it one way and lots will optimise it out. So as a delay it is non portable and the delay is completely variable depending on the system it is running on. In which case do a hardware delay using HW timers. It to will not be portable BUT it will give a precise and reliable delay. -- \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ \/\/\/\/\ Chris Hills Staffs England /\/\/\/\/ /\/\/ chris@phaedsys.org www.phaedsys.org \/\/\ \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/