PIC32MZ tutorial -- 32-bit Timer

发布者:吾道明亮最新更新时间:2017-01-20 来源: eefocus关键字:PIC32MZ  tutorial  32-bit  Timer 手机看文章 扫描二维码
随时随地手机看文章

  The microcontroller is PIC32MZ2048ECH144 on the PIC32MZ EC Starter Kit. This microcontroller has four 32-bit synchronous timers are available by combining Timer2 with Timer3, Timer4 with Timer5, Timer6 with Timer7, and Timer8 with Timer9. The 32-bit timers can operate in one of three modes:


•Synchronous internal 32-bit timer

•Synchronous internal 32-bit gated timer

•Synchronous external 32-bit timer


  At the moment, I accomplish the 32-bit timer with combining Timer2 and Timer3, and let it operates in synchronous internal 32-bit timer. I enable the 32-bit timer interrupt. In a 32-bit timer configuration, it's the odd numbered interrupt that fires. In this case, it's the Timer3 interrupt. You can see that in the following interface.


  The first, configuration bits in CFB.h



// DEVCFG3  BFFFFFFF

// USERID = No Setting

#pragma config FMIIEN = ON // Ethernet RMII/MII Enable (MII Enabled) // need a 25MHz XTAL in MII mode, a 50MHz Clock in RMII mode. 

#pragma config FETHIO = ON // Ethernet I/O Pin Select (Default Ethernet I/O)

#pragma config PGL1WAY = ON // Permission Group Lock One Way Configuration (Allow only one reconfiguration)

#pragma config PMDL1WAY = ON // Peripheral Module Disable Configuration (Allow only one reconfiguration)

#pragma config IOL1WAY = ON // Peripheral Pin Select Configuration (Allow only one reconfiguration)

#pragma config FUSBIDIO = OFF // USB USBID Selection (Controlled by Port Function)


// DEVCFG2  7FF9B11A

#pragma config FPLLIDIV = DIV_3 // System PLL Input Divider (3x Divider)

#pragma config FPLLRNG = RANGE_5_10_MHZ // System PLL Input Range (5-10 MHz Input)

#pragma config FPLLICLK = PLL_POSC // System PLL Input Clock Selection (POSC is input to the System PLL)

#pragma config FPLLMULT = MUL_50 // System PLL Multiplier (PLL Multiply by 50) //PLL must output between 350 and 700 MHz

#pragma config FPLLODIV = DIV_2 // System PLL Output Clock Divider (2x Divider)

#pragma config UPLLFSEL = FREQ_24MHZ // USB PLL Input Frequency Selection (USB PLL input is 24 MHz)

#pragma config UPLLEN = OFF // USB PLL Enable (USB PLL is disabled)


// DEVCFG1  7F7F3839

#pragma config FNOSC = SPLL // Oscillator Selection Bits (System PLL)

#pragma config DMTINTV = WIN_127_128 // DMT Count Window Interval (Window/Interval value is 127/128 counter value)

#pragma config FSOSCEN = OFF // Secondary Oscillator Enable (Disable SOSC)

#pragma config IESO = OFF // Internal/External Switch Over (Disabled)

#pragma config POSCMOD = EC // Primary Oscillator Configuration (External clock mode)

#pragma config OSCIOFNC = ON // CLKO Output Signal Active on the OSCO Pin (Enabled)

#pragma config FCKSM = CSDCMD // Clock Switching and Monitor Selection (Clock Switch Disabled, FSCM Disabled)

#pragma config WDTPS = PS1048576 // Watchdog Timer Postscaler (1:1048576)

#pragma config WDTSPGM = STOP // Watchdog Timer Stop During Flash Programming (WDT stops during Flash programming)

#pragma config WINDIS = NORMAL // Watchdog Timer Window Mode (Watchdog Timer is in non-Window mode)

#pragma config FWDTEN = OFF // Watchdog Timer Enable (WDT Disabled)

#pragma config FWDTWINSZ = WINSZ_25 // Watchdog Timer Window Size (Window size is 25%)

#pragma config DMTCNT = DMT31 // Deadman Timer Count Selection (2^31 (2147483648))

#pragma config FDMTEN = OFF // Deadman Timer Enable (Deadman Timer is disabled)


// DEVCFG0  FFFFFFF7

#pragma config DEBUG = OFF // Background Debugger Enable (Debugger is disabled)

