### Thread: Basic information

1. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Nov 2013
Posts
2
Rep Power
0

#### Basic information

Hi,
I'm trying to learn c programming and I was reading the book and there are a few thing that I don't understand.
-what is elapsed time
- what is state machine
-what are Prescale, period register ,IDEL, ISR and TIMER and what do they do?
-what does 0x31 mean?
-how can I get DELAY
-what is interrupt and how can I get interrupt each (1,5 or any number) second

thank you
2. Which book?

Interrupts would be quite hardware dependent, usually at an assembly language coding level (yes of course we can handle it in c, but not usually)

J implements the finite state machine; a verb that is part of the language. Read about it at this link. Alternatively you could investigate flex and bison on the web.

0x31 is a c language hexadecimal numeric representation. In the
Originally Posted by wikipedia
the Hindu-Arabic numeral system developed by ancient Indian mathematicians
digits placement determines the scaling magnitude.
To convert 31 in base 16 to base 10 use the equation
3*pow(16,1) + 1 * pow(16,0)
which gives..uh..about 49. Let's check in executable Iverson notation
Code:
```   16b31
49```
Good!

DELAY: once again, in c you'll use a library call that abstracts the hardware. Time now, to sleep. zzzz
3. Apparently, your book is about embedded programming. If you are doing or preparing to do embedded programming, then that book may be appropriate. If you are not going to do embedded programming but instead application programming, then that book would not be appropriate.

If you have no clue what "embedded programming" is, then obviously you are not preparing to do embedded programming and you should get a different book.

Most of your other questions pertain exclusively to embedded programming.

Originally Posted by geekStar
- what is state machine
There are different levels to this question. Most computer science students are only aware of the theorical basis for state machines: finite-state automata (fsa), AKA "finite-state machines" (fsm) (that is a link to the Wikipedia article on the subject; read it). In school, we used the theory in compiler class in order to understand the process of parsing tokenized code.

It wasn't until I had been working professionally for six years that another programmer showed me a software technique based on fsm's, a technique that we use extensively in our current produces both to parse data streams and to control sequences of actions over extended periods of time (in computer time). Basically, you define a number of states, the action(s) to be performed when in that state, and the conditions that will cause you to transition to another state. We normally implement that in C with a switch state whose cases are the states of the fsm. That Wikipedia article whose link I provided above in turn links you to an article on the software implementation of an fsm: Automata-based programming (yes, this is another link).

In the future when you are researching something new, I would recommend that one of your first steps should be to look it up in Wikipedia, which starts at http://www.wikipedia.org/. What you will find there should provide you with basic information, plus links to other sources from which you can do serious research. I'm not recommending Wikipedia as a research source in itself, but rather as a good first step in starting your research.

If you are not a native English speaker, then an added benefit is that most articles also have versions in other languages, so by reading in both English and your native language, you can learn what the technical terms are. To illustrate the value of that, a Portuguese programmer once came here and posted a question on how to use lights in multithreading. Nobody had any idea what he was talking about, but from my Spanish I remembered that the word for a traffic light (which in American English we sometimes simply refer to as a "light", as in "turn right at the second light") is semáforo. When I verified via Wikipedia that the term is the same in Portuguese, I was able to tell him that the English term he wanted was "semaphore". If he had used Wikipedia instead of his Portuguese-English dictionary, he wouldn't have made that mistake.

PS
Originally Posted by geekStar
-what is interrupt and how can I get interrupt each (1,5 or any number) second
Interrupts are a very low-level concept that is almost more hardware than software. They are an integral part of the CPU (central processing unit, which now-a-days is referred to as the µP, "micro-processor").

Basically, stuff happens that the hardware needs to respond to when it happens. Typically, circuitry attached to other hardware devices will place a level or a pulse on certain input pins of the µP, which will trigger the interrupt. The µP will allow the current instruction to complete, whereupon it will save its current state (completely different from a state machine) and jump to a specified memory location to start executing the code residing there. That code that it jumps to is the Interrupt Service Routine (ISR). Each interrupt line has a different ISR associated with it; each ISR address is called an interrupt vector and it is common for these interrupt vectors to be stored together in an Interrupt Vector Table (IVT). From my experience (Intel), the location of that IVT is fixed by hardware (ie, by the µP design) and the location of each interrupt line's vector is also fixed by hardware (ie, by the µP design). In addition to the hardware interrupt lines, there can be software interrupts; in systems programming under MS-DOS, you would access the various operating system and BIOS services via software interrupts.

In embedded programming, we can write the ISRs in C, though often a few lines of assembly are needed as well.

