C Examples 1. Download Links dsPIC30F4011/4012 Data Sheet dsPIC30F4013/3014 dsPIC30F Family Reference Manual MikroC MikroC Manual MikroC Quick Reference.

Slides:



Advertisements
Similar presentations
4-1 Timers Timers can be used for  timing  event counting  pulse width measurement  pulse generation  frequency multiplication There are 8 Timers.
Advertisements

Microcontroller Programming II MP6-1
C Examples 1.
8051 Core Specification.
C Examples 4.
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 
Timers and Interrupts Shivendu Bhushan Summer Camp ‘13.
16-Bit Timer/Counter 1 and 3 Counter/Timer 1,3 (TCNT1, TCNT3) are identical in function. Three separate comparison registers exist. Thus, three separate.
DsPIC30F4011. Main Features High-Performance, Modified RISC CPU: –Modified Harvard architecture –C compiler optimized instruction set architecture with.
8254 Programmable Interval Timer
1 Chapter 4 Timer Operation (I. Scott MacKenzie).
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,
Timer/counter Chapter 12
ARM Timers.
System Clocks.
Chapter 2 A Loop in the Pattern Designing the Main Loop and Timing.
16F877A. Timer 0 The Timer0 module timer/counter has the following features: –8-bit timer/counter –Readable and writable –8-bit software programmable.
Timers ELEC 330 Digital Systems Engineering Dr. Ron Hayne
Chapter 4 TIMER OPERATION
CoE3DJ4 Digital Systems Design Chapter 4: Timer operation.
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.
Clock Options and Sleep Modes. Clock Sources Flash Fuse bits can be programmed to choose one of the following Clock sources: 1. External RC Osc. f = 1/(3RC).
AT91 Embedded Peripherals
MCU: Interrupts and Timers Ganesh Pitchiah. What’s an MCU ?
C Examples 5. Download Links MPLAB IDE dsPIC30F4011/4012 Data Sheet dsPIC30F Family Reference Manual MikroC MikroC Manual MikroC Quick Reference.
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.
Chapter 7 Larger Systems and the PIC 16F873A The aims of this chapter are to introduce: The architecture of the 16F873A microcontroller; The 16F873A memory.
Conclusion Speech. Content Organization Pronunciation Handwriting.
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.
DsPIC30F4011 Fall DIP Switches  The upper four switches of SW1 are used to enable LEDs connected to PORTB/C, PORTA/D, PORTE and PORTF. For example,
I NTRODUCTION TO PIC PROGRAMMING By : S HERIF H ARHASH.
Chapter 5 - Interrupts.
C Examples 1. Download Links MPLAB IDE dsPIC30F4011/4012 Data Sheet dsPIC30F Family Reference Manual MikroC MikroC Manual MikroC Quick Reference.
Lecture 4 General-Purpose Input/Output NCHUEE 720A Lab Prof. Jichiang Tsai.
MACHINE CYCLE AND T-STATE
8051 Aula 02 Prof Afonso Ferreira Miguel. Microcontrolador 8051 (MCS-51)  Timers do MCS51 Two 16-bit Counter/Timers: Two 16-bit Counter/Timers: Up counters,
DsPIC30F4011.
#1 of 10 Tutorial Introduction PURPOSE -To explain how to configure and use the Timer Interface Module in common applications OBJECTIVES: -Identify the.
PIC16F887.
C Examples 6. Download Links MPLAB IDE dsPIC30F4011/4012 Data Sheet dsPIC30F Family Reference Manual MikroC MikroC Manual MikroC Quick Reference.
Chapter Microcontroller
1 68HC11 Timer. 2 68HC11 Timer Subsystem Several timing functions: Basic timing Basic timing Real time interrupts Real time interrupts Output compare.
Microcontrollers JULES CALELLA. Microcontrollers vs Microprocessors  Microprocessors – do not contain RAM, ROM, I/O  Microcontrollers – The whole package.
80C51 Block Diagram 1. 80C51 Memory Memory The data width is 8 bits Registers are 8 bits Addresses are 8 bits – i.e. addresses for only 256.
Special Features. Device Configuration bits Revision Device Configuration bits Revision On-chip Power-on Reset (POR) Revision On-chip Power-on Reset (POR)
One more PIC18F252 example and revision for exam B222L Branislav Vuksanovic, UoP, ECE.
Microprocessors A practical approach..
TIMERS.
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.
Timer modules in PIC 16F877.  The PIC 16F877 basically has three independent timer modules,  denoted by the symbols, TIMER-0, TIMER1,andTIMER2. . These.
Why are Timer Functions Important?
CPU Sequencing 6/30/2018.
COMP2121: Microprocessors and Interfacing
AVR Addressing Modes Subject: Microcontoller & Interfacing
MSP432 ARM Timer Programming
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.
8051 Micro Controller.
CPU Sequencing 7/20/2019.
Timers Chapter 2.
Presentation transcript:

C Examples 1

Download Links dsPIC30F4011/4012 Data Sheet dsPIC30F4013/3014 dsPIC30F Family Reference Manual MikroC MikroC Manual MikroC Quick Reference

