Julius Fernandez

Help: Input Capture to measure frequency

Discussion created by Julius Fernandez on May 2, 2007
Latest reply on May 3, 2007 by bigmac
I started a project using a MiniDragon+ (MC9S12DP256) to measure the frequency off a Siemens Flex Fuel sensor found in current GM model vehicles.  The sensor outputs a linear frequency from 50Hz-150Hz, where 50Hz is 0%ethanol and 150Hz is 100%ethanol.  In lab, we are using a function generator with a frequency any where from 50-150Hz to simulate the sensors output. We are getting the same values in TC1 and TC2 in the terminal. What are the units of TCx stored as? Does that mean IOC1 and IOC2 are capturing the same edges of the squrewave? I am not really clear on initializing the edges in TCTL4 register. Also here is a picture of the scope measuring California 91octane (10%).Code:
#include "hcs12.h"#include "DBug12.h"#include "vectors12.h"#include "delay.c"main( ){      unsigned int time, first, second, frequency, total;            TSCR1 = 0x80;                    //Bit 7 = 1 ;  turns on timer sub system      TSCR2 = 0x03;                       //Overflow time      //Sets up IOC1      TIOS =0x00;                 //Enables IOC1      TCTL4 = 0x14;                       //Selects edge to capture      TFLG1 = 0x02;      //Sets up IOC2      TIOS = 0x00;   //Enables IOC2      TCTL4 = 0x14;                       //Selects edge to capture      TFLG1 = 0x04;               while(( TFLG1 & 0x02) == 0);        //waits for 1st rising edge      first = TC1;                        //Reads time of 1st edge      while(( TFLG1 & 0x04) == 0);        //waits for second rising edge      second = TC2;                       //Reads time of 2nd edge.      total = second - first;      frequency = 1/total;      DB12FNP->printf("TC1 = %d \n \n",first);      DB12FNP->printf("TC2 = %d \n \n",second);      DB12FNP->printf("total = %d \n \n",total);      DB12FNP->printf("frequency = %d \n", frequency);                  return 0;      }
We are using Embedded GNU and Introduction to HCS12 by Hwang.

Message Edited by gda02 on 2007-05-0207:20 AM