Go Down

Topic: Need advice on programming articles (Read 487 times) previous topic - next topic

frodofski

Hi everyone,

I've been working with my Arduino for over two years now, at home and at college, and I feel I've gotten pretty good at programming. Because of this, I decided to write a few articles to help get newer Arduino programmers into some of the more advanced features of the Arduino and microcontrollers in general.

Here is my first article.

I have quite a list of things that I want to write about, so I was hoping I could get some feedback or advice on this article so I can write my future articles even better.

Thanks.

AWOL

Quote
Firstly the sensor value is read into the 'reading' variable. This could take up to a few hundred microseconds.

Except for the first reading, about 100 microseconds. (13 cycles of a 125kHz clock)
Not "a few hundred microseconds".
The first will take about 200 microseconds. (25 cycles of a 125kHz clock)

Quote
Next, the 'reading' variable is then sent via Serial comms to the computer. Depending on the baud rate, this could take up to a few milliseconds to complete.

Since about Arduino 1.0 the output is buffered, and will be sent out during the "delay()", so the completion time will be during the delay.

Code: [Select]
ISR(TIMER1_COMPA_vect) 
{
  // Code in here gets executed every time the counter
  // reaches, in this case, 6250 (every 100 ms)
  reading = analogRead(sensorPin);
}

IMO, an ISR is not the place to be doing an analogRead. Too slow.
Initiate a read in an ISR and interrupt again on completion, but don't sit in an ISR doing a busy-wait.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

frodofski

Thanks AWOL.

Quote

Code: [Select]

ISR(TIMER1_COMPA_vect) 
{
  // Code in here gets executed every time the counter
  // reaches, in this case, 6250 (every 100 ms)
  reading = analogRead(sensorPin);
}

IMO, an ISR is not the place to be doing an analogRead. Too slow.
Initiate a read in an ISR and interrupt again on completion, but don't sit in an ISR doing a busy-wait.

Yeah I see what you mean. I was trying to keep things simple by just using the analogRead function, but what you said would be much better.

Go Up