Pulse Capture 50% duty, varying Freq

Hi All

I have built a data logger type of “Black Box” to be installed on a boat.

I’m using a BL4S200 in a waterproof housing,

We want to record wind speed and I have modified a standard wind instrument so that I can get a raw signal from the anomemeter. This signal is a square wave, 2 pulses per revolution. It is 50 % duty cycle pulse, with the frequency increasing with wind speed. So low wind speeds the frequency on only a few Hz, and a few hundred Hz at high wind speeds.

I have tried getBegin() and getEnd() functions, using DIO1, but not having much success.

I looked at the sample IC_Test.C but could not figure out how to access PC5 as on the BL4S200 this port/bit seems to go to the RIO chip.

The following code is what I created to test capturing a 50% duty square wave from DIO1 (taken from the sample file pulse_capture.c as found in the BlxS200/DIO directory

I’m not a great programmer, more of a technican. But struggling through Dynamic C.

Any advise appreciated

/******************************************

	This sample program was created from  code within

   samples/blxs200/DIO/pulse_capture.c

*********************************************/

#class auto
#use "BLxS2xx.lib"
#define USE_PRESCALE BL_PRESCALE

// set the STDIO cursor location and display a string
void DispStr(int x, int y, char *s)
{
   x += 0x20;
   y += 0x20;
   printf ("\x1B=%c%c%s", x, y, s);
}

void main()
{
   int i;
   word begin;
   word end;
   char pulse_width[80];

   // Initialize the controller
	brdInit();

 // Setup input capture for begin=rise & end=fall on the same channel
 setCapture(1, BL_CNT_RUN, BL_EVENT_RISE,
	                 BL_SAME_CHANNEL | BL_EVENT_FALL | USE_PRESCALE);
   i = 0;
	while (i < 10000)
	{
   		resetCounter(1);
	      getBegin(1, &(begin));
	      getEnd(1, &(end));

      // Display current captured begin and end values from pulses
      sprintf(pulse_width,"%d, 	 Ch. 0 Begin = %u, End = %u,  Diff = %u 
",
      		i,
                 begin,
                 end,
      		(begin - end)
                 );

     DispStr(1,2,(pulse_width));
     i = i+1;
	}
}

Also

I was having trouble finding any referance to the functions

setCounter()
GetBegin()
getEnd()
resetCounter() etc …

in the Dynamic C 4000, 5000, 6000, reference manual.

You will find the documentation for these functions in the BL4S200 user manual as they are in board specific libraries.

Regards,
Peter

Ahhhh …

I thought I had downloaded that manual but, revisiting the DIGI web site, I have now found a manual with descriptions of those functions.

Thanks for the direction Peter

Simon

OK, So I have spent some time with the correct manual,

But am still having some difficulty.

I can use the setCounter() function effectively, and as I increase frequency of my 50% duty cycle square wave from about 80hz to 10 K hz I see the counter increase in speed.

But If trying setCapture() to read the width of a single pulse I seem to just get some noise.

Attached here are the very simple bits of code I’m using to test this.

Here is the code I’m using to test the hardware, and the fact that I’m actually reading in the pulses to DIO1

This works fine and I see the counter output speed increase as I increase the speed (frequency from about 80 hz to 10K hz).


 #class auto 
#use "BLxS2xx.lib"  

void main()
 {     
word wind;  	

brdInit();    
setCounter(1, BL_UP_COUNT, BL_EDGE_RISE, BL_EDGE_RISE);

  	while (1) 	{ 			

      getCounter (1, &(wind));         	
       printf("%u 
", wind );  	
       } 
}

However when I try to read the length of a single pulse using setCapture() I just seem to get noise.

The Begin and End numbers are within 1, regardless of my change in input frequency of my 50% duty cycle square wave (5vdc P)

Is there some issue with using PRESCALE or RIO_FREQ that I’m not understanding ?


#class auto
#use "BLxS2xx.lib"

void main()
{

   word begin;
   word end;
   word wind;
   char pulse_width[80];

   // Initialize the controller
	brdInit();

 // Setup input capture for begin=rise & end=fall on the same channel
 setCapture(1, BL_CNT_BEGIN_END, BL_EVENT_RISE, BL_SAME_CHANNEL | BL_EVENT_FALL|  BL_PRESCALE );

	while (1)
	{
              resetCounter(1);
	      getBegin(1, &(begin));
	      getEnd(1, &(end));
	      getCounter (1, &(wind));
         
      sprintf(pulse_width,"Ch. 1 Begin = %u, End = %u,  Diff = %u  Wind = %u 
",
                  begin,
                  end,
                  (end - begin),
                  wind
                  );

     printf(pulse_width);

	}
}