Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature currently requires accessing the site using the built-in Safari browser.
I will use FT60E211_RB it has 16bit timer2Hi,
Not sure whether your microcontroller supports CAPTURE feature. Just found a Chinese datasheet.
Most accurate approach:
* set up a 16bit timer/counter to count with 1MHz
* use CAPTURE method on both edges
* calculate CAPTURE_Falling - CAPTURE_Rising
Klaus
I want to use FMD MCU (FT60E211) to measure pulse width that generated from HC-SR04 ultrasonic sensor so looking for a simple code to startHi,
questions like:
* "is there anyone has experience with FMD MCU?"
* "can you help me?"
are useless. They just make the thread longer and longer.
--> just provide all informations about your situation
--> then ask detailed, elaborated questions.
Informations we need:
* a link to an English datasheet
* your IDE, language, compiler
* your SW approach. At least a flow chart ... or a clear description. A sketch often is better than a lot of words.
* what is clear so far?
Question:
* what exactly is the problem?
****
We don´t know whether you never had a resistor in your hand ... whether you are experiened in programming, ...whether you have difficulties in understanding
datasheets.
We can´t replace school. We won´t do the whole engineering job for you.
But we can help you rectify some detailed problems.
Klaus
//*********************************************************
/* ÎļþÃû£ºTest_60F21X_Timer2.c
* ¹¦ÄÜ£º FT60F21X_Timer2¹¦ÄÜÑÝʾ
* IC: FT60F21X SOP8
* ¾§Õñ£º 16M/4T
* ˵Ã÷£º µ±DemoPortInÐü¿Õ»òÕß¸ßµçÆ½Ê±,
* DemoPortOutÊä³ö2.5KHzÕ¼¿Õ±È50%µÄ²¨ÐÎ-Tm2ʵÏÖ
* µ±DemoPortIn½ÓµØÊ±,DemoPortOutÊä³ö¸ßµçƽ.¹Ø¶¨Ê±Æ÷
*/
//===========================================================
//===========================================================
#include "SYSCFG.h";
#include "FT60F21X.h";
#define unchar unsigned char
#define unint unsigned int
#define unlong unsigned long
//===========================================================
//
// ϵͳʱÖÓ
//===========================================================
#define OSC_16M 0X70
#define OSC_8M 0X60
#define OSC_4M 0X50
#define OSC_2M 0X40
#define OSC_1M 0X30
#define OSC_500K 0X20
#define OSC_250K 0X10
#define OSC_32K 0X00
#define DemoPortOut RA4
#define DemoPortIn RA2
//===========================================================
//±äÁ¿¶¨Òå
//===========================================================
//===========================================================
//Funtion name£ºinterrupt ISR
//parameters£ºÎÞ
//returned value£ºÎÞ
//===========================================================
void interrupt ISR(void)
{
//¶¨Ê±Æ÷2µÄÖжϴ¦Àí**********************
if(TMR2IE && TMR2IF) //200usÖжÏÒ»´Î = 2.5KHz
{
DemoPortOut = ~DemoPortOut; //·×ªµçƽ
TMR2IF = 0;
}
}
/*-------------------------------------------------
* º¯ÊýÃû£ºPOWER_INITIAL
* ¹¦ÄÜ£º Éϵçϵͳ³õʼ»¯
* ÊäÈ룺 ÎÞ
* Êä³ö£º ÎÞ
--------------------------------------------------*/
void POWER_INITIAL (void)
{
OSCCON = OSC_16M; // bit7 Timer2 Ñ¡ÔñLIRCΪʱÖÓԴʱ LIRCµÄƵÂÊÑ¡Ôñ 0:32KHz 1:256KHz
//bit[6:4] ϵͳƵÂÊÑ¡Ôñ
//bit[2] ¸ßËÙÄÚ²¿Ê±ÖÓ״̬ 1:ready 0:not ready
//bit[1] µÍËÙÄÚ²¿Ê±ÖÓ״̬ 1:ready 0:not ready
INTCON = 0; //ÔݽûÖ¹ËùÓÐÖжÏ
OPTION = 0;
TRISA = 1<<2; //1:ÊäÈë 0:Êä³ö
PSRCA = 0; //00: 4mA 01/10: 8mA 11: 28mA bit[3:2]¿ØÖÆPA5Ô´µçÁ÷ bit[1:0]¿ØÖÆPA4Ô´µçÁ÷
PSINKA = 0; //bit[1:0] ¿ØÖÆPA5ºÍPA4 0:¹àµçÁ÷×îС 1:¹àµçÁ÷×î´ó
PORTA = 0; //1:PAxÊä³ö¸ßµçƽ 0:PAxÊä³öµÍµçƽ
WPUA = 1<<2; //1: ʹÄÜPA¿ÚÉÏÀ 0:¹Ø±ÕPA¿ÚÉÏÀ
}
/*-------------------------------------------------
* º¯ÊýÃû³Æ£º TIMER2_INITIAL
* ¹¦ÄÜ£º ³õʼ»¯ÉèÖö¨Ê±Æ÷1
* Ïà¹Ø¼Ä´æÆ÷£ºT2CON TMR2 PR2 TMR2IE TMR2IF PEIE GIE
-------------------------------------------------*/
void TIMER2_INITIAL (void)
{
T2CON0 = 0B00000001; //Bit[1,0]=01,T2ʱÖÓ·ÖÆµ 1:4
//Bit[6-3]=0000,T2Êä³öʱÖÓ·ÖÆµ1:1
T2CON1 = 0B00001000; //Bit[2:0] 000: Ö¸ÁîÖÜÆÚ 100:HIRC Timer2ʱÖÓÔ´Ñ¡Ôñ
TMR2H = 0;
TMR2L = 0; //TMR2¸³³õÖµ
PR2H =0;
PR2L = 200; //ÉèÖÃTMR2Êä³ö±È½ÏÖµ¶¨Ê±200us=(1/16000000)*4*4*200(PR2)
//16M-4T-4·ÖƵ
TMR2IF = 0; //ÇåTIMER2ÖжϱêÖ¾
TMR2IE = 1; //ʹÄÜTIMER2µÄÖжÏ
TMR2ON = 1; //ʹÄÜTIMER2Æô¶¯
PEIE=1; //ʹÄÜÍâÉèÖжÏ
GIE = 1; //ʹÄÜÈ«¾ÖÖжÏ
}
/*-------------------------------------------------
* º¯ÊýÃû: main
* ¹¦ÄÜ£º Ö÷º¯Êý
* ÊäÈ룺 ÎÞ
* Êä³ö£º ÎÞ
--------------------------------------------------*/
void main()
{
POWER_INITIAL(); //ϵͳ³õʼ»¯
TIMER2_INITIAL(); //³õʼ»¯T2
while(1)
{
if(DemoPortIn == 1) //ÅжÏÊäÈëÊÇ·ñΪ¸ßµçƽ
{
TMR2IE = 1; //¿ª¶¨Ê±Æ÷2
}
else
{
TMR2IE = 0; //¹Ø¶¨Ê±Æ÷2
DemoPortOut = 1;
}
}
}
//===========================================================
I want to use FT60E211 to measure high pulse width range 150us to 25ms
is there an example?