#pragma config JTAGEN = ON // JTAG Enable (JTAG Port Enabled)

#pragma config ICESEL = ICS_PGx2 // ICE/ICD Comm Channel Select (Communicate on PGEC2/PGED2)

#pragma config TRCEN = ON // Trace Enable (Trace features in the CPU are enabled)

#pragma config BOOTISA = MIPS32 // Boot ISA Selection (Boot code and Exception code is MIPS32)

#pragma config FECCCON = OFF_UNLOCKED // Dynamic Flash ECC Configuration (ECC and Dynamic ECC are disabled (ECCCON bits are writable))

#pragma config FSLEEP = OFF // Flash Sleep Mode (Flash is powered down when the device is in Sleep mode)

#pragma config DBGPER = ALLOW_PG2 // Debug Mode CPU Access Permission (Allow CPU access to Permission Group 2 permission regions)

#pragma config EJTAGBEN = NORMAL // EJTAG Boot (Normal EJTAG functionality)


// DEVCP0

#pragma config CP = OFF // Code Protect (Protection Disabled)


// SEQ0


// DEVADC1


// DEVADC2


// DEVADC3


// DEVADC4


// DEVADC5


  The second, T32 implementation in T32.c (the 32-bit timer is set to overflow and make interrupt every second).



void T32_Init(void)

{

    T2CON = 0x0;

    T3CON = 0x0;

    TMR2 = 0;

    TMR3 = 0;

    

    IPC3SET = 0x50000;

    IEC0SET = 0x4000;

    IFS0CLR = 0x4000;

    

    PR3 = 0x05F5;

    PR2 = 0xE100;


    T2CON = 0x8008;

}


void T32_Write(unsigned long value)

{

    TMR3 = (unsigned int)(value>>16);

    TMR2 = (unsigned int)value;

}


unsigned long T32_Read(void)

{

    return (((unsigned long)TMR3 << 16) | TMR2);

}


  The last, main function and interrupt service routine.



#include

#include "T32.h"

#include "CFB.h"


#define LED_IOCTL()       TRISHCLR = (1<<0)

#define LED_SETON()       LATHSET = (1<<0)

#define LED_SETOFF()      LATHCLR = (1<<0)

#define LED_ONOFF()       LATHINV = (1<<0)

#define LED_OPEN()        ANSELH &= 0xFFFFFFFE


#define Mvec_Interrupt() INTCONSET = 0x1000; asm volatile("ei")


void __ISR(_TIMER_3_VECTOR,ipl1AUTO) T32_Handler(void)

{

    LED_ONOFF();

    T32_Write(0);

    IFS0CLR = 0x4000;

}

void main(void)

{

    LED_OPEN();

    LED_IOCTL();

    T32_Init();

    Mvec_Interrupt();

    while(1)

    {

        ; // do nothing

    }

}


关键字:PIC32MZ  tutorial  32-bit  Timer 引用地址:PIC32MZ tutorial -- 32-bit Timer

上一篇:PIC32MZ tutorial -- Input Capture
下一篇:PIC32MZ tutorial -- Change Notification

推荐阅读最新更新时间:2024-03-16 15:31

[AVR应用]Timer1测量正向脉冲的宽度
#include mega16.h #include delay.h #define ICP PIND.6 sfrw ICR1=0x26; flash const unsigned char tabel ={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}; unsigned char ledbuff ={0x8c,0x8c,0x8c,0x8c,0x8c,0x8c}; unsigned char ov_counter; //counter for timer1 overflow unsigned int rising_edge,falling_edge; //storag
[单片机]
NO.14 MSP432定时器Timer的使用
  什么是定时器?定时器其实就在我们生活中的方方面面。   在老式的电风扇,都是用旋钮作为人机交互的方式。其中有一个旋钮就是定时关机。当我们把旋钮扭到某一个位置的时候,风扇的机械计时结构就会开启倒计时。等到时间一到,你的风扇就断电了。这就是定时器。   再比如你晚上去睡觉,你调了手机的倒计时,选择你要睡的时长,这时候你人放心的去睡觉,等倒计时一到,手机就会提示。这也是定时器。   所以说,定时器其实很简单。比如说你的单片机要设置一个定时器功能,首先你要像以前旋钮定时关风扇一样,选择好你要时间,然后开启定时功能。在开启定时功能的时候,你的CPU可以干别的事情,就像你睡觉前设定时器,不可能你一晚上都盯着手机看,你人可以去做
