C Examples 5. Download Links MPLAB IDE dsPIC30F4011/4012 Data Sheet dsPIC30F Family Reference Manual MikroC MikroC Manual MikroC Quick Reference.

Slides:



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

Interrupts, Low Power Modes and Timer A (Chapters 6 & 8)
More fun with Timer/Counters
4-1 Timers Timers can be used for  timing  event counting  pulse width measurement  pulse generation  frequency multiplication There are 8 Timers.
C Examples 1.
Computertechniek Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 1  pak het project tint.zip.
C Examples 4.
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.
PIC16F bit 8-channel Analog-to-Digital Converter.
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 
In this PPT, all the materials covered up for the PIC microcontroller set-up would be studied. Preliminary skills: Knowing of basic C grammar and basic.
Chapter 12 Capturing Input. Di Jasio - Programming 32-bit Microcontrollers in C Button Inputs.
1 Timing System Timing System Applications. 2 Timing System components Counting mechanisms Input capture mechanisms Output capture mechanisms.
Software Three Main Functions Records/Monitors Zero Detection Points Gives our PWM a starting point Data used to dynamically adjust carrier frequency Detects.
Today’s Lecture List the Timers of PIC18 and their associated registers Describe the various modes of the PIC18 timers Program the PIC18 timers in Assembly.
Designing with components II
Designing with components II Fall Overview Possible Components.
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,
ARM Timers.
System Clocks.
Timers ELEC 330 Digital Systems Engineering Dr. Ron Hayne
Interrupts, Counter and Timers. Interrupts (1) Interrupt-driven I/O uses the processor’s interrupt system to “interrupt” normal program flow to allow.
Timers The timers of the PIC16C7X microcontroller can be briefly described in only one sentence. There are three completely independent timers/counters.
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.
Practical Electronics & Programming
RS232 #use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7
1 Lab 1: Introduction. 2 Configure ATMEL AVR Starter Kit 500 (STK500), a prototyping/development board for Lab1. ATmega16 ( V) is the chip used.
Robotraffic software and programming aids Robotics Laboratory Faculty of Mechanical Engineering Technion Israel Institute of Technology.
Lecture 11: TI MSP430 Timers Compare Modes
LAB 8: Program Design Pattern and Software Architecture
FREQUENCY COUNTER USING Silicon Labs C8051F020 microcontroller
Time Measurement Capture Mode of the Capture/Compare/PWM module is used for time measurement. TMR1 or TMR3 16-bit value transferred to 16-bit capture.
1 68HC11 Timer Chapter HC11 Timer Subsystem Several timing functions: Basic timing Basic timing Real time interrupts Real time interrupts Output.
Timers and Interrupts Anurag Dwivedi. Let Us Revise.
Teachers Name : Suman Sarker Telecommunication Technology Subject Name : Microcontroller & Embedded System Subject Code : 6871 Semester : 7th Department.
Saxion University of Applied Sciences Advanced Microcontrollers A practical approach.
1 68HC11 Timer HC11 or HC12: Chapter HC11 Timer Subsystem  Several timing functions: Basic timing Basic timing Real time interrupts Real time.
Interrupts  An interrupt is any service request that causes the CPU to stop its current execution stream and to execute an instruction stream that services.
Real Time Interrupts Section Real-Time Interrupt (RTI) Most operating systems (OS) require an interrupt every T seconds by the RTI RTI 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.
C Examples 1. Download Links dsPIC30F4011/4012 Data Sheet dsPIC30F4013/3014 dsPIC30F Family Reference Manual MikroC MikroC Manual MikroC Quick Reference.
Arduino Mega Arduino Mega 2560 Arduino Mega 2560.
Analog to Digital Conversion - ADC Mark Neil - Microprocessor Course 1 Device Drivers – Measuring Voltages.
PIC16F887.
C Examples 6. Download Links MPLAB IDE dsPIC30F4011/4012 Data Sheet dsPIC30F Family Reference Manual MikroC MikroC Manual MikroC Quick Reference.
1 68HC11 Timer. 2 68HC11 Timer Subsystem Several timing functions: Basic timing Basic timing Real time interrupts Real time interrupts Output compare.
Timer & Watch Dog Test UNIT 16 로봇 SW 교육원 조용수. 학습 목표 Timer Init Timer Delay Test Timer Interrupt Test –One Shot Mode –Periodic Mode Watch Dog Test 시계 만들어.
Microcontrollers JULES CALELLA. Microcontrollers vs Microprocessors  Microprocessors – do not contain RAM, ROM, I/O  Microcontrollers – The whole package.
1 Lab 4: D/A Converter Lab 4: D/A Converter This is a simple resistive network for a D/A converter Port 1, Port 0 are digital inputs ==> 00 (minimum),
One more PIC18F252 example and revision for exam B222L Branislav Vuksanovic, UoP, ECE.
Microprocessors A practical approach..
1. PIC ADC  PIC18F877 has 8 analog input channels i.e. port A pins(RA0 to RA5) and port E pins(RE1 and RE2). These pins are used as Analog input pins.
C Examples 3. Download Links dsPIC30F4011/4012 Data Sheet dsPIC30F4013/3014 dsPIC30F Family Reference Manual MikroC MikroC Manual MikroC Quick Reference.
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
Analog Comparator An analog comparator is available on pins PE2(AIN0), PE3(AIN1) The comparator operates like any other comparator. -when (+) exceeds (-)
Interrupts, Counter and Timers
MSP432 ARM Timer Programming
ECE 354 Computer Systems Lab II
ADC and DAC Programming in AVR
Wave Generation and Input Capturing
ANALOG TO DIGITAL CONVERTER (ATD).
Device Drivers – Digital Voltmeter
PIC16F887.  1.Microcontroller introducton  2.MPLAB,Hi-tech compilers  3.LED  4.Switches/push buttons  5.7-Segment Display  6.Keypad  7.LCD  8.Timers.
Timers Chapter 2.
Presentation transcript:

