help with 16f877A using C

Discussion in 'Embedded Systems and Microcontrollers' started by aza2, Apr 14, 2012.

  1. aza2

    Thread Starter New Member

    Apr 12, 2012
    4
    0
    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.
     
  2. hexreader

    Active Member

    Apr 16, 2011
    250
    82
    Which C compiler(s) are available for you to use?

    I can only help with mikroC - maybe
     
  3. chrisw1990

    Active Member

    Oct 22, 2011
    543
    41
    more info would be appreciated
     
  4. aza2

    Thread Starter New Member

    Apr 12, 2012
    4
    0
    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.
     
  5. chrisw1990

    Active Member

    Oct 22, 2011
    543
    41
    use input capture module.. and measure the timeperiod, then 1/t is the frequency..
     
  6. aza2

    Thread Starter New Member

    Apr 12, 2012
    4
    0
    I m new in microcontroller so i dont know how to use capture module.
     
  7. chrisw1990

    Active Member

    Oct 22, 2011
    543
    41
    ok, what compiler suite are you using?
     
  8. aza2

    Thread Starter New Member

    Apr 12, 2012
    4
    0
    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;
    }
     
  9. chrisw1990

    Active Member

    Oct 22, 2011
    543
    41
    use code tags, its the little hash (#) in the reply box..
    why have you got the *?
     
  10. chrisw1990

    Active Member

    Oct 22, 2011
    543
    41
    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.
     
Loading...