輸出動作與輸入命令相同.

Slides:



Advertisements
Similar presentations
Mark Neil - Microprocessor Course 1 Device Drivers – Digital Voltmeter.
Advertisements

C Examples 1.
Digital Thermostat and Data Logger Brandon Wagner and David Southwick.
Computertechniek Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 1  pak het project tint.zip.
Chapter 11 It’s an Analog World Learning to use the Analog to Digital Converter.
Analog to Digital Convertor MTT48 V1.0 ADC - 1 ANALOG TO DIGITAL CONVERTOR (ADC)
Analog Comparator Positive input chooses bet. PB2 and Bandgap Reference. Negative input chooses bet. PB3 and the 8 inputs of the A/D. ACME= Analog Comparator.
Lecture 5: PIC32 development board, Timers ADC and interrupts,
1 Lab2: A/D Converter. 2 This circuit connects a variable voltage to an A/D port on the AVR mcu. Your software running on the AVR mcu will read the digital.
5-1 Analogue Input/Output Many sensors/transducers produce voltages representing physical data.  To process transducer data in a computer requires conversion.
PIC16F bit 8-channel Analog-to-Digital Converter.
ECT 357 Ch 10 Analog to Digital COnversion. Today’s Quote: It’s better to die with a good name than to live with a bad one. It’s better to die with a.
8-Bit Timer/Counter 0 Counter/Timer 0 and 2 (TCNT0, TCNT2) are nearly identical. Differences: -TCNT0 can run off an external 32Khz clock (Tosc) or the.
5-1 Timer/Counters In many microprocessor systems we need to:  count logic pulses  measure the frequency of signals  measure the period of pulses 
Lecture 9 Timer Operations and Programming. 2  Introduction  Summary of timers  Timer programming sequence  Summary of timer SFRs  Timer 0: 8-bit.
Lecture 9. - Synchronous Devices require a timing signal. Clock generated Interval Timer Microprocessor Interval Timer Clk PCLK = MHz PCLK (for.
V 0.21 Timers A timer on a  C is simply a counter The input clock frequency to a timer can be prescaled so that it is some fraction of the system clock.
ECE 371- Unit 11 Timers and Counters (“Stop Watches and Alarm Clocks”)
7/23 Timers in Coldfire Processor Computer Science & Engineering Department Arizona State University Tempe, AZ Dr. Yann-Hang Lee (480)
V 0.91 Polled IO versus Interrupt Driven IO Polled Input/Output (IO) – processor continually checks IO device to see if it is ready for data transfer –Inefficient,
Timers ELEC 330 Digital Systems Engineering Dr. Ron Hayne
Unit 10.2 Timer Examples. Example – Music Generation Channel 6 – Set up as a timer Output to Generate Square Waves Channel 4 – Set up as a timer Output.
Revised: Aug 1, ECE 263 Embedded System Design Lessons 23, 24 - Exceptions - Resets and Interrupts.
MCU: Interrupts and Timers Ganesh Pitchiah. What’s an MCU ?
Page 1 D&C EBV Seminar June 2003 Motor Demo C868 Chevillot/Jansen June 2003 N e v e r s t o p t h i n k i n g. Infineon C868 Hands On Training CAPCOM6.
Robotraffic software and programming aids Robotics Laboratory Faculty of Mechanical Engineering Technion Israel Institute of Technology.
Lecture 11: TI MSP430 Timers Compare Modes
dsPIC DSC –Modul A/D Conversia A/D Registre programare
FREQUENCY COUNTER USING Silicon Labs C8051F020 microcontroller
© 2008, Renesas Technology America, Inc., All Rights Reserved 1 Course Introduction Purpose This course provides an overview of the peripheral functions.
EEE527 Embedded Systems Lecture 10B:Chapter 11 Analogue to Digital Convertors (ADCs) (version 2: 25/11/13, see after slide 20 Ian McCrumRoom 5B18, Tel:
Atmel Atmega128 Overview ALU Particulars RISC Architecture 133, Mostly single cycle instructions 2 Address instructions (opcode, Rs, Rd, offset) 32x8 Register.
ECE/CS-352: Embedded Microcontroller Systems The Silicon Laboratories C8051F020 Enhanced 8051 Part 4 Timer3, Temperature Sensor, AD0WINT.
CS224 I/O. Timers Timer1 is 16-bit timer 2^16-1 or 65,535 SYSCLK = 40MHz, Prescalers – 1:1, 1:8, 1:64, and 1:256 – Use T1CONbits.TCKPS=3 for 1:256 scaling.
Saxion University of Applied Sciences Advanced Microcontrollers A practical approach.
By James Cockrell and Justin Loveless
Real Time Interrupts Section Real-Time Interrupt (RTI) Most operating systems (OS) require an interrupt every T seconds by the RTI RTI interrupts.
Chapter 5 - Interrupts.
Lecture 11: Liquid Level Control System: A Case Study 1.
C Examples 1. Download Links MPLAB IDE dsPIC30F4011/4012 Data Sheet dsPIC30F Family Reference Manual MikroC MikroC Manual MikroC Quick Reference.
Microcontroller based system design Asst. Prof. Dr. Alper ŞİŞMAN.
C Examples 1. Download Links dsPIC30F4011/4012 Data Sheet dsPIC30F4013/3014 dsPIC30F Family Reference Manual MikroC MikroC Manual MikroC Quick Reference.
Analog to Digital Converter (ADC)
Analog to Digital Conversion - ADC Mark Neil - Microprocessor Course 1 Device Drivers – Measuring Voltages.
Group: CCM Project 2.5. EMERSON Emerson is a diversified global manufacturing company.  Provides innovative solutions to customers in the following areas:
PIC16F887.
Timer & Watch Dog Test UNIT 16 로봇 SW 교육원 조용수. 학습 목표 Timer Init Timer Delay Test Timer Interrupt Test –One Shot Mode –Periodic Mode Watch Dog Test 시계 만들어.
SGDRS Software System Design Justin A. King WWU EET Senior project 2013.
ADC 1 Analog to Digital Converter. ADC 2 ADC Features n General Features -Supports 8 or 10-bit resolution Modes, -Track period fully programmable up to.
Sensing Algorithm using IR Sensor and ADC Soong-sil University. Robotics 기 정 두 원.
One more PIC18F252 example and revision for exam B222L Branislav Vuksanovic, UoP, ECE.
FOR MORE CLASSES VISIT   ECET 340 Week 1 HomeWork 1  ECET 340 Week 1 iLab 1  ECET 340 Week 2 HomeWork 2  ECET 340 Week 2 iLab.
C Examples 3. Download Links dsPIC30F4011/4012 Data Sheet dsPIC30F4013/3014 dsPIC30F Family Reference Manual MikroC MikroC Manual MikroC Quick Reference.
Servos Elementary Robotics with Servos
Outline Introduction to Arduino UNO Programming environment setup GPIO
CS4101 Introduction to Embedded Systems Lab 6: Low-Power Optimization
Analog Comparator An analog comparator is available on pins PE2(AIN0), PE3(AIN1) The comparator operates like any other comparator. -when (+) exceeds (-)
Prof. Chung-Ta King Department of Computer Science
Interrupt Source: under
8-Bit Timer/Counter 0 Counter/Timer 0 and 2 (TCNT0, TCNT2) are nearly identical. Differences: -TCNT0 can run off an external 32Khz clock (Tosc) or the.
The Arduino Microcontroller: Atmel AVR Atmega 328
Timer Operations and Programming
ECE 354 Computer Systems Lab II
Example 15 Interrupt-Driven Controller
Chapter 10 It’s an Analog World
ADC and DAC Programming in AVR
Figure CCP1 Control Register
ANALOG TO DIGITAL CONVERTER (ATD).
Prof. Chung-Ta King Department of Computer Science
Presentation transcript:

輸出動作與輸入命令相同

工作圖

//#include <stdio.h> //呼叫stdio(標準輸入輸出)指令巨集 //#define FCY 2000000 #include <p30F4011.h> //呼叫p30F3011(IC)指令巨集 #include <timer.h> #include <math.h> unsigned int icount=0; double v1=0.0,v2=0.0,e_new=0.0,e_old=0.0,d_new=0.0,d_old=0.0,kp=1.0,ki=100.0; _FWDT(WDT_OFF); void PWM_Initial(void) { PTPER = 1250; //PWM = (10MHz / (2000)) = 5 KHz IEC2bits.PWMIE = 0; //Disable PWM Interrupt PTCON = 0xA008; // 0b 1010 0000 0000 0000 PWMCON1 = 0x0777; // 0b 0000 0111 0111 0111 PDC1=0; OVDCON= 0x0100; //設定輸出腳位 IPC9bits.PWMIP = 7; }

void Init_Timer1( void ) { T1CON = 0; IFS0bits.T1IF = 0; IPC0bits.T1IP = 7; IEC0bits.T1IE = 1; PR1 = 5000; // 20MHz/8/5000=500Hz 中斷為2ms T1CONbits.TCS = 0; T1CONbits.TCKPS=1; //TCKPS<1:0>: Timer Input Clock Prescale Select bits //11 = 1:256 prescale value //10 = 1:64 prescale value //01 = 1:8 prescale value //00 = 1:1 prescale value T1CONbits.TON=1; } void _ISR _ADCInterrupt(void) IFS0bits.ADIF = 0 ; // 1 = Interrupt request has occurred // 0 = Interrupt request has not occurred while (!ADCON1bits.DONE ); // wait for end of conversion // 1 = A/D conversion is done // 0 = A/D conversion is NOT done ADCON1bits.DONE = 0;

void ADC10_Initial(void) { ADPCFG = 0xfffc; // 0B 1111 1111 1111 1110 // 1 = Analog input pin in Digital mode // 0 = Analog input pin in Analog mode ADCON1 = 0x00EE; // 0b 0000 0000 1110 1110 ADCON2 = 0x043C; // 0b 0000 0100 0011 1100 ADCON3 = 0x1F3F; // 0b 0001 1111 0011 1111 ADCSSL = 0xFFFF; // no scan input selected ....... ADCHS = 0x0000 ; IEC0bits.ADIE = 1 ; // Disable AD interrupt // IPC2bits.ADIP = 7 ; // Set Priority to 7 >> highest !! ADCON1bits.ADON = 1; // turn ADC ON }

void _ISR _T1Interrupt(void) { v1=ADCBUF0 & 0x3ff; v2=ADCBUF1 & 0x3ff; e_old=e_new; d_old=d_new; e_new=(v1-v2)*1.0; d_new=d_old+kp*(e_new-e_old)+ki*0.001*e_new; if(d_new>2500.0) d_new=2500.0; else if(d_new<0.0) d_new=0.0; PDC1=d_new; IFS0bits.T1IF = 0; } int main(void) TRISB = 0x0003; ADC10_Initial( ); Init_Timer1(); PWM_Initial(); while(1);

作業 改變輸出或輸入的倍率