[单片机]
PIC16F877A单片机 (中断与定时器Timer0)
1 基本原理 2 实现代码 主要根据FIGURE 5-1 和中断的逻辑框图来编写代码,这样代码的可读性强,也便于理解。但有些寄存器在框图中可能没有说明,所以也需要仔细阅读定时器0的官方文档,即基本原理部分。 /*----------------函数功能: 中断 定时器0 --------------------------*/ #include pic.h // 调用PIC16f87XA单片机的头文件 //#include delay.h //调用延时子函数 __CONFIG(0xFF32);//芯片配置字,看门狗关,上电延时开,掉电检测关,低压编程关 //__CONFIG(HS&WDTDI
[单片机]
PIC16F877A单片机 (中断与定时器<font color='red'>Timer</font>0)
PIC32MZ tutorial -- OC Interrupt
  In my previous blog PIC32MZ tutorial -- Output Compare , I shows how to apply Output Compare without interrupt to generate PWM signal. I also tried the Output Compare interrupt. I selected OC to be PWM mode without fault pin (OCM = 110 ) and enable its interrupt. Below is the initialization of OC. void OC1_Init(vo
[单片机]
对8051两个定时器(timer0和timer1)的使用解析
1.如何使用8051单片机内部的定时器timer0? #include STC89C5xRC.h void delay(int n) { int i; TMOD=0x01;//16bits for(i=0;i n;i++) { TH0=0x3C; TL0=0xB0; //12MHZ - 1MHZ - 0.05s=5*10^-2s - (5*10^-2)/(1*10^-6)=5*10^4 //65536-50000=15536=3CB0H TF0=0; TR0=1;//start the intern
[单片机]
单片机定时器工作模式0(timer013位定时器)
;定时器0工作模式0(13位的定时器),P1.1口接的是共阳极的LED灯运行结果是使led灯明一下,暗一下 ;定时 COUNT EQU 5000;定时一次也只能够定时5ms LED EQU P1.1 ORG 0000H MOV R0,#00H L0: DJNZ R0,L0 ;刚开始,先进行少量的延时,是各种工作寄存器准备好 MOV R1,00H ;作为定时器累加器使用 MOV A,TMOD ANL A,#11110000B;相与指令 CLR ACC.3 ;GATE=0,允许Timer操作 CLR ACC.2 ;为定时模式(C/T位为0):清零指令 CLR ACC.1 ;TIMER0 M1=0 CLR
[单片机]
工程师笔记|使用 TIMER 输出比较模式输出相移信号
1、前言 客户想要使用 STM32L031 产生两个特定的 PWM 波,这两个波形频率相同,占空比相同,但相位不同。经过验证,使用定时器的输出比较模式可以产生这种带相移的 PWM 波形。 下面以 STM32L031 的 TIM2 为例来介绍使用产生相移信号的方法。 2、概述 在未使能预装载寄存器时(OCxPE=0),使用输出比较模式,可以随时通过软件更新 TIM_CCRx 寄存器的值,以控制输出波形。 DMA 的循环模式,可以在最后一次数据传输完成后,自动重新加载初始编程值,内部地址寄存器会重新加载基址值,进入下一个循环。 使用输出比较模式配合 DMA 的循环模式可以不断更新 TIMx_CCR 寄存器的值,从而输出可控的波形。
[单片机]
MSP430单片机16 位定时器Timer_A 操作
/**********(一)定时器A 比较模式*************/ int main( void ) { WDTCTL=WDTPW+WDTHOLD; //关看门狗 BCSCTL1 =CALBC1_1M Hz ; //设定DCO 为1MHZ DCOCTL =CALBC1_1MHZ; P1DIR |=BIT0; //LED 使能 TACTL=TASSEL1+TACLR; //定时器A 时钟源为SMCLK,并清TAR CCTL0 |=CCIE; //CCR0 中断使能 CCR0 =50000; //计数值为50000 个SMCLK 周期 TACTL |=MC1; //启动定时器A 为连续计数模式 _BIS_SR(GIE+CP
[单片机]
小广播
添点儿料...
无论热点新闻、行业分析、技术干货……
设计资源 培训 开发板 精华推荐

最新单片机文章
何立民专栏 单片机及嵌入式宝典

北京航空航天大学教授,20余年来致力于单片机与嵌入式系统推广工作。

更多每日新闻
电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved