16-08-2012, 04:20 PM
The Silicon Laboratories C8051F020
(DAC-ADC)The Silicon Laboratories C8051F020.ppt (Size: 1.42 MB / Downloads: 34)
System Clocks
Internal clock oscillator
default at reset
2 MHz default frequency
configured by SFR OSCICN
External oscillator installed on board
22.1184 MHz
configured by SFR OSCXCN
Timers
Original 8051 has 2 Timers, T0 and T1
Can think of timers as binary counters
Clock is derived from system clock (frequency is configurable)
Timer registers can be read via mov instructions
Events (interrupts or flag bits set) occur when timers overflow (eg. count up from FF 00)
Can be used to create waveforms, measure time intervals, set frequency of events, etc.
Using Timers For Periodic EventsUsing Interrupts
Set mode to be timer, use appropriate clock and timer size
Set timer to interrupt on overflow
In Interrupt Service Routine
Do event
Reset interrupt flag
Reset timer to initial value (unless using auto-reload)
Return from interrupt
Using Timers to Measure Time
Using Timers:
Configure timers with mode 0 or 1 (13 or 16-bit timer) and desired system clock.
In main program, wait for initial event.
Start the timer.
Each time the timer overflows, a register should be incremented using an interrupt service routine.
When the second event occurs, disable the interrupts and the timer in the main program.