C Examples 5

Download Links MPLAB IDE dsPIC30F4011/4012 Data Sheet dsPIC30F Family Reference Manual MikroC MikroC Manual MikroC Quick Reference

Measuring Tin Will include an offset error Decoupling Capacitor needed

Input Capture

IC1CON = 0x0082

int dist, i; char txt[6]; void main () // 20 MHz and PLL 80 { Uart1_Init(19200); TRISD=0b ; PR2=20; T2CON=0x8010; // Enable Timer 2 Prescaler=8 pulse will be 8 useconds while(1) { Delay_ms(1000); PORTD = 1; // Start Pulse TMR2 = 0; // Reset Timer 2 IEC0=0x0040; // Only Interrupt for Timer 2 is enabled. To stop Pulse } void interrupt_T2() org 0x { PORTD.F0 =0; // End Pulse IEC0=0x0002; // Only input capture interrupt 1 is enabled IC1CON = 0x0082; // Interrupt capture Timer 2 Every falling edge TRISD=TRISD|0b ; // Set D0 to input to wait for echo PR2=0xFFFF; // Allow maximum count on TIMER2 TMR2 = 0; // Reset Timer 2 IFS0=0x0000; // Clear interrupt flags } void interrupt_I1() org 0x { dist =TMR2/147-13; // Compensates offset error WordToStr(dist, txt); // Convert distance value to text i=0; while (txt[i]) { Uart1_Write_Char(txt[i]); // Send text to UART one character at a time i=i+1; } IC1CON = 0x0000; // Interrupt capture off IEC0=0x0000; // Disable interrupts TRISD=TRISD&0b ; // Return D0 to output PR2=20; // Prepare to generate next pulse IFS0=0x0000; // Clear interrupt Flags } Ping Distance Measurement

Main Function int dist, i; char txt[6]; void main () // 20 MHz and PLL 80 { Uart1_Init(19200); TRISD=0b ; PR2=20; T2CON=0x8010; // Enable Timer 2 Prescaler=8 pulse will be 8 useconds while(1) { Delay_ms(1000); PORTD = 1; // Start Pulse TMR2 = 0; // Reset Timer 2 IEC0=0x0040; // Only Interrupt for Timer 2 is enabled. To stop Pulse }

Start Pulse Generation void interrupt_T2() org 0x { PORTD.F0 =0; // End Pulse IEC0=0x0002; // Only input capture interrupt 1 is enabled IC1CON = 0x0082; // Interrupt capture Timer 2 Every falling edge TRISD=TRISD|0b ; // Set D0 to input to wait for echo PR2=0xFFFF; // Allow maximum count on TIMER2 TMR2 = 0; // Reset Timer 2 IFS0=0x0000; // Clear interrupt flags }

Time Measurement void interrupt_I1() org 0x { dist =TMR2/147-13; // Compensates offset error WordToStr(dist, txt); // Convert distance value to text i=0; while (txt[i]) { Uart1_Write_Char(txt[i]); // Send text to UART one character at a time i=i+1; } IC1CON = 0x0000; // Interrupt capture off IEC0=0x0000; // Disable interrupts TRISD=TRISD&0b ; // Return D0 to output PR2=20; // Prepare to generate next pulse IFS0=0x0000; // Clear interrupt Flags }

GP2D120

Components: GP2D120

GP2D120 Distance Measurement // Measures distance with GP2D120 //unsigned float adcRes; unsigned long adcRes; char txt[15]; void main() { int i; PORTB = 0x0000; TRISB.F1 = 1; // set pin as input - needed for ADC to work Uart1_Init(19200); while (1) { Delay_ms(1000); adcRes = Adc_Read(0); // Read ADC channel 1 adcRes = adcRes*500/1023; // Transform ADC result into volts adcRes = /adcRes; // Calculates distance // FloatToStr(adcRes, txt); // Convert ADC value to text LongToStr(adcRes, txt); // Convert ADC value to text i=0; while (txt[i]) { Uart1_Write_Char(txt[i]); // Send text to UART one character at a time i=i+1; } }//~!