Pages: [1]   Go Down
Author Topic: Need advice on programming articles  (Read 458 times)
0 Members and 1 Guest are viewing this topic.
Ireland
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 303
Posts: 26350
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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.
Logged

"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.

Ireland
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks AWOL.

Quote
Code:
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.
Logged

Pages: [1]   Go Up
Jump to: