RPM of CPU fan PIC12f683


Closed Thread
Results 1 to 4 of 4

Hybrid View

  1. #1
    Join Date
    Sep 2012
    Posts
    2

    Default RPM of CPU fan PIC12f683

    Greetings all,

    This is my first post to this forum but I will try to stay within guidelines for posting. Basically, I am using the PIC12F683 to read the RPM signal from a CPU fan. Have any of you done this before? I am not very experienced with programming PICS but have done this same application using another chip. Also, I am writing the code with a C compiler in MPLABX.

    Datasheet for this PIC- http://ww1.microchip.com/downloads/e...oc/41211d_.pdf

    Below is the code I have completed so far. I 'think' that I should be getting the value of the time so I solved for the RPM of the fan. The only problem now is how could I output it in voltage? Do I need an A/D to do this? (tried in code already) If so any hints on how the code should be written? Also, feel free to edit my code if you feel generous. I enabled the global interrupt and have set everything up to receive a value from the CPU fan. Am I anywhere near being able to read the RPM? I have followed the datasheet and tried my best. I need to complete this code so I can use it for another similar application.

    Code:
    #include <pic.h>
    #ifndef _XTAL_FREQ
     // Unless already defined assume 4MHz system frequency
     // This definition is required to calibrate __delay_us() and __delay_ms()
     #define _XTAL_FREQ 8000000
    #endif
    
    __CONFIG(FCMEN_OFF & IESO_OFF & MCLRE_OFF & WDTE_OFF & FOSC_INTOSCIO);
    
    unsigned long t1; // 16 bit number
    unsigned short int i; // counter
    unsigned short int stringLength;
    unsigned long sps;
    unsigned long output;
    unsigned char input;
    
    void config(){
        T1CON = 0b00110001; // enable timer1
        CCP1CON = 0x05; // capture rising edge
        INTCON = 0b11000000; // enable global/periph interrupt
        PIE1 = 0b00100000; // enable CCP interrupt
        TRISIO = 0x01; // gpio 2 pin (rising edge)
    
        ANSEL=0b01110001; // A/D pin
        ADCON0=0b00000001; // A/D setup
    }
    
    void inter(void){
    //respond to CCP interrupt
        
        INTCON = 0; // disable interrupts
        PIR1 = 0; // periph interrupt flag reset
        t1 = TMR1H;
        t1 = t1 << 8; // shift 8 bits
        t1 = t1 | TMR1L; //t1 long
        sps = t1 * 2; // time * 2 = speed per second
        output = sps * 60; // sps * 60hz = output
    
    
        // output in voltage here (not sure I am doing it right
        ADCON0bits.GO_DONE=1; // not sure about this
        input=ADRESH;
        CCPR1L = input;
        
        INTCON = 0b11000000; // re-enable the interrupt again
    }
    
    void main() {
        // set up output here
        config();
        while(1){
            // NOT SURE IF I NEED THIS LOOP YET
        }
    
    }
    Last edited by mrmodest; - 2nd September 2012 at 23:21.

  2. #2
    Join Date
    Nov 2008
    Posts
    60


    Did you find this post helpful? Yes | No

    Default Re: RPM of CPU fan PIC12f683

    It seems that your code is in C. What compiler are you using?
    Regards
    CharlieM
    Using PBP3
    MCSPX

  3. #3
    Join Date
    Sep 2012
    Posts
    2


    Did you find this post helpful? Yes | No

    Default Re: RPM of CPU fan PIC12f683

    I am using the hitech ansii c compiler. It is the free version of it.

  4. #4
    Join Date
    Jul 2003
    Location
    USA - Arizona
    Posts
    156


    Did you find this post helpful? Yes | No

    Default Re: RPM of CPU fan PIC12f683

    Have you tried the HiTech forum: http://forum.htsoft.com/all/ubbthreads.php ?

Members who have read this thread : 3

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts