1 / 103

The Silicon Laboratories C8051F020

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:

cybil
Télécharger la présentation

The Silicon Laboratories C8051F020

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. The Silicon Laboratories C8051F020 Enhanced 8051 ECE/CS-352: Embedded Microcontroller Systems

  2. 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

  3. 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

  4. 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

  5. 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

  6. 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

  7. Development Board Oscillator ECE/CS-352: Embedded Microcontroller Systems

  8. 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

  9. 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

  10. Pipelining Omit from Student Version ECE/CS-352: Embedded Microcontroller Systems

  11. 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 (2s) ECE/CS-352: Embedded Microcontroller Systems

  12. 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

  13. 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

  14. 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

  15. 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

  16. 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

  17. 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

  18. 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

  19. 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

  20. Time to use timers! ECE/CS-352: Embedded Microcontroller Systems

  21. 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

  22. 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

  23. Measuring Pulses.... And using the Config tool ECE/CS-352: Embedded Microcontroller Systems

  24. Memory Interface address data CPU Memory control ECE/CS-352: Embedded Microcontroller Systems

  25. 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

  26. 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

  27. 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

  28. Move some data…. ECE/CS-352: Embedded Microcontroller Systems

  29. 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

  30. 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

  31. 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

  32. 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

  33. 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

  34. DAC Output Scaling/Justification ECE/CS-352: Embedded Microcontroller Systems

  35. 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

  36. 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

  37. 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

  38. 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

  39. 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

  40. Creating Analog Output... ECE/CS-352: Embedded Microcontroller Systems

  41. 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

  42. 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

  43. 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

  44. 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

  45. 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

  46. 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

  47. ADC0 Analog source options SFRs Reference voltage options Conversion sync options ECE/CS-352: Embedded Microcontroller Systems

  48. 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

  49. AMX0SL – AMUX0 Channel Select Register AMUX0 address bits What is MUXed in depends on AMUX0CF AMX0SL ECE/CS-352: Embedded Microcontroller Systems

  50. AMUX0SL Possibilities ECE/CS-352: Embedded Microcontroller Systems

More Related