1.09k likes | 1.38k Views
The Silicon Laboratories C8051F020. Enhanced 8051. Overview. Timing – system clocks CPU Execution timing Software Delays Timers On-chip “external” RAM A/D and D/A Conversion Temperature Sensor Additional Timers and Interrupts. SFRs for Subsystems. Control registers:
E N D
The Silicon Laboratories C8051F020 Enhanced 8051 ECE/CS-352: Embedded Microcontroller Systems
Overview • Timing – system clocks • CPU Execution timing • Software Delays • Timers • On-chip “external” RAM • A/D and D/A Conversion • Temperature Sensor • Additional Timers and Interrupts ECE/CS-352: Embedded Microcontroller Systems
SFRs for Subsystems • Control registers: • XXXCN (WDTCN, ADC0CN, DAC0CN, TMR3CN) • Configuration registers: • XXXCF (ADC0CF, AMX0CF, EMI0CF) • Data registers for subsystems: • ADC0H, ADC0L, DAC0H, DAC0L • Many others..... ECE/CS-352: Embedded Microcontroller Systems
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 ECE/CS-352: Embedded Microcontroller Systems
Internal Osc ConfigurationOSCICN Missing clock detector enable Internal Osc. frequency ready Internal Osc. freq. control bits 00 – 2MHz 01 – 4 MHz 10 – 8 MHz 11 – 16 MHz system clock select 0 = internal 1 = external (internal by default) Default Sysclk f = 2 MHz T = 0.5 s Internal Osc. enable (enabled by default) ECE/CS-352: Embedded Microcontroller Systems
External Osc. ConfigurationOSCXCN • External Osc. freq. control bits • Depends on frequency range of operation External Osc. mode bits 00x: Off. XTAL1 pin is grounded internally. 010: System Clock from External CMOS Clock on XTAL1 pin. 011: System Clock from External CMOS Clock on XTAL1 pin divided by 2. 10x: RC/C Oscillator Mode with divide by 2 stage. 110: Crystal Oscillator Mode 111: Crystal Oscillator Mode with divide by 2 stage. Crystal Osc. valid flag ECE/CS-352: Embedded Microcontroller Systems
Development Board Oscillator ECE/CS-352: Embedded Microcontroller Systems
To use 22.1184 MHz external oscillator 110: Crystal Oscillator Mode 111: f > 6.7 MHz Step 1. Enable the external oscillator. Step 2. Wait at least 1 ms. Step 3. Poll for XTLVLD => ‘1’. Step 4. Switch the system clock to the external oscillator. ECE/CS-352: Embedded Microcontroller Systems
Instruction Timing • C8051F020 – Pipelined architecture • Machine cycle = clock cycle • Most instructions take 1 or 2 clock cycles • Total of 109 instructions • Summary of instruction timing: ECE/CS-352: Embedded Microcontroller Systems
Pipelining Omit from Student Version ECE/CS-352: Embedded Microcontroller Systems
Delay Loops djnz acc, $ ; 3 cycles if no jump, ; 4 cycles if jump # cycles (acc) x 4 Execution time = # cycles x (T) With 22.1184 MHz External Osc. With 2 MHz Internal Osc. T = 45.211 ns Execution time = (acc) x (180.8 ns) T = 0.5 s Execution time = (acc) x (2s) ECE/CS-352: Embedded Microcontroller Systems
Sample Configuration • Use 22.1184 MHzexternal oscillator Main: mov WDTCN, #0deh ; disable watchdog timer mov WDTCN, #0adh mov OSCXCN, #67h ; enable external crystal ; oscillator at 22.1184MHz clr A ; wait at least 1ms djnz acc, $ ; wait ~510us (255 x 4 x 0.5us) = 510 us) djnz acc, $ ; wait ~510us osc_wait: ; poll for XTLVLD-->1 mov a, OSCXCN jnb acc.7, osc_wait orl OSCICN, #08h ; select external oscillator as ; system clock source ECE/CS-352: Embedded Microcontroller Systems
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 • Can be used to create waveforms, measure time intervals, set frequency of events, etc. ECE/CS-352: Embedded Microcontroller Systems
C8051F020 Timers Size of timers can be configured. • Timers can count from arbitrary initial value with the “Auto-reload” feature. • “Capture” allows the timer to be “frozen” when an event occurs. • Timers 2 and 4 can be used to set baud rate for uarts. ECE/CS-352: Embedded Microcontroller Systems
Timer Clock Sources CKCON: Clock Control Register Timer0 Timer clock selects 0 = system clock 12 (for compatibility with original 8051, and for slow stuff) 1 = system clock Timer4 ECE/CS-352: Embedded Microcontroller Systems
Configuring Timers • TCON and TMOD used to configure Timer0 and Timer1 TCON: Timer Control Register These deal with external interrupts Timer 1 Overflow Flag Timer 1 run control 0 = disable Timer 1 1 = enable Timer 1 ECE/CS-352: Embedded Microcontroller Systems
Configuring Timers TMOD: Timer Mode Register Timer 1 Timer 0 GATE1: 0 = timer enabled with TR1 only 1 = timer enabled only when TR1=1 and \INT=1 C/T1: 0 = timer incremented by clock input 1 = counter incremented by edge on external T1 pin ECE/CS-352: Embedded Microcontroller Systems
Using Timers For Periodic EventsUsing Polling • Set mode to be timer – use appropriate clock and timer size • In main program • Check for overflow flag (polling) • When overflow flag occurs • Do event • Reset timer overflow flag • Reset timer initial value (unless using auto-reload or initial value of 0 is OK) • Continue checking ECE/CS-352: Embedded Microcontroller Systems
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 ECE/CS-352: Embedded Microcontroller Systems
Time to use timers! ECE/CS-352: Embedded Microcontroller Systems
Using Timers as Counter • Set mode to be counter, with appropriate size (8, 13 or 16 bits) • Initialize counter to zero • Enable counter • Counter can be read and reset by main program. ECE/CS-352: Embedded Microcontroller Systems
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. ECE/CS-352: Embedded Microcontroller Systems
Measuring Pulses.... And using the Config tool ECE/CS-352: Embedded Microcontroller Systems
Memory Interface address data CPU Memory control ECE/CS-352: Embedded Microcontroller Systems
On-chip “External” RAM “external” RAM accessed with movx instruction Can add MORE memory Interfaced using External Data Memory Bus ECE/CS-352: Embedded Microcontroller Systems
Memory Expansion Can add more external RAM port 4 implements control lines ports 5 and 6 implement address bus port 7 implements data bus ECE/CS-352: Embedded Microcontroller Systems
Using External RAM • Used to hold large data sets • Accessed with movx instruction • MOVX A, @Ri Move external data to A register • MOVX @Ri, A Move A to external data (8-bit address) • MOVX A, @DPTR Move external data (16-bit address) to A • MOVX @DPTR, A Move A to external data (16-bit address) • Remember that the data pointer can be incremented, but not decremented. ECE/CS-352: Embedded Microcontroller Systems
Move some data…. ECE/CS-352: Embedded Microcontroller Systems
Digital to Analog Conversion 0001 0010 Digital Signals: 04, 00, 06, 12, 1D, 22, 21…. Analog Signal ideal actual ECE/CS-352: Embedded Microcontroller Systems
Digital to Analog Conversion • Two general types • Weighted D/A Converter (4-bit example) R digital input Q3 Q2 Q1 Q0 analog output 2R 4 Rout register 4R 1111 8R 1100 1000 0100 0000 ECE/CS-352: Embedded Microcontroller Systems
Digital to Analog Conversion Ladder D/A Converter (4-bit example) Q3 Q2 Q1 Q0 analog output 2R digital input 4 R 1111 register 2R 1100 R 2R 1000 R 2R 0100 2R 0000 ECE/CS-352: Embedded Microcontroller Systems
Digital/Analog Converters in C8051F020 DAC0 and DAC1 (identical) When disabled, output is high impedance Data registers 12 bit digital value ECE/CS-352: Embedded Microcontroller Systems
DAC0CN: DAC Control Register DAC Output Scaling/Justification DAC Enable 0 = disable 1 = enable • DAC Mode • 00: DAC updates occur on a write to DAC0H. • 01: DAC updates occur on Timer 3 overflow. • 10: DAC updates occur on Timer 4 overflow. • 11: DAC updates occur on Timer 2 overflow. ECE/CS-352: Embedded Microcontroller Systems
DAC Output Scaling/Justification ECE/CS-352: Embedded Microcontroller Systems
DAC Registers • In mode 00 (default), analog output is updated on a write to DAC0H (or DAC1H) DAC0H (8) DAC0L (8) DAC1H (8) DAC1L (8) Example: ECE/CS-352: Embedded Microcontroller Systems
Conversion Synchronization • Use Timer overflows to synchronize DAC when it is important to have smooth output waveforms. Using software loops which may be interrupted. Using timer overflows. ECE/CS-352: Embedded Microcontroller Systems
Example: Vref = 3V 3V 4095 levels Range = 0 to (3V-732.6 V) 0 to 2.999267 Output Voltage Swing 0 analog range Vref – 1 lsb 000h digital range FFFh (4095) V level = 732.6 ECE/CS-352: Embedded Microcontroller Systems
Reference Voltage • Can be an external voltage on pin VREFD • Can be the internal reference voltage VREF (2.4V) ECE/CS-352: Embedded Microcontroller Systems
Configuring VREFDREF0CN REF0CN • BIASE: ADC/DAC Bias Generator Enable Bit. • (Must be ‘1’ if using ADC or DAC). • 0: Internal Bias Generator Off. • 1: Internal Reference Buffer On. Internal voltage reference is driven on the VREF pin. • REFBE: Internal Reference Buffer Enable Bit. • 0: Internal Reference Buffer Off. • 1: Internal Reference Buffer On. ECE/CS-352: Embedded Microcontroller Systems
Creating Analog Output... ECE/CS-352: Embedded Microcontroller Systems
Analog to Digital Conversion V Digital value 01111110 10110000 10111110 01111100 11111110 11101110 11111110 01110000 01111110 time time Analog A/D Converter Digital (8-bit) GND ECE/CS-352: Embedded Microcontroller Systems
Analog to Digital Conversion DAC n Basic idea is to compare analog input to value produced by DAC and use logic to adjust the digital output so that it properly represents the analog input. A/D converters classified based on what logic is used. ECE/CS-352: Embedded Microcontroller Systems
Counting Converter DAC n Count from 0 to 2n, when DAC output is higher than Input, then flag changes. ECE/CS-352: Embedded Microcontroller Systems
Successive Approximation DAC n Starting at MSB, set each bit to 1, and if it trips the comparator, reset to 0. If not, hold at 1. Repeat for all bits. 100000000000 110000000000 101000000000 ..... Example... first 3 bits 110000000000 analog 101000000000 100000000000 ECE/CS-352: Embedded Microcontroller Systems
Analog to Digital ConversionPrecision Analog Digital n A/D Converter Analog 0.00 0.25 0.50 0.75 1.00 1.25 1.50 1.75 2.00 2.25 2.50 2.75 3.00 3.25 3.50 3.75 4.00 Digital 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111 Examples: Analog Range: 0V-4V Digital: n=4 4 Volts .25 V/bit Precision: 16 values ECE/CS-352: Embedded Microcontroller Systems
C8051F020 A/D Converters • ADC0 • 12-bit Successive Approximation (SAR) • 100ksps (kilo-samples per second) • ADC1 • 8-bit SAR • 500ksps ECE/CS-352: Embedded Microcontroller Systems
ADC0 Analog source options SFRs Reference voltage options Conversion sync options ECE/CS-352: Embedded Microcontroller Systems
AMX0CF – AMUX0 Configuration Register Differential pair inputs: + - V V can be positive or negative 0 – single-ended analog inputs 1 – differential pairs AMX0CF ECE/CS-352: Embedded Microcontroller Systems
AMX0SL – AMUX0 Channel Select Register AMUX0 address bits What is MUXed in depends on AMUX0CF AMX0SL ECE/CS-352: Embedded Microcontroller Systems
AMUX0SL Possibilities ECE/CS-352: Embedded Microcontroller Systems