PT 3
PT 3
Jason J. Gu
Department of Electrical and Computer Engineering
Dalhousie University
Clock signal
Time delays are dependent on accurate system clock
frequency
MCU includes complex circuitry that generates and
distributes clock signals to every peripheral module
Devices used to generate clock signal: ceramic
resonators, crystal oscillators, and RC circuits
Frequency division: using count down counter
Frequency multiplication: phase lock loop (PLL)
Note: No PORT I
// C code
DDRA = 0xFF; configure Port A for output
PORTA = 0x53; output the value of 0x53 to Port A
// C code
DDRA = 0x00; configure Port A for input
r20 = PINA; input the value from port A to r20
while(1)
{
PORTK = 0x00;
_delay_ms(500);
PORTK = 0xFF;
_delay_ms(500);
}
}
{0x79,0xDF,0x33,0xEF,0x5B,0xF7,0x5F,0xFB,0x70,0xFD,0x7F,0xFE},
{0x33,0xDF,0x5B,0xEF,0x5F,0xF7,0x70,0xFB,0x7F,0xFD,0x7B,0xFE},
{0x5B,0xDF,0x5F,0xEF,0x70,0xF7,0x7F,0xFB,0x7B,0xFD,0x7E,0xFE},
{0x5F,0xDF,0x70,0xEF,0x7F,0xF7,0x7B,0xFB,0x7E,0xFD,0x30,0xFE},
{0x70,0xDF,0x7F,0xEF,0x7B,0xF7,0x7E,0xFB,0x30,0xFD,0x6D,0xFE},
{0x7F,0xDF,0x7B,0xEF,0x7E,0xF7,0x30,0xFB,0x6D,0xFD,0x79,0xFE},
{0x7B,0xDF,0x7E,0xEF,0x30,0xF7,0x6D,0xFB,0x79,0xFD,0x33,0xFE},
{0x7E,0xDF,0x30,0xEF,0x6D,0xF7,0x79,0xFB,0x33,0xFD,0x5B,0xFE}
};
int main(void)
{
unsigned char k1, k2, k3;
setCPUClkto32Mwith16MCrystal();
PORTA_DIR = 0xFF; // configure Port A for output , PORTA= 0xFF for MEGA
PORTB_DIR = 0xFF; // configure Port B for output to drive digit select
while(1) {
for(k1 = 0; k1 < ROWS; k1++)
for(k2 = 0; k2 < REPCNT; k2++)
for(k3 = 0; k3 < DIGITS; k3++) {
PORTA_OUT = segTable[k1][k3*2];
PORTB_OUT = segTable[k1][k3*2+1];
delayby1ms(1);
}
}
}
Vout=2*VREF*N/255
Figure 8.22 Circuit connection between the AD7302 and the Mega2560
Solution: To divide 360 into 50 points, then the sine waveform starts
from 0o to 352.8o and repeats. Since there is no negative value in the
sine waveform, we need to use the following equation to calculate
the voltage corresponding to xo:
Voltage= 5/2 * [sine(x) + 1]
To generate this voltage, we need to send the following value to the
DAC:
N = (sine x + 1) * 255 / 2
For example, we need to send 127 (or 128) to DAC to generate the
sine wave value at 0o.
; -------------------------------------------------------------------------------------------------------------------
; Values to generate the triangular and sine waves are stored alternately in the same
; table to simplify data access.
; -------------------------------------------------------------------------------------------------------------------
waveforms:
.db 0,128,10,143,20,159,31,174,41,189,51,202,61,215,71,226,82,235,92,243
.db 102,249,112,253,122,255,133,255,143,253,153,249,163,243,173,235
.db 184,226,194,215,204,202,214,189,224,174,235,159,245,143,255,128
.db 245,112,235,96,224,81,214,66,204,53,194,40,184,29,173,20,163,12,153,6
.db 143,2,133,0,122,0,112,2,102,6,92,12,82,20,71,29,61,40,51,53
.db 41,66,31,81,20,96,10,112
Start:
.org 0xF6
Code in Assembling,compiled
ldi tmp, low(RAMEND)
out SPL,tmp
ldi tmp, high(RAMEND)
out SPH, tmp
lds tmp,DDRD ; configure PD0/INT0, PD1/INT1 for input
andi tmp,0xFC
sts DDRD,tmp
ldi tmp, 0x0B
sts EICRA, tmp ; //INT0 on rising edge, INT1 on falling edge
ldi tmp,0x03 ; "
sts EIMSK,tmp ; // enable INT0,INT1
sei
again: jmp again ;// loop
INT0_Vect: nop
reti
} code in assembling??
Practice in
assignment
Clockwise full-
step rotation
Counterclock
wise full-step
rotation
(reverse the
polarities of
C3,C4)
Half-step operation:
rotor (in a four-pole
step) is moved to eight
discrete positions (45
degrees)
DMA registers
Control register (CTRL)
Status register (STATUS)
Interrupt flag register (INTFLAGS)
16-bit temporary register (TEMP): controls the
overall operation
DMA channel operation: supported by it own
set of registers
• Instructions
Clear display Set CGRAM address
Return home Set DDRAM address
Entry mode set Read busy flag and address
Cursor or display shift
Function set
Note: over 80
characters
refer to text