Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Fan Controller - PIC16F871

Status
Not open for further replies.

Omar.M

Member
Hello,
I was building a small fan controller for my computer's case using PIC16F871, writing the code in ASM. I pieced together bits and pieces of code from the net, but suddenly it stopped working-- I must have made a change that killed it.

I backtracked all the way down to the bare minimum code, still unable to find the problem. I am sure it is a silly little mistake that I just cannot pick up. Any help is appreciated!

I am using LEDs to test it, outputting the three fan signals to PORTB0, 1 and 2. The interrupt should be occurring at 250 Hz, however, each LED is on for a few seconds, then the next LED turns on, and so on. This leads me to believe that the TMR1 was setup incorrectly. But I've double checked! I tried a different chip and even new XT OSC. No luck!

Code:
						;16F871, 4mHz EXT OSC	
	list P=16F871
	#include <p16F871.inc>
	
	cblock		20h
		pwmwar, dutycycle1, dutycycle2, dutycycle3
	endc
	
	org	0x0000
	goto	Init

	ORG	0x0004
							;Turn off interrupts
		BCF		INTCON, 7
		BCF		PIR1, 0

							;If fan1 is less than the value of PWM Var, keep it on. Else, set it off.
 		BSF     STATUS, C
        MOVF    dutycycle1, W
        SUBWF   pwmwar, W

        BTFSS   STATUS, C
        BSF     PORTB, 0
        BTFSC   STATUS, C
        BCF     PORTB, 0

							;If fan2 is less than the value of PWM Var, keep it on. Else, set it off.
        BSF     STATUS, C
        MOVF    dutycycle2, W
        SUBWF   pwmwar, W

        BTFSS   STATUS, C
        BSF     PORTB, 1
        BTFSC   STATUS, C
        BCF     PORTB, 1
				
							;If fan3 is less than the value of PWM Var, keep it on. Else, set it off
        BSF     STATUS, C
        MOVF    dutycycle3, W
        SUBWF   pwmwar, W

        BTFSS   STATUS, C
        BSF     PORTB, 2
        BTFSC   STATUS, C
        BCF     PORTB, 2

							;Increase PWM Variable. If it has reached 100, reset it.
        INCF    pwmwar, F
        MOVF    pwmwar, W
        SUBLW   d'100'
        BTFSC   STATUS, Z
        CLRF    pwmwar
		BSF		INTCON, 7
	retfie

Init
							;Set TMR1 interrupt. Approximately 4000uS.
	MOVLW	0x5F
	MOVWF	TMR1L
	MOVLW	0xF0
	MOVWF	TMR1H
	MOVLW	0x1
	MOVWF	T1CON
	MOVLW	0xC0
	MOVWF	INTCON

	bsf		STATUS,RP0		;bank 1
	clrf	TRISB			;Set PORTB as outputs
	BSF		PIE1, 0
	bcf		STATUS,RP0

							;Set PWM Variable to 1
	MOVLW	0x1
	MOVWF	pwmwar

start
							;Setting dutycycles for each of the fans.
	MOVLW	d'99'
	MOVWF	dutycycle1
	MOVLW	d'1'
	MOVWF	dutycycle2
	MOVLW	d'50'
	MOVWF	dutycycle3
	goto	start
	end

-Omar
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top