日本黄色一级经典视频|伊人久久精品视频|亚洲黄色色周成人视频九九九|av免费网址黄色小短片|黄色Av无码亚洲成年人|亚洲1区2区3区无码|真人黄片免费观看|无码一级小说欧美日免费三级|日韩中文字幕91在线看|精品久久久无码中文字幕边打电话

當(dāng)前位置:首頁(yè) > 單片機(jī) > 單片機(jī)
[導(dǎo)讀]  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

  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 = 0;

TMR3 = 0;

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 = 0;

unsigned int i;

for ( i = 0; i < SIZE_MAX; i++)

{

IC1_ST.buf[i] = 0;

}

IC1CON |= 0x8000;

}


unsigned long IC1_ReadCapture(void)

{

while ((IC1CON & 0x8) == 0x8)

{

if (IC1_ST.count == SIZE_MAX)

{

IC1_ST.count = 0;

}

IC1_ST.buf[IC1_ST.count++] = IC1BUF;

}

}


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



#include

#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(1)

{

; // 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.


本站聲明: 本文章由作者或相關(guān)機(jī)構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點(diǎn),本站亦不保證或承諾內(nèi)容真實(shí)性等。需要轉(zhuǎn)載請(qǐng)聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請(qǐng)及時(shí)聯(lián)系本站刪除。
換一批
延伸閱讀

Microchip公司的PIC32MZ EF系列是高達(dá)250MHz的集成浮點(diǎn)單元(FPU),具有廣泛的外設(shè)和包括局域網(wǎng)(CAN)的極好的連接選擇,工作電壓2.1V到 3.6V,DSP增強(qiáng)核具有四

關(guān)鍵字: Microchip pic32mz 處理器

  An interrupt is an internal or external event that requires quick attention from the controller. The PIC32MZ...

關(guān)鍵字: interrupt pic32mz timer tutorial

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

關(guān)鍵字: pic32mz tutorial change notification

/*Capture mode時(shí),外部CCP1事件觸發(fā)后,CCPR1H和CCPR1L將獲取Timer1的TMR1H和TMR1L中的數(shù)值對(duì)于CCP1的觸發(fā)事件,設(shè)置鍵CCP1Con中的相應(yīng)位CCP1M3--CCP1M0CCP...

關(guān)鍵字: capture mode pic16f877a

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

關(guān)鍵字: interrupt pic32mz tutorial external

Windows CE Features > InternationalMicrosoft? Windows? CE includes the Input Method Manager (IMM)

關(guān)鍵字: input manager

經(jīng)過(guò)千辛萬(wàn)苦,今天終于完工PIC32MZ EC Starter Kit的ethernet bootloader項(xiàng)目。我將整個(gè)項(xiàng)目, 命名為PhnBootloader。它分為兩個(gè)部分。第一個(gè)部分是PC 端的host程序Ph...

關(guān)鍵字: bootloader ethernet pic32mz udp協(xié)議

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

關(guān)鍵字: communication pic32mz tutorial uart

  Core Timer is a very popular feature of PIC32 since it isa piece of the MIPS M4K core itself and is common t...

關(guān)鍵字: core pic32mz timer tutorial

  The microcontroller is PIC32MZ2048ECH144 on the PIC32MZ EC Starter Kit. This microcontroller has four 32-bit...

關(guān)鍵字: pic32mz timer tutorial 32-bit
關(guān)閉