„UT.6.01” változatai közötti eltérés
510. sor: | 510. sor: | ||
P-V-I-R cheat sheet (Ohms/Watts law)<br /> | P-V-I-R cheat sheet (Ohms/Watts law)<br /> | ||
Calculate any of P, V, I, R from 2 known values:<br /> | Calculate any of P, V, I, R from 2 known values:<br /> | ||
[[Fájl:Ohms-watts law.jpg|keretezett|bal|Ohms-watts_law.jpg]] | [[Fájl:Ohms-watts law.jpg|keretezett|bal|Ohms-watts_law.jpg]]<br /> | ||
<hr> | |||
V=R∗I=PI=√P∗R | V=R∗I=PI=√P∗R | ||
A lap 2014. május 18., 14:02-kori változata
UT.6.01x
Az UT.6.01x egy online kurzus, ami a Tiva C lauchpad-ről és a beágyazott rendszerekről szól.
A kurzust Jonathan Valvano és Ramesh Yerraballi tartja.
Ezen az oldalon a kurzusból idézett szöveg kiemelések, táblázatok és képek vannak, ezeket használom jegyzetnek.
C1 Bevezetés
Folyamatosan gyűjtöm az anyagokat és fordítom, ahogy lehet
C2 Alap fogalmak
Bináris számok és rendszerek
Hexadecimális számok
Hex Digit |
Decimal Value |
Binary Value |
0 |
0 |
0000 |
1 |
1 |
0001 |
2 |
2 |
0010 |
3 |
3 |
0011 |
4 |
4 |
0100 |
5 |
5 |
0101 |
6 |
6 |
0110 |
7 |
7 |
0111 |
8 |
8 |
1000 |
9 |
9 |
1001 |
A or a |
10 |
1010 |
B or b |
11 |
1011 |
C or c |
12 |
1100 |
D or d |
13 |
1101 |
E or e |
14 |
1110 |
F or f |
15 |
1111 |
Beágyazott rendszerek
Processzor típusok: x86 (ált. asztali gép), ARM.
"Az I/O az a ragasztó, amivel a processzor kapcsolódik a világhoz."
Tervezési szempontok: tesztelhetőség, haszon, energia igény, méret, megfelelő válasz megfelelő időben.
Human-computer interface (HCI) or man-machine interface (MMI).
Tipikus példa: multiméter.
Bevezetés a számítógépekhez
Neumann architecture
Számítógép = proceszor + RAM + ROM + IO.
Neumann architecture,
"A port is a physical connection between the computer and its outside world. Ports allow information to enter and exit the system."
"A bus is a collection of wires used to pass information between modules."
A busz vezetékek gyűjteménye, amit a modulok közti információ cserére használunk.
Harvard architecture
ARM®Cortex™-M processor. "separate data and instruction buses"
Külön adat, és utasítás buszok.
"The nested vectored interrupt controller (NVIC) manages interrupts, which are hardware-triggered software functions. "
A beágyazott irányítható megszakítás-vezérlő - NVIC
Fogalmak
A microprocessor is a small processor.
A microcomputer is a small computer that includes a processor, memory and I/O devices.
A microcontroller is a single chip computer.
RAM-ROM memory
RAM (random access memory)
ROM (read only memory)
ROM-ok:
Static RAM (SRAM)
Programmable ROM (PROM) 10000 times slower RAM
Electrically erasable programmable ROM (EEPROM)
"In regular EEPROM, you can erase and program individual bytes. "
FLASH ROM
"Flash ROM is a popular type of EEPROM. Each flash bit requires only two MOSFET transistors. The input (gate) of one transistor is electrically isolated, so if we trap charge on this input, it will remain there for years."
"Each flash bit requires only two MOSFET transistors The input (gate) of one transistor is electrically isolated, so if we trap charge on this input, it will remain there for years. The other transistor is used to read the bit by sensing whether or not the other transistor has trapped charge."
"Flash ROM must be erased in large blocks. On many of Stellaris family of microcontrollers, we can erase the entire ROM or just a 1024-byte block."
"Because flash is smaller than regular EEPROM, most microcontrollers have a large flash into which we store the software. For all the systems in this class, we will store instructions and constants in flash ROM and place variables and temporary data in static RAM."
"Flash ROM is higher density because it requires few transistors compared to RAM."
IO portok
CPU regiszterek
Memory Map Layout
Part number |
RAM |
Flash |
I/O |
I/O modules |
LM3S811 |
8 |
64 |
32 |
PWM |
LM3S1968 |
64 |
256 |
52 |
PWM |
LM3S2965 |
64 |
256 |
56 |
PWM, CAN |
LM3S3748 |
64 |
128 |
61 |
PWM, DMA, USB |
LM3S6965 |
64 |
256 |
42 |
PWM, Ethernet |
LM3S8962 |
64 |
256 |
42 |
PWM, CAN, Ethernet, IEEE1588 |
LM4F110B2QR |
12 |
32 |
43 |
floating point, CAN, DMA |
LM4F120H5QR |
32 |
256 |
43 |
floating point, CAN, DMA, USB |
TM4C123GH6PM |
32 |
256 |
43 |
floating point, CAN, DMA, USB, PWM |
|
KiB |
KiB |
pins |
|
ISA Instruction set architecture
Software
CortexM_InstructionSet.pdf Instruction Set Reference Manual https://courses.edx.org/c4x/UTAustinX/UT.6.01x/asset/CortexM_InstructionSet.pdf
CortexM4_TRM_r0p1.pdf Cortex-M4 Technical Reference Manual https://courses.edx.org/c4x/UTAustinX/UT.6.01x/asset/CortexM_InstructionSet.pdf
LaunchPadUsersManual.pdf LaunchPad Manual
tm4c123gh6pm.pdf Data Sheet for the TM4C123 microcontroller
C3 Elektronikai alapismeretek
Ohm törvény
R = V / I I = V / R
R = V / I
P = V * I Power = Voltage * Current
P = V2 / R Power = Voltage2 / Resistance P = I2 * R Power = Current2 * Resistance
https://6002x.mitx.mit.edu/wiki/view/P-V-I-RcheatsheetOhmsWattslaw/
P-V-I-R cheat sheet (Ohms/Watts law)
Calculate any of P, V, I, R from 2 known values:
V=R∗I=PI=√P∗R
R=VI=V2P=PI2
I=VR=PV=√PR
P=V∗I=R∗I2=V2R
Energia
Elemekre:
E (energia)= V (feszültség) * I (áramerősség) * time (idő)
E-> állandó ; V -> állandó, az idő vagy az I csökkentésével csökkenthetjük a felhasznált energiát.
C4 Digitális logikai műveletek
D Logikai műveletek
A |
B |
AND |
NAND |
OR |
NOR |
EOR |
Ex NOR |
0 |
0 |
0 |
1 |
0 |
1 |
0 |
1 |
0 |
1 |
0 |
1 |
1 |
0 |
1 |
0 |
1 |
0 |
0 |
1 |
1 |
0 |
1 |
0 |
1 |
1 |
1 |
0 |
1 |
0 |
0 |
1 |
Symbol |
A&B |
~(A&B) |
A|B |
~(A|B) |
A^B |
~(A^B) |
Boolean Algebra
A & B = B & A |
Commutative Law |
Large numbers reference
Value |
SI Decimal |
SI Decimal |
|
Value |
IEC Binary |
IEC Binary |
10001 |
k |
kilo- |
|
10241 |
Ki |
kibi- |
10002 |
M |
mega- |
|
10242 |
Mi |
mebi- |
10003 |
G |
giga- |
|
10243 |
Gi |
gibi- |
10004 |
T |
tera- |
|
10244 |
Ti |
tebi- |
10005 |
P |
peta- |
|
10245 |
Pi |
pebi- |
10006 |
E |
exa- |
|
10246 |
Ei |
exbi- |
10007 |
Z |
zetta- |
|
10247 |
Zi |
zebi- |
10008 |
Y |
yotta- |
|
10248 |
Yi |
yobi- |
C4 Beveztés a C-be
Háttér
A C nagyon népszerű nyelv (2013-ban a programok 18%), több programot írnak C-ben mint Javaban, PHP-ben, Python-ban vagy Perl-ben.
Szintén nagyon népszerű még Objective-C és a C++ is.
A C nagyon vas közeli, a beágyazott rendszerek pedig az I/O-kra (GPIO-kra) épülnek.
A C felépítése
Punctuation |
Meaning |
; |
End of statement |
: |
Defines a label |
, |
Separates elements of a list |
( ) |
Start and end of a parameter list |
{ } |
Start and stop of a compound statement |
[ ] |
Start and stop of a array index |
" " |
Start and stop of a string |
' ' |
Start and stop of a character constant |
Változók (variables)
Data type |
Precision |
Range |
unsigned char |
8-bit unsigned |
0 to +255 |
signed char |
8-bit signed |
-128 to +127 |
unsigned int |
compiler-dependent |
|
int |
compiler-dependent |
|
unsigned short |
16-bit unsigned |
0 to +65535 |
short |
16-bit signed |
-32768 to +32767 |
unsigned long |
unsigned 32-bit |
0 to 4294967295L |
long |
signed 32-bit |
-2147483648L to 2147483647L |
float |
32-bit float |
±10-38 to ±10+38 |
double |
64-bit float |
±10-308 to ±10+308 |
Műveletek, operátorok
Operation |
Meaning |
|
Operation |
Meaning |
= |
Assignment statement |
|
== |
Equal to comparison |
? |
Selection |
|
<= |
Less than or equal to |
< |
Less than |
|
>= |
Greater than or equal to |
> |
Greater than |
|
!= |
Not equal to |
! |
Logical not (true to false, false to true) |
|
<< |
Shift left |
~ |
1’s complement |
|
>> |
Shift right |
+ |
Addition |
|
++ |
Increment |
- |
Subtraction |
|
-- |
Decrement |
* |
Multiply or pointer reference |
|
&& |
Boolean and |
/ |
Divide |
|
|| |
Boolean or |
% |
Modulo, division remainder |
|
+= |
Add value to |
| |
Logical or |
|
-= |
Subtract value to |
& |
Logical and, or address of |
|
*= |
Multiply value to |
^ |
Logical exclusive or |
|
/= |
Divide value to |
. |
Used to access parts of a structure |
|
|= |
Or value to |
|
|
|
&= |
And value to |
|
|
|
^= |
Exclusive or value to |
|
|
|
<<= |
Shift value left |
|
|
|
>>= |
Shift value right |
|
|
|
%= |
Modulo divide value to |
|
|
|
-> |
Pointer to a structure |
Precedence |
Operators |
Associativity |
Highest |
() []. -> ++(postfix) --(postfix) |
Left to right |
|
++(prefix) --(prefix) ! ~ sizeof(type) +(unary) -(unary) &(address) *(dereference) |
Right to left |
|
* / % |
Left to right |
|
+ - |
Left to right |
|
<< >> |
Left to right |
|
< <= > >= |
Left to right |
|
== != |
Left to right |
|
& |
Left to right |
|
^ |
Left to right |
|
| |
Left to right |
|
&& |
Left to right |
|
|| |
Left to right |
|
? : |
Right to left |
|
= += -= *= /= %= <<= >>= |= &= ^= |
Right to left |
Lowest |
, |
Left to right |
Kulcsszavak
Keyword |
Meaning |
__asm |
Specify a function is written in assembly code (specific to ARM Keil™ uVision®) |
auto |
Specifies a variable as automatic (created on the stack) |
break |
Causes the program control structure to finish |
case |
One possibility within a switch statement |
char |
Defines a number with a precision of 8 bits |
const |
Defines parameter as constant in ROM, and defines a local parameter as fixed value |
continue |
Causes the program to go to beginning of loop |
default |
Used in switch statement for all other cases |
do |
Used for creating program loops |
double |
Specifies variable as double precision floating point |
else |
Alternative part of a conditional |
extern |
Defined in another module |
float |
Specifies variable as single precision floating point |
for |
Used for creating program loops |
goto |
Causes program to jump to specified location |
if |
Conditional control structure |
int |
Defines a number with a precision that will vary from compiler to compiler |
long |
Defines a number with a precision of 32 bits |
register |
Specifies how to implement a local |
return |
Leave function |
short |
Defines a number with a precision of 16 bits |
signed |
Specifies variable as signed (default) |
sizeof |
Built-in function returns the size of an object |
static |
Stored permanently in memory, accessed locally |
struct |
Used for creating data structures |
switch |
Complex conditional control structure |
typedef |
Used to create new data types |
unsigned |
Always greater than or equal to zero |
void |
Used in parameter list to mean no parameter |
volatile |
Can change implicitly outside the direct action of the software. |
while |
Used for creating program loops |
C6 Prortok
I/O Signals
UART Universal asynchronous receiver/transmitter SSI Synchronous serial interface I2C Inter-integrated circuit Timer Periodic interrupts, input capture, and output compare PWM Pulse width modulation ADC Analog to digital converter, measure analog signals Analog Comparator Compare two analog signals QEI Quadrature encoder interface USB Universal serial bus Ethernet High-speed network CAN Controller area network JTAG Joint Test Action Group
"Common Error: Even though it is possible to use the five JTAG pins as general I/O, debugging most microcontroller boards will be more stable if these five pins are left dedicated to the JTAG debugger."
A JTAG tüskéket soha nem szabad általános I/O -ként használni, mert ezeken történik a debugg.
I/O Pins
IO |
Ain |
0 |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
14 |
PA0 |
|
Port |
U0Rx |
|
|
|
|
|
|
CAN1Rx |
|
|
PA1 |
|
Port |
U0Tx |
|
|
|
|
|
|
CAN1Tx |
|
|
PA2 |
|
Port |
|
SSI0Clk |
|
|
|
|
|
|
|
|
PA3 |
|
Port |
|
SSI0Fss |
|
|
|
|
|
|
|
|
PA4 |
|
Port |
|
SSI0Rx |
|
|
|
|
|
|
|
|
PA5 |
|
Port |
|
SSI0Tx |
|
|
|
|
|
|
|
|
PA6 |
|
Port |
|
|
I2C1SCL |
|
M1PWM2 |
|
|
|
|
|
PA7 |
|
Port |
|
|
I2C1SDA |
|
M1PWM3 |
|
|
|
|
|
PB0 |
|
Port |
U1Rx |
|
|
|
|
|
T2CCP0 |
|
|
|
PB1 |
|
Port |
U1Tx |
|
|
|
|
|
T2CCP1 |
|
|
|
PB2 |
|
Port |
|
|
I2C0SCL |
|
|
|
T3CCP0 |
|
|
|
PB3 |
|
Port |
|
|
I2C0SDA |
|
|
|
T3CCP1 |
|
|
|
PB4 |
Ain10 |
Port |
|
SSI2Clk |
|
M0PWM2 |
|
|
T1CCP0 |
CAN0Rx |
|
|
PB5 |
Ain11 |
Port |
|
SSI2Fss |
|
M0PWM3 |
|
|
T1CCP1 |
CAN0Tx |
|
|
PB6 |
|
Port |
|
SSI2Rx |
|
M0PWM0 |
|
|
T0CCP0 |
|
|
|
PB7 |
|
Port |
|
SSI2Tx |
|
M0PWM1 |
|
|
T0CCP1 |
|
|
|
PC4 |
C1- |
Port |
U4Rx |
U1Rx |
|
M0PWM6 |
|
IDX1 |
WT0CCP0 |
U1RTS |
|
|
PC5 |
C1+ |
Port |
U4Tx |
U1Tx |
|
M0PWM7 |
|
PhA1 |
WT0CCP1 |
U1CTS |
|
|
PC6 |
C0+ |
Port |
U3Rx |
|
|
|
|
PhB1 |
WT1CCP0 |
USB0epen |
|
|
PC7 |
C0- |
Port |
U3Tx |
|
|
|
|
|
WT1CCP1 |
USB0pflt |
|
|
PD0 |
Ain7 |
Port |
SSI3Clk |
SSI1Clk |
I2C3SCL |
M0PWM6 |
M1PWM0 |
|
WT2CCP0 |
|
|
|
PD1 |
Ain6 |
Port |
SSI3Fss |
SSI1Fss |
I2C3SDA |
M0PWM7 |
M1PWM1 |
|
WT2CCP1 |
|
|
|
PD2 |
Ain5 |
Port |
SSI3Rx |
SSI1Rx |
|
M0Fault0 |
|
|
WT3CCP0 |
USB0epen |
|
|
PD3 |
Ain4 |
Port |
SSI3Tx |
SSI1Tx |
|
|
|
IDX0 |
WT3CCP1 |
USB0pflt |
|
|
PD4 |
USB0DM |
Port |
U6Rx |
|
|
|
|
|
WT4CCP0 |
|
|
|
PD5 |
USB0DP |
Port |
U6Tx |
|
|
|
|
|
WT4CCP1 |
|
|
|
PD6 |
|
Port |
U2Rx |
|
|
M0Fault0 |
|
PhA0 |
WT5CCP0 |
|
|
|
PD7 |
|
Port |
U2Tx |
|
|
|
|
PhB0 |
WT5CCP1 |
NMI |
|
|
PE0 |
Ain3 |
Port |
U7Rx |
|
|
|
|
|
|
|
|
|
PE1 |
Ain2 |
Port |
U7Tx |
|
|
|
|
|
|
|
|
|
PE2 |
Ain1 |
Port |
|
|
|
|
|
|
|
|
|
|
PE3 |
Ain0 |
Port |
|
|
|
|
|
|
|
|
|
|
PE4 |
Ain9 |
Port |
U5Rx |
|
I2C2SCL |
M0PWM4 |
M1PWM2 |
|
|
CAN0Rx |
|
|
PE5 |
Ain8 |
Port |
U5Tx |
|
I2C2SDA |
M0PWM5 |
M1PWM3 |
|
|
CAN0Tx |
|
|
PF0 |
|
Port |
U1RTS |
SSI1Rx |
CAN0Rx |
|
M1PWM4 |
PhA0 |
T0CCP0 |
NMI |
C0o |
|
PF1 |
|
Port |
U1CTS |
SSI1Tx |
|
|
M1PWM5 |
PhB0 |
T0CCP1 |
|
C1o |
TRD1 |
PF2 |
|
Port |
|
SSI1Clk |
|
M0Fault0 |
M1PWM6 |
|
T1CCP0 |
|
|
TRD0 |
PF3 |
|
Port |
|
SSI1Fss |
CAN0Tx |
|
M1PWM7 |
|
T1CCP1 |
|
|
TRCLK |
PF4 |
|
Port |
|
|
|
|
M1Fault0 |
IDX0 |
T2CCP0 |
USB0epen |
|
|
I/O Registers
"A DIR bit of 0 means input and 1 means output."
"Common Error: You will get a bus fault if you access a port without enabling its clock."
- DIR 0 means input and 1 means output
- PCTL select regular digital function.
- LOCK unlock the port; Only PC3-0, PD7, and PF0 on the TM4C need to be unlocked
- AMSEL analog functionality
- AFSEL alternative function
- PUR internal pull-up resistor
Registers
Address |
7 |
6 |
5 |
4 |
3 |
2 |
1 |
0 |
Name |
$400F.E108 |
-- |
-- |
GPIOF |
GPIOE |
GPIOD |
GPIOC |
GPIOB |
GPIOA |
SYSCTL_RCGC2_R |
$4000.43FC |
DATA |
DATA |
DATA |
DATA |
DATA |
DATA |
DATA |
DATA |
GPIO_PORTA_DATA_R |
$4000.4400 |
DIR |
DIR |
DIR |
DIR |
DIR |
DIR |
DIR |
DIR |
GPIO_PORTA_DIR_R |
$4000.4420 |
SEL |
SEL |
SEL |
SEL |
SEL |
SEL |
SEL |
SEL |
GPIO_PORTA_AFSEL_R |
$4000.4510 |
PUE |
PUE |
PUE |
PUE |
PUE |
PUE |
PUE |
PUE |
GPIO_PORTA_PUR_R |
$4000.451C |
DEN |
DEN |
DEN |
DEN |
DEN |
DEN |
DEN |
DEN |
GPIO_PORTA_DEN_R |
$4000.4524 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
GPIO_PORTA_CR_R |
$4000.4528 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
GPIO_PORTA_AMSEL_R |
$4000.53FC |
DATA |
DATA |
DATA |
DATA |
DATA |
DATA |
DATA |
DATA |
GPIO_PORTB_DATA_R |
$4000.5400 |
DIR |
DIR |
DIR |
DIR |
DIR |
DIR |
DIR |
DIR |
GPIO_PORTB_DIR_R |
$4000.5420 |
SEL |
SEL |
SEL |
SEL |
SEL |
SEL |
SEL |
SEL |
GPIO_PORTB_AFSEL_R |
$4000.5510 |
PUE |
PUE |
PUE |
PUE |
PUE |
PUE |
PUE |
PUE |
GPIO_PORTB_PUR_R |
$4000.551C |
DEN |
DEN |
DEN |
DEN |
DEN |
DEN |
DEN |
DEN |
GPIO_PORTB_DEN_R |
$4000.5524 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
GPIO_PORTB_CR_R |
$4000.5528 |
0 |
0 |
AMSEL |
AMSEL |
0 |
0 |
0 |
0 |
GPIO_PORTB_AMSEL_R |
$4000.63FC |
DATA |
DATA |
DATA |
DATA |
JTAG |
JTAG |
JTAG |
JTAG |
GPIO_PORTC_DATA_R |
$4000.6400 |
DIR |
DIR |
DIR |
DIR |
JTAG |
JTAG |
JTAG |
JTAG |
GPIO_PORTC_DIR_R |
$4000.6420 |
SEL |
SEL |
SEL |
SEL |
JTAG |
JTAG |
JTAG |
JTAG |
GPIO_PORTC_AFSEL_R |
$4000.6510 |
PUE |
PUE |
PUE |
PUE |
JTAG |
JTAG |
JTAG |
JTAG |
GPIO_PORTC_PUR_R |
$4000.651C |
DEN |
DEN |
DEN |
DEN |
JTAG |
JTAG |
JTAG |
JTAG |
GPIO_PORTC_DEN_R |
$4000.6524 |
1 |
1 |
1 |
1 |
JTAG |
JTAG |
JTAG |
JTAG |
GPIO_PORTC_CR_R |
$4000.6528 |
AMSEL |
AMSEL |
AMSEL |
AMSEL |
JTAG |
JTAG |
JTAG |
JTAG |
GPIO_PORTC_AMSEL_R |
$4000.73FC |
DATA |
DATA |
DATA |
DATA |
DATA |
DATA |
DATA |
DATA |
GPIO_PORTD_DATA_R |
$4000.7400 |
DIR |
DIR |
DIR |
DIR |
DIR |
DIR |
DIR |
DIR |
GPIO_PORTD_DIR_R |
$4000.7420 |
SEL |
SEL |
SEL |
SEL |
SEL |
SEL |
SEL |
SEL |
GPIO_PORTD_AFSEL_R |
$4000.7510 |
PUE |
PUE |
PUE |
PUE |
PUE |
PUE |
PUE |
PUE |
GPIO_PORTD_PUR_R |
$4000.751C |
DEN |
DEN |
DEN |
DEN |
DEN |
DEN |
DEN |
DEN |
GPIO_PORTD_DEN_R |
$4000.7524 |
CR |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
GPIO_PORTD_CR_R |
$4000.7528 |
0 |
0 |
AMSEL |
AMSEL |
AMSEL |
AMSEL |
AMSEL |
AMSEL |
GPIO_PORTD_AMSEL_R |
$4002.43FC |
|
|
DATA |
DATA |
DATA |
DATA |
DATA |
DATA |
GPIO_PORTE_DATA_R |
$4002.4400 |
|
|
DIR |
DIR |
DIR |
DIR |
DIR |
DIR |
GPIO_PORTE_DIR_R |
$4002.4420 |
|
|
SEL |
SEL |
SEL |
SEL |
SEL |
SEL |
GPIO_PORTE_AFSEL_R |
$4002.4510 |
|
|
PUE |
PUE |
PUE |
PUE |
PUE |
PUE |
GPIO_PORTE_PUR_R |
$4002.451C |
|
|
DEN |
DEN |
DEN |
DEN |
DEN |
DEN |
GPIO_PORTE_DEN_R |
$4002.4524 |
|
|
1 |
1 |
1 |
1 |
1 |
1 |
GPIO_PORTE_CR_R |
$4002.4528 |
|
|
AMSEL |
AMSEL |
AMSEL |
AMSEL |
AMSEL |
AMSEL |
GPIO_PORTE_AMSEL_R |
$4002.53FC |
|
|
|
DATA |
DATA |
DATA |
DATA |
DATA |
GPIO_PORTF_DATA_R |
$4002.5400 |
|
|
|
DIR |
DIR |
DIR |
DIR |
DIR |
GPIO_PORTF_DIR_R |
$4002.5420 |
|
|
|
SEL |
SEL |
SEL |
SEL |
SEL |
GPIO_PORTF_AFSEL_R |
$4002.5510 |
|
|
|
PUE |
PUE |
PUE |
PUE |
PUE |
GPIO_PORTF_PUR_R |
$4002.551C |
|
|
|
DEN |
DEN |
DEN |
DEN |
DEN |
GPIO_PORTF_DEN_R |
$4002.5524 |
|
|
|
1 |
1 |
1 |
1 |
CR |
GPIO_PORTF_CR_R |
$4002.5528 |
|
|
|
0 |
0 |
0 |
0 |
0 |
GPIO_PORTF_AMSEL_R |
|
|
|
|
|
|
|
|
|
|
|
31-28 |
27-24 |
23-20 |
19-16 |
15-12 |
11-8 |
7-4 |
3-0 |
|
$4000.452C |
PMC7 |
PMC6 |
PMC5 |
PMC4 |
PMC3 |
PMC2 |
PMC1 |
PMC0 |
GPIO_PORTA_PCTL_R |
$4000.552C |
PMC7 |
PMC6 |
PMC5 |
PMC4 |
PMC3 |
PMC2 |
PMC1 |
PMC0 |
GPIO_PORTB_PCTL_R |
$4000.652C |
PMC7 |
PMC6 |
PMC5 |
PMC4 |
0x1 |
0x1 |
0x1 |
0x1 |
GPIO_PORTC_PCTL_R |
$4000.752C |
PMC7 |
PMC6 |
PMC5 |
PMC4 |
PMC3 |
PMC2 |
PMC1 |
PMC0 |
GPIO_PORTD_PCTL_R |
$4002.452C |
|
|
PMC5 |
PMC4 |
PMC3 |
PMC2 |
PMC1 |
PMC0 |
GPIO_PORTE_PCTL_R |
$4002.552C |
|
|
|
PMC4 |
PMC3 |
PMC2 |
PMC1 |
PMC0 |
GPIO_PORTF_PCTL_R |
$4000.6520 |
LOCK (write 0x4C4F434B to unlock, other locks) (reads 1 if locked, 0 if unlocked) |
GPIO_PORTC_LOCK_R |
|||||||
$4000.7520 |
LOCK (write 0x4C4F434B to unlock, other locks) (reads 1 if locked, 0 if unlocked) |
GPIO_PORTD_LOCK_R |
|||||||
$4002.5520 |
LOCK (write 0x4C4F434B to unlock, other locks) (reads 1 if locked, 0 if unlocked) |
GPIO_PORTF_LOCK_R |
Regiszter programozás
Maszkolás writing friendly code
* OR művelettel egy bitet BE kapcsolhatunk; ahova 1-et írunk 1 lesz; ahova 0-t ott nem változik * AND művelettel egy bitet LE kapcsolhatunk; ahova 0-t írunk 0 lesz; ahova 1-t ott nem változik
* Egyszerűbb annak a bitnek amit le akarunk kapcsolni, az ellentettjét (~) maszkolni AND művelettel. (&)
* Ha le akarok olvasni egy bitet egy regiszterből, & -em a bit helyét.
Gyakori maszkolási értékek
If we wish to access bit |
Constant |
7 |
0x0200 |
6 |
0x0100 |
5 |
0x0080 |
4 |
0x0040 |
3 |
0x0020 |
2 |
0x0010 |
1 |
0x0008 |
0 |
0x0004 |
Port címzések
Port | Base address |
PortA | 0x40004000 |
PortB | 0x40005000 |
PortC | 0x40006000 |
PortD | 0x40007000 |
PortE | 0x400240000 |
PortF | 0x40025000 |
C7 Tervezési és fejlesztési folyamat
Termék életciklusai
- Probléma meghatározása
- Tervezés
- Fejlesztés
- Tesztelés
- Üzembe helyezés
Tervezési kritériumok
- Safety: The risk to humans or the environment
- Accuracy: The difference between the expected truth and the actual parameter
- Precision: The number of distinguishable measurements
- Resolution: The smallest change that can be reliably detected
- Response time: The time between a triggering event and the resulting action
- Bandwidth: The amount of information processed per time
- Maintainability: The flexibility with which the device can be modified
- Testability: The ease with which proper operation of the device can be verified
- Compatibility: The conformance of the device to existing standards
- Mean time between failure: The reliability of the device, the life of a product
- Size and weight: The physical space required by the system
- Power: The amount of energy it takes to operate the system
- Nonrecurring engineering cost (NRE cost): The one-time cost to design and test
- Unit cost: The cost required to manufacture one additional product
- Time-to-prototype: The time required to design, build, and test an example system
- Time-to-market: The time required to deliver the product to the customer
- Human factors: The degree to which our customers like/appreciate the product
Tippek
"Common Error: Programmers who sacrifice clarity in favor of execution speed often develop software that runs fast, but is error-prone and difficult to change."
"Observation: The easiest way to debug is to write software without any bugs."
"Maintenance Tip: Go from working system to working system."
"Maintenance Tip: It is better to have some parts of the system that run with 100% reliability than to have the entire system with bugs."
"Maintenance Tip: It is better to have a system that runs slowly than to have one that doesn’t run at all."
"Observation:There are two ways of constructing a software design: one way is to make it so simple that there are obviously no deficiencies and the other way is make it so complicated that there are no obvious deficiencies. C.A.R. Hoare, "The Emperor's Old Clothes," CACM Feb. 1981."
Azaz kétféle képen tervezhetünk egy szoftvert: "Az egyik út hogy annyira egyszerű hogy nyilvánvalóan nincs benne hiba A másik lehetőség az, hogy olyan bonyolult hogy nincsenek egyértelmű hibák."
Funkciók, eljárások, módszerek, szubrutinok
Ezek kialakítására a a hiba megelőzést segíti.
- "Make the software project easier to understand"
- "Increase the number of modules"
- "Decrease the interdependency (minimize bandwidth between modules)."
Fontos hogy ne keverjük a különböző változókat!
C8 Switches and leds
Leds
Előtét ellenállás számítás:
- Positive logic: R = VOH-Vd / Id
- Negative logic: R = 3.3-Vd-VOL / Id
Positive logic: | Negative logic: |
---|---|
C9 Arrays & functional debugging
Debugging Theory
* Black-box testing: "is simply observing the inputs and outputs without looking inside." * White-box testing: "allows you to control and observe the internal workings of a system."
Common Error: "The most common debugging mistake new programmers make is to simply observe the overall inputs and outputs system without looking inside the device. Then they go to their professor and say, “My program gives incorrect output. Do you know why?”
SysTick timer
(nem telje, a systick órajel beállítása itt)
Address |
31-24 |
23-17 |
16 |
15-3 |
2 |
1 |
0 |
Name |
$E000E010 |
0 |
0 |
COUNT |
0 |
CLK_SRC |
INTEN |
ENABLE |
NVIC_ST_CTRL_R |
$E000E014 |
0 |
24-bit RELOAD value |
NVIC_ST_RELOAD_R |
|||||
$E000E018 |
0 |
24-bit CURRENT value of SysTick counter |
NVIC_ST_CURRENT_R |
Inicializálás
#define NVIC_ST_CTRL_R (*((volatile unsigned long *)0xE000E010)) #define NVIC_ST_RELOAD_R (*((volatile unsigned long *)0xE000E014)) #define NVIC_ST_CURRENT_R (*((volatile unsigned long *)0xE000E018)) void SysTick_Init(void){ NVIC_ST_CTRL_R = 0; // 1) disable SysTick during setup NVIC_ST_RELOAD_R = 0x00FFFFFF; // 2) maximum reload value NVIC_ST_CURRENT_R = 0; // 3) any write to current clears it NVIC_ST_CTRL_R = 0x00000005; // 4) enable SysTick with core clock }
Example
unsigned long Now; // 24-bit time at this call (12.5ns) unsigned long Last; // 24-bit time at previous call (12.5ns) unsigned long Elapsed; // 24-bit time between calls (12.5ns) void Action(void){ // function under test Now = NVIC_ST_CURRENT_R; // what time is it now? Elapsed = (Last-Now)&0x00FFFFFF; // 24-bit difference Last = Now; // set up for next... }
Arrays
String
A String egy karakter sorozat, maga szöveg.
Mindig 0-ra végződik, de ezt nem kell írni, fordításnál alapértelmezetten bekerül.
Speciális karakterk:
Character |
Escape Sequence |
alert (beep) |
\a |
backslash |
\\ |
backspace |
\b |
carriage return |
\r |
double quote |
\" |
form feed |
\f |
horizontal tab |
\t |
newline |
\n |
null character |
\0 |
single quote |
\' |
vertical tab |
\v |
question mark |
\? |
C10 Finite State Machine
Phase-Lock-Loop PLL
"internal oscillator is 16 MHz ±1%"
A LM4F/TM4C MCU-kban van egy belső oszcillátor ez 16 MHz ±1%. Az egy 1% nagyon nagy hibahatár, ezért kell egy külső kristály ami pontosabb.
A Tiva C launchpaden egy 16 MHz-es NX5032GA ±50 parts per million (PPM) kristály van. Az ±50 PPM 0.005% hibahatárt jelent "which is about ±5 seconds per day"
Más kristályt is használhatunk, az értékének megfelelően be kell állítani az SysTick XTAL regiszterét az alábbiak szerint:
'''XTAL''' |
Crystal Freq (MHz) |
|
'''XTAL''' |
Crystal Freq (MHz) |
0x0 |
Reserved |
|
0x10 |
10.0 MHz |
0x1 |
Reserved |
|
0x11 |
12.0 MHz |
0x2 |
Reserved |
|
0x12 |
12.288 MHz |
0x3 |
Reserved |
|
0x13 |
13.56 MHz |
0x4 |
3.579545 MHz |
|
0x14 |
14.31818 MHz |
0x5 |
3.6864 MHz |
|
0x15 |
16.0 MHz |
0x6 |
4 MHz |
|
0x16 |
16.384 MHz |
0x7 |
4.096 MHz |
|
0x17 |
18.0 MHz |
0x8 |
4.9152 MHz |
|
0x18 |
20.0 MHz |
0x9 |
5 MHz |
|
0x19 |
24.0 MHz |
0xA |
5.12 MHz |
|
0x1A |
25.0 MHz |
0xB |
6 MHz (reset value) |
|
0x1B |
Reserved |
0xC |
6.144 MHz |
|
0x1C |
Reserved |
0xD |
7.3728 MHz |
|
0x1D |
Reserved |
0xE |
8 MHz |
|
0x1E |
Reserved |
0xF |
8.192 MHz |
|
0x1F |
Reserved |
SysTick registers
Address |
26-23 |
22 |
13 |
11 |
10-6 |
5-4 |
Name |
$400FE060 |
SYSDIV |
USESYSDIV |
PWRDN |
BYPASS |
XTAL |
OSCSRC |
SYSCTL_RCC_R |
$400FE050 |
|
|
|
|
PLLRIS |
|
SYSCTL_RIS_R |
|
|
|
|
|
|
|
|
|
31 |
30 |
28-22 |
13 |
11 |
6-4 |
|
$400FE070 |
USERCC2 |
DIV400 |
SYSDIV2 |
PWRDN2 |
BYPASS2 |
OSCSRC2 |
SYSCTL_RCC2_R |
PLL init
void PLL_Init(void){ // 0) Use RCC2 SYSCTL_RCC2_R |= 0x80000000; // USERCC2 // 1) bypass PLL while initializing SYSCTL_RCC2_R |= 0x00000800; // BYPASS2, PLL bypass // 2) select the crystal value and oscillator source SYSCTL_RCC_R = (SYSCTL_RCC_R &~0x000007C0) // clear XTAL field, bits 10-6 + 0x00000540; // 10101, configure for 16 MHz crystal SYSCTL_RCC2_R &= ~0x00000070; // configure for main oscillator source // 3) activate PLL by clearing PWRDN SYSCTL_RCC2_R &= ~0x00002000; // 4) set the desired system divider SYSCTL_RCC2_R |= 0x40000000; // use 400 MHz PLL SYSCTL_RCC2_R = (SYSCTL_RCC2_R&~ 0x1FC00000) // clear system clock divider + (4<<22); // configure for 80 MHz clock // 5) wait for the PLL to lock by polling PLLLRIS while((SYSCTL_RIS_R&0x00000040)==0){}; // wait for PLLRIS bit // 6) enable use of PLL by clearing BYPASS SYSCTL_RCC2_R &= ~0x00000800; } //Program 10.1. Activate the LM4F/TM4C with a 16 MHz crystal to run at 80 MHz (C10_PLL.zip).
Delays; Useing SysTick
A busz 2 számolása közt, 80MHz-en, 12.5 ns telik el, ennek megfelelően: " The RELOAD register is set to the number of bus cycles one wishes to wait. If the PLL function of Program 10.1 has been executed, then the units of this delay will be 12.5 ns. Writing to CURRENT will clear the counter and will clear the count flag (bit 16) of the CTRL register. After SysTick has been decremented delay times, the count flag will be set and the while loop will terminate. Since SysTick is only 24 bits, the maximum time one can wait with SysTick_Wait is 224*12.5ns, which is about 200 ms. To provide for longer delays, the function SysTick_Wait10ms calls the function SysTick_Wait repeatedly. Notice that 800,000*12.5ns is 10ms."
Bomba biztos Delay-ek
#define NVIC_ST_CTRL_R (*((volatile unsigned long *)0xE000E010)) #define NVIC_ST_RELOAD_R (*((volatile unsigned long *)0xE000E014)) #define NVIC_ST_CURRENT_R (*((volatile unsigned long *)0xE000E018)) void SysTick_Init(void){ NVIC_ST_CTRL_R = 0; // disable SysTick during setup NVIC_ST_CTRL_R = 0x00000005; // enable SysTick with core clock } // The delay parameter is in units of the 80 MHz core clock. (12.5 ns) void SysTick_Wait(unsigned long delay){ NVIC_ST_RELOAD_R = delay-1; // number of counts to wait NVIC_ST_CURRENT_R = 0; // any value written to CURRENT clears while((NVIC_ST_CTRL_R&0x00010000)==0){ // wait for count flag } } // 800000*12.5ns equals 10ms void SysTick_Wait10ms(unsigned long delay){ unsigned long i; for(i=0; i<delay; i++){ SysTick_Wait(800000); // wait 10ms } } //Program 10.2. Use of SysTick to delay for a specified amount of time (C10_SysTick_Wait).
Struktúrák
//Meghatározzuk a strukturat: struct player{ unsigned char Xpos; // first element unsigned char Ypos; // second element unsigned short Score; // third element }; typedef struct player playerType;
//We can allocate a variable called Sprite of this type, which will occupy four bytes in RAM: //azaz lefoglaljuk a strukturánknak megfeleo Sprite, valtozoit a RAM-ban playerType Sprite;
//dolgozhatunk az ertekekkel Sprite.Xpos = 10; Sprite.Ypos = 20; Sprite.Score = 12000;
Finite State Machine FSM
- Set of Inputs
- Set of outputs
- Set of State
- State transitions: Graph (STG) or Matrix
- Output determination
Moore FSM:
A rendszerünk következő értékét, a mostani állapota és a bemenet határozza meg.
A rendsz.-ben a kiment aktuális értéke a mostani állapot.
Moore & Mealy FSM:
Figure 10.5. The output in a Moore depends just on the state. In a Mealy the output depends on state and input.
Example: traffic light controller
#define SENSOR (*((volatile unsigned long *)0x4002400C)) #define LIGHT (*((volatile unsigned long *)0x400050FC)) // Linked data structure struct State { unsigned long Out; unsigned long Time; unsigned long Next[4];}; typedef const struct State STyp; #define goN 0 #define waitN 1 #define goE 2 #define waitE 3 STyp FSM[4]={ {0x21,3000,{goN,waitN,goN,waitN}}, {0x22, 500,{goE,goE,goE,goE}}, {0x0C,3000,{goE,goE,waitE,waitE}}, {0x14, 500,{goN,goN,goN,goN}}}; unsigned long S; // index to the current state unsigned long Input; int main(void){ volatile unsigned long delay; PLL_Init(); // 80 MHz, Program 10.1 SysTick_Init(); // Program 10.2 SYSCTL_RCGC2_R |= 0x12; // 1) B E delay = SYSCTL_RCGC2_R; // 2) no need to unlock GPIO_PORTE_AMSEL_R &= ~0x03; // 3) disable analog function on PE1-0 GPIO_PORTE_PCTL_R &= ~0x000000FF; // 4) enable regular GPIO GPIO_PORTE_DIR_R &= ~0x03; // 5) inputs on PE1-0 GPIO_PORTE_AFSEL_R &= ~0x03; // 6) regular function on PE1-0 GPIO_PORTE_DEN_R |= 0x03; // 7) enable digital on PE1-0 GPIO_PORTB_AMSEL_R &= ~0x3F; // 3) disable analog function on PB5-0 GPIO_PORTB_PCTL_R &= ~0x00FFFFFF; // 4) enable regular GPIO GPIO_PORTB_DIR_R |= 0x3F; // 5) outputs on PB5-0 GPIO_PORTB_AFSEL_R &= ~0x3F; // 6) regular function on PB5-0 GPIO_PORTB_DEN_R |= 0x3F; // 7) enable digital on PB5-0 S = goN; while(1){ LIGHT = FSM[S].Out; // set lights SysTick_Wait10ms(FSM[S].Time); Input = SENSOR; // read sensors S = FSM[S].Next[Input]; } } //Program 10.4. Linked data structure implementation of the traffic light controller (C10_TableTrafficLight).