PDA

View Full Version : RPM of CPU fan PIC12f683



mrmodest
- 2nd September 2012, 23:19
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 (http://ww1.microchip.com/downloads/en/devicedoc/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.



#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
}

}

c_moore
- 3rd September 2012, 00:12
It seems that your code is in C. What compiler are you using?

mrmodest
- 3rd September 2012, 02:12
I am using the hitech ansii c compiler. It is the free version of it.

languer
- 3rd September 2012, 04:12
Have you tried the HiTech forum: http://forum.htsoft.com/all/ubbthreads.php ?