Parallel I/O (PIO) Ports All port pins have three registers directly associated with the operation of the port pin. The Data Direction register (TRISx) determines whether the pin is an input or an output. If the Data Direction register bit is a ‘1’, then the pin is an input. All port pins are defined as inputs after a Reset. LATx Data Latch Drives the outputs. PORTx input output operations. When a peripheral is enabled and the peripheral is actively driving an associated pin, the use of the pin as a general purpose output pin is disabled. The I/O pin may be read, but the output driver for the Parallel Port bit will be disabled. If a peripheral is enabled, but the peripheral is not actively driving a pin, that pin may be driven by a port.

LED ON void main () { ADPCFG = 0xFFFF; // In order to use PORTB as digital input TRISB=0b ; // Sets bit 1 as output, the other bits as inputs. See comments Bellow while(1) // Infinite Loop { PORTB.F1=1; // Sets Bit 1 of PORT B to logic “1”. See comments Bellow } // The mikroC for dsPIC30/33 and PIC24 allows you to access individual (works with micro variables) // bits of 16-bit variables. Simply use the direct member selector (.) // with a variable, followed by one of identifiers F0, F1, …, F15 with // F15 being the most significant bit. // All dsPIC30/33 and PIC24 SFR registers are also available as structures // with bitfields named identically to the Microchip datasheets in order // to facilitate bit access e.g // // TRISBbits.TRISB3 = 1.

FLASH 1 void main () { ADPCFG = 0xFFFF; // In order to use PORTB as digital input TRISB=0b ; // Sets bit 1 as output, the other bits as inputs. See comments Bellow PORTB.F1=1; // Sets Bit 1 of PORT B to logic “1”. See comments Bellow while(1) // Infinite Loop { Delay_ms(1000); // Library function delay ms PORTB.F1=PORTB.F1^1; // Takes the complement }

Blinking LED - 2 void main () { ADPCFG = 0xFFFF; TRISB=0b ; PORTB=PORTB|0b ; // Bitwise setting of bit 1 while(1) { Delay_ms(1000); PORTB=PORTB^0x02; // Bitwise toggle of bit 1 }

Logical VS Bitwise

Timer 1 16-bit Timer Mode: In the 16-bit Timer mode, the timer increments on every instruction cycle up to a match value, preloaded into the Period register, PR1, then resets to 0 and continues to count.  When the CPU goes into the Idle mode, the timer will stop incrementing unless the TSIDL (T1CON ) bit 0. If TSIDL 1, the timer module logic will resume the incrementing sequence upon termination of the CPU Idle mode. 16-bit Synchronous Counter Mode: In the 16-bit Synchronous Counter mode, the timer increments on the rising edge of the applied external clock signal, which is synchronized with the internal phase clocks. The timer counts up to a match value preloaded in PR1, then resets to 0 and continues.  When the CPU goes into the Idle mode, the timer will stop incrementing unless the respective TSIDL bit o. If TSIDL 1, the timer module logic will resume the incrementing sequence upon termination of the CPU Idle mode. 16-bit Asynchronous Counter Mode: In the 16-bit Asynchronous Counter mode, the timer increments on every rising edge of the applied external clock signal. The timer counts up to a match value preloaded in PR1, then resets to 0 and continues. The 16-bit timer can be placed in the Gated Time Accumulation mode. This mode allows the internal TcY to increment the respective timer when the gate input signal (Ti CK pin) is asserted high. Control bit, TGATE (T1CON ), must be set to enable this mode. The timer must be enabled (TON 1) and the timer clock source set to internal (TCS 0). 16-bit Timer Mode 16-bit Synchronous Counter 16-bit Asynchronous Counter Mode The 16-bit timer in Gated Time Accumulation mode

Blinking LED - 3 void main () // 10 MHz and PLL 20MHZ not possible to generate 1 sec delay { T2CON=0x8030; // Enable Timer 2 Prescaler=256 IEC0=0x0040; // Enable Interrupt for Timer 2 PR2=0x9897; ADPCFG = 0xFFFF; TRISB=0b ; PORTB=PORTB|0b ; while(1) { } void interrupt_T2() org 0x { PORTB=PORTB^0x02; IFS0=0x0000; // IFS0 = IFS0&0b ; // If you want to turn off just this flag }

T2CON=0x8030

IEC0=0x0040;

Blinking LED - 4 void main () { ADPCFG = 0xFFFF; T2CON=0b ; // Enable Timer 2/3, Prescaler =1 IEC0=0x0080; // Enable Interrupt for Timer 3 PR2=0x2D00; // (PR3PR2)BASE16 = (20,000,000)BASE10 PR3=0x0131; // There will be an interrupt every 20,000,000 instruction cycles TRISB=0b ; PORTB=0x00; while(1) { } void interrupt_T2() org 0x { PORTB=PORTB^0x02; IFS0=0x0000; }

Counter void main () { ADPCFG = 0xFFFF; T2CON=0b ; // Enable Timer 2/3, Prescaler =1 IEC0=0x0080; // Enable Interrupt for Timer 3 PR2=0x2D00; // (PR3PR2)BASE16 = (20,000,000)BASE10 PR3=0x0131; // There will be an interrupt every 20,000,000 instruction cycles TRISB=0b ; TRISF=0x0000; PORTB=0x00; while(1) { } void interrupt_T2() org 0x { PORTB=PORTB^0x02; PORTF=PORTF+PORTB.F1; IFS0=0x0000; }