The Silicon Laboratories C 8051 F 020 Enhanced
The Silicon Laboratories C 8051 F 020 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, ADC 0 CN, DAC 0 CN, TMR 3 CN) • Configuration registers: – XXXCF (ADC 0 CF, AMX 0 CF, EMI 0 CF) • Data registers for subsystems: – ADC 0 H, ADC 0 L, DAC 0 H, DAC 0 L • 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 Configuration OSCICN Missing clock detector enable Internal Osc. frequency system clock ready select 0 = internal 1 = external (internal by Default Sysclk default) f = 2 MHz T = 0. 5 s Internal Osc. freq. control bits 00 – 2 MHz 01 – 4 MHz 10 – 8 MHz 11 – 16 MHz Internal Osc. enable (enabled by default) ECE/CS-352: Embedded Microcontroller Systems
External Osc. Configuration OSCXCN External Osc. mode bits Crystal Osc. valid flag 00 x: Off. XTAL 1 pin is grounded internally. 010: System Clock from External CMOS Clock on XTAL 1 pin. • External Osc. freq. control bits • Depends on frequency range of operation 011: System Clock from External CMOS Clock on XTAL 1 pin divided by 2. 10 x: RC/C Oscillator Mode with divide by 2 stage. 110: Crystal Oscillator Mode 111: Crystal Oscillator Mode with divide by 2 stage. 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 • • C 8051 F 020 – 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. T = 45. 211 ns Execution time = (acc) x (180. 8 ns) With 2 MHz Internal Osc. T = 0. 5 s Execution time = (acc) x (2 s) ECE/CS-352: Embedded Microcontroller Systems
Sample Configuration • Use 22. 1184 MHz external oscillator Main: mov WDTCN, #0 deh mov WDTCN, #0 adh mov OSCXCN, #67 h clr A djnz acc, $ ; disable watchdog timer ; enable external crystal ; oscillator at 22. 1184 MHz ; wait at least 1 ms ; wait ~510 us (255 x 4 x 0. 5 us) = 510 us) ; wait ~510 us osc_wait: ; poll for XTLVLD-->1 mov a, OSCXCN jnb acc. 7, osc_wait orl OSCICN, #08 h ; select external oscillator as ; system clock source ECE/CS-352: Embedded Microcontroller Systems
Timers • Original 8051 has 2 Timers, T 0 and T 1 • 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
C 8051 F 020 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 Timer 4 Timer clock selects Timer 0 0 = system clock 12 (for compatibility with original 8051, and for slow stuff) 1 = system clock ECE/CS-352: Embedded Microcontroller Systems
Configuring Timers • TCON and TMOD used to configure Timer 0 and Timer 1 TCON: Timer Control Register Timer 1 Overflow Flag Timer 1 run control 0 = disable Timer 1 1 = enable Timer 1 These deal with external interrupts ECE/CS-352: Embedded Microcontroller Systems
Configuring Timers TMOD: Timer Mode Register Timer 1 Timer 0 GATE 1: 0 = timer enabled with TR 1 only 1 = timer enabled only when TR 1=1 and INT=1 C/T 1: 0 = timer incremented by clock input 1 = counter incremented by edge on external T 1 pin ECE/CS-352: Embedded Microcontroller Systems
Using Timers For Periodic Events Using 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 Events Using 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 autoreload) – 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 CPU data Memory control ECE/CS-352: Embedded Microcontroller Systems
On-chip “External” RAM Can add MORE memory Interfaced using External Data Memory Bus “external” RAM accessed with movx instruction 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, 1 D, 22, 21…. Analog Signal actual ideal ECE/CS-352: Embedded Microcontroller Systems
Digital to Analog Conversion • Two general types – Weighted D/A Converter (4 -bit example) 4 register digital input Q 3 Q 2 Q 1 Q 0 R 2 R 4 R analog output Rout 1111 8 R 1100 1000 0100 0000 ECE/CS-352: Embedded Microcontroller Systems
Digital to Analog Conversion Ladder D/A Converter (4 -bit example) 4 analog output 2 R register digital input Q 3 Q 2 Q 1 Q 0 R 1111 2 R 2 R 1100 R 1000 2 R R 0100 2 R 0000 ECE/CS-352: Embedded Microcontroller Systems
Digital/Analog Converters in C 8051 F 020 DAC 0 and DAC 1 (identical) When disabled, output is high impedance Data registers 12 bit digital value ECE/CS-352: Embedded Microcontroller Systems
DAC 0 CN: DAC Control Register DAC Output Scaling/Justification DAC Enable 0 = disable 1 = enable DAC Mode 00: DAC updates occur on a write to DAC 0 H. 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 DAC 0 H (8) DAC 0 L (8) DAC 1 H (8) DAC 1 L (8) • In mode 00 (default), analog output is updated on a write to DAC 0 H (or DAC 1 H) 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
Output Voltage Swing 0 analog range 000 h digital range Example: Vref = 3 V V 4095 levels = 732. 6 level Vref – 1 lsb FFFh (4095) Range = 0 to (3 V-732. 6 V) 0 to 2. 999267 ECE/CS-352: Embedded Microcontroller Systems
Reference Voltage • Can be an external voltage on pin VREFD • Can be the internal reference voltage VREF (2. 4 V) ECE/CS-352: Embedded Microcontroller Systems
REF 0 CN Configuring VREFD REF 0 CN 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
V Digital value 01111110 10110000 101111100 011111101110 11111110 01110000 Analog to Digital Conversion 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 2 n, when DAC output is higher than Input, then flag changes. ECE/CS-352: Embedded Microcontroller Systems
Successive Approximation DAC n Example. . . first 3 bits 1100000 101000000 analog 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. 1000000 1100000 10100000. . . ECE/CS-352: Embedded Microcontroller Systems
Analog to Digital Conversion Precision Analog n A/D Converter Examples: Analog Range: 0 V-4 V Digital: n=4 Precision: 4 Volts 16 values . 25 V/bit Digital 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 ECE/CS-352: Embedded Microcontroller Systems
C 8051 F 020 A/D Converters • ADC 0 – 12 -bit Successive Approximation (SAR) – 100 ksps (kilo-samples per second) • ADC 1 – 8 -bit SAR – 500 ksps ECE/CS-352: Embedded Microcontroller Systems
ADC 0 Analog source options SFRs Reference voltage options Conversion sync options ECE/CS-352: Embedded Microcontroller Systems
AMX 0 CF – AMUX 0 Configuration Register Differential pair inputs: + V V can be positive or negative 0 – single-ended analog inputs 1 – differential pairs AMX 0 CF ECE/CS-352: Embedded Microcontroller Systems
AMX 0 SL – AMUX 0 Channel Select Register AMUX 0 address bits What is MUXed in depends on AMUX 0 CF AMX 0 SL ECE/CS-352: Embedded Microcontroller Systems
AMUX 0 SL Possibilities ECE/CS-352: Embedded Microcontroller Systems
ADC 0 CF – ADC 0 Configuration Register Bit 7 -Bit 3: SAR Conversion Clock Period Bits Bit 2 -Bit 0: Internal Amplifier Gain ADC 0 CF 000: Gain = 1 001: Gain = 2 010: Gain = 4 011: Gain = 8 10 x: Gain = 16 11 x: Gain = 0. 5 ECE/CS-352: Embedded Microcontroller Systems
ADC 0 CN – ADC 0 Control Register AD 0 EN 0 = disabled 1 = enabled AD 0 TM Track mode bit Normally 0 AD 0 INT 0 = conversion not completed (must be cleared by software) 1 = conversion has been completed ADC 0 CN AD 0 BUSY 0 = conversion not in progress 1 = conversion in progress ECE/CS-352: Embedded Microcontroller Systems
ADC 0 CN – ADC 0 Control Register ADC 0 CN Bit 3 -2: ADC 0 Start of Conversion Mode Select. If AD 0 TM = 0 (tracking mode on): 00: ADC 0 conversion initiated on every write of ‘ 1’ to AD 0 BUSY. 01: ADC 0 conversion initiated on overflow of Timer 3. 10: ADC 0 conversion initiated on rising edge of external CNVSTR. 11: ADC 0 conversion initiated on overflow of Timer 2. If AD 0 TM = 1: Same as above except conversion takes 3 SAR clock cycles longer Bit 1: ADC 0 Window Compare Interrupt Flag. This bit must be cleared by software. 0: ADC 0 Window Comparison Data match has not occurred since this flag was last cleared. 1: ADC 0 Window Comparison Data match has occurred. Bit 0: ADC 0 Left Justify Select. 0: Data in ADC 0 H: ADC 0 L registers are right-justified. 1: Data in ADC 0 H: ADC 0 L registers are left-justified. ECE/CS-352: Embedded Microcontroller Systems
Selecting VREF, Gain • Maximum VREF = 3. 3 V (Vdd) • Suppose analog range is about 0 -3 V – No Gain needed – External VREF of 3 V or – Gain =. 5 (so analog range becomes 0 -1. 5 V) – VREF from DAC 0 of 1. 5 V • Suppose analog range is low: 0 -0. 01 V – Use max gain of 16 (so range is 0 -0. 16 V) – VREF from DAC 0 or external, 0. 16 V) ECE/CS-352: Embedded Microcontroller Systems
ADC 0 Example 1 Vin + - 2. 0 V • Differential input (can be negative or positive) on AIN 0 and AIN 1 (channel select AIN 0) • Convert on timer 2 overflow • Amplify by 4 • Right justified data • Interrupt each conversion • External Vref = 2. 0 V ECE/CS-352: Embedded Microcontroller Systems
ADC 0 Example 1 Data Conversion: Gain = 4 VREF = 2. 0 V Note: Vin limited to range of -. 5 V to +. 5 V Vin ADC 0 H: ADC 0 L +. 5 V 07 FFh 00000111: 1111 +. 25 V 0400 h 00000100: 0000 0 0000 h 0000: 0000 -. 25 V FC 00 h 11111100: 0000 -. 5 V F 800 h 11111000: 0000 n = 12 for single-ended inputs, n = 11 for differential Values are sign-extended. ECE/CS-352: Embedded Microcontroller Systems
ADC 0 Example 2 Vin 1 Vin 2 Vin 3 • Single ended inputs (3 of them) • Convert on timer 2 overflow • Amplify by 2 • Right justified data • Interrupt on conversion mov AMX 0 CF, #060 h mov AMX 0 SL, #000 h mov ADC 0 CF, #009 h mov ADC 0 CN, #08 Ch Channel can be modified in the program ; AMUX Configuration Register ; AMUX Channel Select Register ; ADC 0 Configuration Register ; ADC Control Register ECE/CS-352: Embedded Microcontroller Systems
Conversion Calculations 0 analog range 000 h digital range Vref – 1 lsb FFFh (4095) There are 4096 different digital values corresponding to 0 -Vref. Find the voltage per least significant bit: Vref 4096 Now find analog value corresponding to some digital value Xd Vref Va = x Xd 4096 ECE/CS-352: Embedded Microcontroller Systems
Become ADC Converts. . ECE/CS-352: Embedded Microcontroller Systems
Two More Useful Analog Subsystems • Analog Programmable Window Detector • Temperature Sensor ECE/CS-352: Embedded Microcontroller Systems
ADC 0 Programmable Window Detector • Set limits for Analog input value • Analog value continuously compared to the limits • System is notified if analog input is out of bounds. ECE/CS-352: Embedded Microcontroller Systems
Window Limit Registers AD 0 WInt = 1 ADC 0 LTH | ADC 0 LTL ADC 0 GTH | ADC 0 GTL AD 0 WInt = 1 ADC 0 GTH | ADC 0 GTL ADC 0 LTH | ADC 0 LTL AD 0 WInt = 1 ECE/CS-352: Embedded Microcontroller Systems
Programmable Window Detector EXAMPLE ECE/CS-352: Embedded Microcontroller Systems
ADC 0 CN AD 0 WINT: ADC 0 Window Compare Interrupt Flag This flag must be cleared by software. 0: ADC 0 Window Comparison Data match has not occurred since this flag was last cleared. 1: ADC 0 Window Comparison Data match has occurred. ECE/CS-352: Embedded Microcontroller Systems
Example – Detect Darkness • Using light sensor setup, with “dark” corresponding to. 25 * VREF • When “dark” is detected, use an interrupt service routine to turn on the LED. • When it becomes light enough, (. 5 VREF) turn LED off = 400 h = 800 h AD 0 WInt = 1 ADC 0 GTH: ADC 0 GTL ADC 0 LTH: ADC 0 l. TL AD 0 WInt = 1 ECE/CS-352: Embedded Microcontroller Systems
Example – Detect Darkness ECE/CS-352: Embedded Microcontroller Systems
Example – Detect Darkness cseg at 043 h ; set the interrupt vector ljmp adw_int …. adw_int: off_light: over: clr AD 0 WINT ; Clear interrupt flag (ADC 0 CN is bit addressable) mov a, ADC 0 H ; check MSB of ADC to see which condition it is clr C subb a, #04 ; Is it less than 04? jnc off_light ; if not, must be time to turn light off setb LED ; if so, turn on light and return sjmp over clr LED reti ECE/CS-352: Embedded Microcontroller Systems
Temperature Sensor • Selected with the AMX 0 SL register • Otherwise treated the same as other ADC inputs • Using above equation, and ADC 0 settings and conversion equation, we can convert temperature to digital value. ECE/CS-352: Embedded Microcontroller Systems
Temperature Sensor Example Letting the assembler do more for us. How hot is it? ECE/CS-352: Embedded Microcontroller Systems
More on Temp. Sensor Code ECE/CS-352: Embedded Microcontroller Systems
More on Temp. Sensor Code ECE/CS-352: Embedded Microcontroller Systems
More on Temp. Sensor Code ECE/CS-352: Embedded Microcontroller Systems
More on Temp. Sensor Code ECE/CS-352: Embedded Microcontroller Systems
More on Temp. Sensor Code ECE/CS-352: Embedded Microcontroller Systems
ADC 1 – the “other” ADC 8 -bit ADC, 500 ksps Control registers similar to ADC 0, but simpler ECE/CS-352: Embedded Microcontroller Systems
ADC 1 AIN 1. 0 – AIN 1. 7 shared with P 1. 0 – P 1. 7 Must set P 1 MDIN for ANALOG inputs, and it is NOT necessary to turn on crossbar switch ECE/CS-352: Embedded Microcontroller Systems
Why not Crossbar? Bypass crossbar ECE/CS-352: Embedded Microcontroller Systems
ADC 1 Equivalent Input Circuit ECE/CS-352: Embedded Microcontroller Systems
Timers 2, 3 & 4 ECE/CS-352: Embedded Microcontroller Systems
The “Other” Timers • Timer 3 – auto-reload feature, more clock sources • Timers 2 and 4 – almost identical to each other – auto-reload feature – capture feature – baud rate generator for UART 0 & 1 (serial interface) ECE/CS-352: Embedded Microcontroller Systems
Timer 3 • Clock sources: – External oscillator 8 (allows for real-time clock input for timed applications) – Sysclk or Sysclk 12 (like all other timers) • Always 16 -bit, auto-reload. – Write “reload” value to TMR 3 RLH : TMR 3 RLL – Defines the time between overflows • Can be used to start ADC conversion • Can be used for SMBbus timing ECE/CS-352: Embedded Microcontroller Systems
Auto-reload Example Suppose we want to sample the ADC every 1 ms. • How many counts for 1 ms with: – With the internal oscillator (2 MHz)? ECE/CS-352: Embedded Microcontroller Systems
TMR 3 RL – Reload Register mov TMR 3 RLH, #(F 8 h) TMR 3 RLL, #(30 h) ; init reload values or SYSCLK EQU 2000 TC_1 ms EQU (SYSCLK)*1 1 ms mov ; SYSCLK frequency in k. Hz ; number of timer counts in Assembler can do these calculations TMR 3 RLH, #HIGH(-TC_1 ms); init reload values TMR 3 RLL, #LOW(-TC_1 ms) ECE/CS-352: Embedded Microcontroller Systems
Timers 2 and 4 - Similar Capture: Can latch the timer value into a separate latch when certain events occur ECE/CS-352: Embedded Microcontroller Systems
Timer 2 – Capture Mode Capture occurs on edge of T 2 EX when EXEN 2 enables it. Capture register Interrupt on overflow or on capture when enabled ECE/CS-352: Embedded Microcontroller Systems
Capture Mode to Measure Intervals 1 2 8051 TEX 2 time interval RCAP 2 Timer 2 value, EXF 2 flag goes high, Timer 2 interrupt generated if enabled If time interval is less than FFFF counts, then ISR can just subtract captured value 2 from captured value 1 to find time interval. Otherwise ISR must also keep track of overflows. ECE/CS-352: Embedded Microcontroller Systems
Programmable Counter Array ECE/CS-352: Embedded Microcontroller Systems
Programmable Counter Array • The ultimate timer/counter! – SIX different possible clock sources – SIX modes of operation • Capture modes (with 3 edge options) • Software timer (Compare) mode (interrupt when timer register = compare register) • High speed output : (output pin is toggled when timer register = compare register) • Frequency output: (square wave produced at a specified frequency) • 8 -bit Pulse-Width-Modulation mode • 16 -bit Pulse-Width-Modulation mode ECE/CS-352: Embedded Microcontroller Systems
PCA Block Diagram Clock sources from timer overflow as well as external clock on ECI or sysclk derivatives Output pins for PWM and other waveforms ECE/CS-352: Embedded Microcontroller Systems
PCA Control • 16 -bit PCA counter/timer consists of two 8 bit SFRs: PCA 0 L and PCA 0 H. • Reading PCA 0 H or PCA 0 L does not disturb the counter operation. • PCA 0 MD and PCA 0 CN are the configuration registers. ECE/CS-352: Embedded Microcontroller Systems
PCA 0 MD Counter/Timer Idle Control ECF: PCA Counter/Timer Overflow Interrupt Enable. 0: Disable the CF interrupt. 1: Enable a PCA 0 Counter/Timer Overflow interrupt request when CF (PCA 0 CN. 7) is set. ECE/CS-352: Embedded Microcontroller Systems
PCA 0 CN CF: PCA Counter/Timer Overflow Flag. CCF 4 -0: PCA 0 Module 4 to Module 0 Capture/Compare Flag – set by hardware when a match or capture occurs. CR: PCA 0 Counter/Timer Run Control ECE/CS-352: Embedded Microcontroller Systems
PCA Capture/Compare Modules • 5 modules: each module can operate in one of the 6 modes • Specified by SFRs PCA 0 CPM 0 -4 (PCA 0 Capture/Compare Mode) • • • PWM 16 n: 16 -bit Pulse Width Modulation Select ECOMn: Comparator Function Enable MATn: Match Function Enable. TOGn: Toggle Function Enable. PWMn: Pulse Width Modulation Mode Enable. ECE/CS-352: Embedded Microcontroller Systems
PCA 0 CPMn ECCFn: Capture/Compare Flag Interrupt Enable. This bit sets the masking of the Capture/Compare Flag (CCFn) interrupt in PCA 0 CN. 0: Disable CCFn interrupts. 1: Enable a Capture/Compare Flag interrupt request when CCFn is set. ECE/CS-352: Embedded Microcontroller Systems
PCA Interrupts • PCA only has one interrupt vector, but can be triggered by many things. ECE/CS-352: Embedded Microcontroller Systems
PCA Capture Mode • Transition (positive, negative, or either depending on how CAPPn and CAPNn bits are set) on CEX pin causes current timer value to be captured. • CCF flag indicates capture has occurred (and causes interrupt if enabled and unmasked. ) ECE/CS-352: Embedded Microcontroller Systems
PCA Compare Mode (software timer) • Set compare registers with software • CCF or interrupt when compare reg = timer ECE/CS-352: Embedded Microcontroller Systems
PCA High Frequency Output • Similar to compare mode, but CEX is toggled on each compare match. ECE/CS-352: Embedded Microcontroller Systems
Frequency Output Mode • Programmable frequency square wave on CEXn • High byte of PCA 0 CPn holds counts between toggles • Frequency defined as follows: ECE/CS-352: Embedded Microcontroller Systems
8 bit PWM mode • Pulse Width Modulation Tp T Duty Cycle = Tp T “Average” value of signal is proportional to duty cycle. Pulse width modulation means varying the duty cycle. ECE/CS-352: Embedded Microcontroller Systems
8 bit PWM Mode • T is set by the clock source of the PCA • Duty cycle is set by high byte of PCA 0 CPn ECE/CS-352: Embedded Microcontroller Systems
16 Bit PWM Mode • Same as 8 -bit but entire PCA 0 CPn register is used to set duty cycle. ECE/CS-352: Embedded Microcontroller Systems
Seven Segment Display! Lab report due next Wednesday ECE/CS-352: Embedded Microcontroller Systems
- Slides: 103