You will need to read up on the hardware platform that you are going to target to learn about its interrupt operations.

One interrupt that is provided by a µP would be a TIMER interrupt; some µPs provide more than one. You can set the timer interrupt to trigger at a set rate; you must read the µP hardware handbook for details of how to do that, also for information on all the other input and output pins, including the interrupt inputs (IRQ lines, for "interrupt request").

If you only have one timer interrupt, then set it for the fastest rate that you need and within the timer ISR maintain counters that will divide that rate down to the slower rates that you need. Eg, we have a 1 ms timer interrupt, so we maintain an millisecond counter that counts up to 1000 whereupon we reset that counter to 0 and also increment our seconds counter. Then the rest of our code can read either counter to get a seconds count (in our case, "system seconds", the length of time the system's been running) or the number of milliseconds into that second.
Last edited by dwise1_aol; November 6th, 2013 at 02:53 PM.
4. Originally Posted by geekStar
what is elapsed time
That is not a C programming question, that is plain English. Elapsed time = the amount of time that has passed (elapsed) since some reference start time.

Originally Posted by geekStar
- what is state machine
That is not a C programming question, it is a general software engineering or computer science term. A state-machine refers to a control flow structure where a program remains in some defined state until some event occurs that changes to another state. You could Google that term and get a more complete answer.

Originally Posted by geekStar
-what are Prescale, period register ,IDEL, ISR and TIMER and
Those are not C programming terms, they relate to specific hardware/microprocessor architecture.

Prescale = to divide a digital clock by some value. Google "prescaler".

Period Register = In a microcontroller timer, the register that stores the value that determines the period of a clock. So for example a timer fed with a 1MHz clock, with a period register set to 1000000, the timer period would be 1 second.

IDEL = I have no idea, but is probably specific to a particulat microcontroller. Are you sure it was not IDLE? Either way its meaning requires context, it is not itself specific enough.

ISR = Interrupt service routine. A software routine that is called on the occurance of a hardware (or in some cases software) interrupt.

TIMER = Guess what? It means "timer". In a microcontroller it refers to a hardware device that generates timing information and may be used to measure time periods or to generate clock signals or periodic interrupts. Often timers also have a "counter" function where they can be used to count events (rising and/or falling edges of some digital signal) essentially this is the same operation as a timer, but the input clock can be aperiodic and from an external source.

Originally Posted by geekStar
what do they do?
What I just said.
Originally Posted by geekStar
-what does 0x31 mean?
It is a number in hexadecinal (base 16). It is equal to 3 * 16 + 1 (49 decimal). Hexadecimal notation is used in computing and especially in embedded systems and systems level code because 1 hexadecimal digit corresponds to exactly 4 binary (base 2) digits (bits) but is easier and less error prone to read and enter than a string of 1's and 0's (which C does not support in any case). For example a 16-bit binary number is represented by just 4 hex digits. Most experienced systems-level and embedded systems developers easily tranlsate between hex digits an binary patters, which is useful for determining values for registers that contain bit-fields.

Originally Posted by geekStar
-how can I get DELAY
Since it appears that you are talking about microcontroller development, by using a TIMER.

Originally Posted by geekStar
-what is interrupt and how can I get interrupt each (1,5 or any number) second
An interrupt is a signal that causes an ISR to execute. On completion of the ISR instruction execution returns to the point at which the interruption occurred. Again Google or Wikipedia are your friends here - you'd do better to do your own research that actually ask as question and wait for a possibly unhelpful and inaccurate answer.

If you want a periodic interrupt, use a TIMER, a timer can generate a periodic interrupt.

Given the nature of your questions, I imagine that I have used terms in this answer that you have not understood either, but I urge you to undertake research via more effective resources that forums before asking about them.
5. Originally Posted by b49P23TIvg
Interrupts would be quite hardware dependent, usually at an assembly language coding level (yes of course we can handle it in c, but not usually)
I beg to differ, I have not written an ISR in assembler for at least 20 years of full time embedded systems development (last time was on an 8051 microcontroller). These days in fact I write them in C++. Moreover ARM Cortex-M devices can vector directly into C or C++ generated code with zero assembler wrapper code, and with no special compiler extensions.
6. Originally Posted by b49P23TIvg
DELAY: once again, in c you'll use a library call that abstracts the hardware.
Except in those cases where the hardware abstraction is the responsibility of the developer, as in most bare-metal microcontroller development. The chip vendor may provide driver level source code for on chip peripherals, including timer hardware from which you might implement a delay.