Today I accomplish a simple application for PIC32MZ EC Starter Kit. This application uses Input Capture feature of PIC32MZ. The Input Capture module captures the 32-bit value of the selected Time Base registers when an event occurs at the ICx pin.  The timer source for each Input Capture module depends on the setting of the ICACLK bit in the CFGCON register. To change this bit, the unlock sequence must be performed. In the implementation I just use IC1 to capture the 32-bit timer with combining Timer2 and Timer3.

  First, see the 32-bit timer initialization.

void T32_Init(void)
{
T2CON = 0x0;
T3CON = 0x0;
TMR2 = ;
TMR3 = ; PR3 = 0xFFFF;
PR2 = 0xFFFF; T2CON = 0x8008;
}

  I use PPS to set RB14 as IC1. And I define a array IC1_ST.buf[] to store capture valure. there is a point to clarify. To set IC1CON, if using one sentence like "IC1CON = 0x8012;"  It will cause a input capture interrupt. It is not expectation. Instead of setting IC1CON with one sentence, I use two sentences like below.

  IC1CON = 0012;

  IC1CON |= 0x8000;

Enable IC1CON last then input capture works as expectation. For the detail, please see the interface of IC1.

// In IC.h
#define SIZE_MAX 20
typedef struct _IC_ST_t{
unsigned int count;
unsigned long buf[SIZE_MAX];
} IC_STR_t; extern IC_ST_t IC1_ST; void IC1_Init(void);
unsigned long IC1_ReadCapture(void); // In IC.c
IC_ST_t IC1_ST; void IC1_Init(void)
{
//AN9|RPB14|RB14 with digital IO, disable AN first
ANSELB &= 0xFFFFBFFF;
TRISBSET = 0x4000;
//Enable internal pull-up
CNPUBSET = 0x4000; // Interrupt with priority 7 and sub-priority 0
IPC1SET = 0x1C0000;
IFS0CLR = 0x40;
IEC0SET = 0x40;
// RPB14 set as IC1 with PPS
IC1R = 0x2;
IC1CON = 0x0102; IC1_ST.count = ;
unsigned int i;
for ( i = ; i < SIZE_MAX; i++)
{
IC1_ST.buf[i] = ;
} IC1CON |= 0x8000;
} unsigned long IC1_ReadCapture(void)
{
while ((IC1CON & 0x8) == 0x8)
{
if (IC1_ST.count == SIZE_MAX)
{
IC1_ST.count = ;
}
IC1_ST.buf[IC1_ST.count++] = IC1BUF;
}
}

  The final, see the main function and interrupt service routine.

#include <sys/attribs.h>
#include "T32.h"
#include "IC.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(_INPUT_CAPTURE_1_VECTOR,ipl7AUTO) IC1_Handler(void)
{
LED_ONOFF();
IC1_ReadCapture();
IFS0CLR = 0x40;
}
void main(void)
{
LED_OPEN();
LED_IOCTL();
T32_Init();
IC1_Init();
Mvec_Interrupt();
while()
{
; // do nothing
}
}

  On the PIC32MZ EC Starter Kit, RB14 connects to a push button. I push down this button with 1 Hz frequency. I can see my array IC1_ST.buf[] filled with values indicating a frequency of 1 Hz frequency in debug mode.

PIC32MZ tutorial -- Input Capture的更多相关文章

  1. PIC32MZ tutorial -- OC Interrupt

    In my previous blog "PIC32MZ tutorial -- Output Compare", I shows how to apply Output Comp ...

  2. PIC32MZ tutorial -- External Interrupt

    In my older blog "PIC32MZ tutorial -- Key Debounce", I shows how to acheive key debounce w ...

  3. PIC32MZ tutorial -- UART Communication

    At this moment, I accomplish the interface of UART communication for PIC32MZ EC Starter Kit. This in ...

  4. PIC32MZ tutorial -- Output Compare

    Output Compare is a powerful feature of embedded world. The PIC32 Output Compare module compares the ...

  5. PIC32MZ tutorial -- 32-bit Timer

    The microcontroller is PIC32MZ2048ECH144 on the PIC32MZ EC Starter Kit. This microcontroller has fou ...

  6. PIC32MZ tutorial -- Change Notification

    In my last post I implement "Key Debounce" with port polling, port polling is not very eff ...

  7. PIC32MZ tutorial -- Key Debounce

    Today I accomplish a application on PIC32MZ EC Starter Kit. The feature of application is to light u ...

  8. PIC32MZ tutorial -- Hello World

    Today I implement "Hello World" on PIC32MZ EC starter kit. The application of "Hello ...

  9. STM32 Timer : Base Timer, Input Capture, PWM, Output Compare

    http://www.cs.indiana.edu/~geobrown/book.pdf An example of a basic timer is illustrated in Figure 10 ...

随机推荐

  1. xcode armv6 armv7 armv7s arm64

    目前ios的指令集有以下几种: armv6 iPhone iPhone2 iPhone3G 第一代和第二代iPod Touch armv7 iPhone4 iPhone4S armv7s iPhone ...

  2. SVN 文件解锁

    之前一直一个人用svn,后来团队扩编,同事使用svn下载项目后.我却无法提交了,出现以下错误: locked in another working copy No lock on path (Stat ...

  3. springmvc工作原理以及源码分析(基于spring3.1.0)

    springmvc是一个基于spring的web框架.本篇文章对它的工作原理以及源码进行深入分析. 一.springmvc请求处理流程 二.springmvc的工作机制 三.springmvc核心源码 ...

  4. jQuery UI Autocomplete是jQuery UI的自动完成组件(share)

    官网:http://jqueryui.com/autocomplete/ 以下分享自:http://www.cnblogs.com/yuzhongwusan/archive/2012/06/04/25 ...

  5. JDK源码解读之toUnsignedString

    我们知道,所有整数都是通过二进制编码的形式存储在内存中的.比如32位的整数,最高位是符号位,0代表正数,1代表负数. 那么怎么才能够将整数的二进制编码形式打印出来呢?Integer类提供了一个公有静态 ...

  6. pods的安装和使用

    ////  pods的安装.h//  IOS笔记 /*Cocoapods安装步骤 1.升级Ruby环境 终端输入:$gem update --system 此时会出现 ERROR:  While ex ...

  7. MPI运行程序(接触)

    网友遇到的问题并解决问题:mpich2在多个节点上运行并行程序时出错 我使用mpich2时遇到一下问题: 当我运行一个计算圆周率的并行程序cpi.c时,我想在指定的若干个节点上运行这个程序,比如hos ...

  8. unbuntu server (linux系统)下面安装 lamp

    1.sudo apt-get update 2.sudo apt-get install apache2 3.检查是否安装成功: apache2 -v 4.sudo apt-get update ph ...

  9. html5-websocket初探

    HTML5规范在传统的web交互基础上为我们带来了众多的新特性,随着web技术被广泛用于web APP的开发,这些新特性得以推广和使用,而websocket作为一种新的web通信技术具有巨大意义. 什 ...

  10. 每日学习心得:$.extend()方法和(function($){...})(jQuery)详解

    2014-02-09 前言: 节后头两天上班,主要是调整工作状态.项目也不是很紧,趁着周末把年前遇到了一些关于JS和JQuery的一些问题给总结一下.主要是介绍JQuery的extend方法和(fun ...