source: firmware/InterlockArduino/src/fact++interface/docu.tex@ 14247

Last change on this file since 14247 was 14236, checked in by neise, 13 years ago
fact++ arduino interface docu init
File size: 4.2 KB
Line 
1\title{FACT Arduino ethernet communication Interface }
2
3\section{Introduction}
4Arduino is the name of a series of open source
5microcontroller equipped boards. The
6microcontroller in use is out of Atmels ATmega family.
7
8The FACT telescope uses mostly the Arduino Ethernet board to
9monitor and control certain auxiliary systems like the motors of the camera
10shutter.
11
12This board was chosen since the needed hardware for ethernet access,
13like a dedicated ethernet controller (Wiznet W5100) and the jack, are already
14in place. In addition the programming of the board, in comparably easy.
15
16Setting up a TCP/IP server (using a fix IP or a DHCP server) as well as
17raw byte-stream communication with clients is handled by the Ethernet library,
18which comes with the Arduino IDE.
19
20There is a variety of open source extension boards available for the Arduino,
21both from the Arduino group as well as from unrelated developers. These
22extension boards are usually called shields.
23The shields can be connected to the ATmega port pins via 100mil headers,
24which can be used to connect custom peripherals as well.
25
26Typical ATmega digital outputs can drive up to 10mA at 5.0V and thus allow for
27quick connection of LEDs for software tests or similar quick hacks.
28
29There exists an open source C cross compiler for Atmega as well a std-lib
30implementation. The Arduino group created not only a user friendly
31(maybe not power user friendly) IDE but also supplies the beginner with a
32bunch of useful classes from serial communication to LCD interfacing.
33
34\subsection{std C vs. Arduino quasi C++}
35The Arduino IDE provides the beginner with a simple programming enviroment.
36While the usual microcontroller program comprises of an init section
37and a never ending while loop which contains the actual job of the microcontroller,
38e.g. like this:
39\begin{verbatim}
40void main (void){
41
42 // set up peripherals and I/O pins
43 // e.g:
44 DDRD |= 1<<PD6; // define pin PD6 to be an output
45
46 // herein the actual 'job' is performed
47 while(1){
48 // toggle the output
49 PORTD ^= 1<<PD6;
50 }
51}
52
53This would look like this in Arduino quasi C++:
54\begin{verbatim}
55// On the Arduino board there are numbers printed
56// next to the 100mil header sockets.
57// The ATmega pin PD6 is named '6' on the Arduino board.
58const int my_output_pin = 6;
59
60setup(){
61 pinMode( my_output_pin, OUTPUT);
62 boolean output_pin_state = false;
63}
64loop(){
65 // toggle the variable...
66 output_pin_state = !output_pin_state;
67 // write the value of the value, to the pin
68 digitalWrite( my_output_pin, output_pin_state);
69}
70\end{verbatim}
71
72In many cases, the code written in the Arduino-C++ dialect does not
73produce the optimal binary, but one can always fall back to standard C
74and even use both styles of writing in one and the same source file.
75
76\subsection{ scheduling on microcontrollers }
77There is nothing like a schedular running on a microcontroller, so one can not
78produce concurrent running code by using threads. The developer needs
79in such a case to implement a form of time sharing himself.
80
81Assume the following task:
82The ATmegas internal ADC should be used to measure a voltage as soon
83as an attached button is pressed. Since we expect some noise, the ADC should
84sample the voltage 100 times and return the mean and the std deviation.
85Since the user is expected to be slow, when pressing a button, 50 of the samples
86shoule be taken, before the user pressed the button.
87We assume the CPU frequency is 16MHz. And the serial communication to run at
889600 baud.
89
90The ADC needs about 130us for a conversion.
91
92
93(Although there might be libraries easing the pain a little out there.)
94The most prominent solution maybe looks like this
95\begin{verbatim}
96loop(){
97 check_if_a_button_was_pressed();
98 check_if_the_ADC_has_a_valid_reading();
99 calculate_something();
100 tell_the_world_about_it(); //9600 baud serial communication
101}
102In case each of the functions runs only a for little amount of time,
103say about 10ms. the user experience is, that the reaction on a pressed button
104is immediate. Assume the ADC needs multiples of about 50ms to get a valid reading,
105it is assured, that the ADC value is read out of the ADC reagister as soon as
106it is valid, and the
107
108\end{verbatim}
109
110
111\section{Usage}
112
113\section{Implementation}
114
115\section{Summary}
Note: See TracBrowser for help on using the repository browser.