help with 16f877A using C

Thread Starter

aza2

Joined Apr 12, 2012
4
hello,
i m new with microcontrollers, i have a project at university and i m facing problems implementing it, if someone could help me i would be grateful.
my project is:
i have square wave pulses as an input, every 30 seconds, i need to count how many pulses i have, multiply the number obtained by 120 and output it on a 5 digit 7 segment display.

thanks in advanced.
 

Thread Starter

aza2

Joined Apr 12, 2012
4
MikroC is great :)
The incoming pulses are being used to calculate the rpm of a motor. The rpm varies from 0 to 12000. The frequency of the pulses isnt a constant it varies with the motor. After the calculation of the rpm i want to output the value on a 5 digits 7 segment display.
 

Thread Starter

aza2

Joined Apr 12, 2012
4
I m using C language with mplab.
I thought of the algorithm using C++ cz i know C++
thats what i got:

#include <ctime>
#include <iostream.h>

int main()
do{

* * * int a=0; // a is used to count the number of pulses every 30 seconds

* * * int temp=0;*

* * * int b; // b contains the value to be outputted

* * * int d=1; // d is used to have an infinite loop

* * * int seconds = 30;

* * * time_t timeout = time(NULL) + seconds;

* * * do

* * * {

* * * * if( A==high) // I considered that A is the input and by high i mean 5V

* * * * a++; // counting pulses

* * * } while (time(NULL) < timeout);

* * * temp= a*120;

* * * b=temp;*

* * * B=b; // I considered B as the port for the output

}

while ( d=1 )
return 0;
}
 

chrisw1990

Joined Oct 22, 2011
551
easiest way is to use the capture module.. datasheet chapter 8.
it will give you accurate time periods, and allow you to do other stuff in between..
to get the frequency.. 1/T (t will be from the capture module)
then you can do your maths and outputting afterwards.
 
Top