Heat - Fan Controller Project (PIC16F88)

Discussion in 'Programmer's Corner' started by Refugees, Nov 19, 2012.

  1. Refugees

    Thread Starter New Member

    Nov 19, 2012
    1
    0
    Hi there.

    I am currently in the progress of of making myself a stand with a fan for my laptop.
    I am using a PIC16F88, Thernistor 4k7 and a 5V Fan, with a home made plastic base.
    I am using a Pickit 3.

    My board is finished and the layout is as follows:
    * Terminator --> RA2 / AN2 Port
    * Fan ----> RB0 / CCP1 Port

    MPLAB programming and I am struggling heavily.
    Here is my code so far, I cannot go any further as I don't know the rest:

    Code ( (Unknown Language)):
    1.  
    2. ;List all PIC16F88 Files that are needed to run the program
    3.  
    4. List p=PIC16F88
    5. #INCLUDE <P16F88.INC>
    6.  
    7. __CONFIG    _CONFIG1, _CP_OFF & _CCP1_RB0 & _DEBUG_OFF & _WRT_PROTECT_OFF & _CPD_OFF & _LVP_OFF & _BODEN_OFF & _MCLR_ON & _PWRTE_OFF & _WDT_OFF & _INTRC_IO
    8. __CONFIG    _CONFIG2, _IESO_OFF & _FCMEN_OFF
    9.  
    10.     ORG 0x0000                  ;Force program to start at address 0
    11.     goto start                  ;Go to the start loop
    12.  
    13. ;----------------------------------------------------------------------------- 
    14. ;Interrupt - Motor Speed Control
    15.  
    16. ISR:                            ;Interrupt
    17.  
    18.     bcf PIR1,ADIF           ;Clear AD interrupt flag
    19.     bsf     STATUS,RP0          ;Go to bank 1
    20.     movlw   b'00000000'         ;Making all TRISB pins outputs
    21.     movwf   TRISB               ;Get to TRISB
    22.     moVLW   ADRESH              ;ADC result byte
    23.     movwf   PR2                 ;Period register
    24.         bcf     STATUS,RP0          ;Go to back 0
    25.         movlw   b'00001100'         ;Set control register pins
    26.     movwf   CCP1CON             ;PWM control register
    27.     bsf     T2CON, TMR2ON       ;Swtches on timer
    28.     movlw   .100                ;Set the speed of the motor
    29.     movwf   CCPR1L              ;PWM low byte
    30.    
    31. retfie
    32.  
    33. ;----------------------------------------------------------------------------- 
    34. ;Start of the inital program
    35.  
    36. start:                          ;Begin the start loop
    37.  
    38.     bsf     INTCON,PEIE         ;Set interrupt enable
    39.     bsf PIE1,ADIE           ;Set AD interrupt enable
    40.         nop                         ;No operation
    41.     bsf     STATUS,RP0          ;Go to bank 1
    42.         movlw   b'00000001'         ;Set TRISA pins
    43.         movwf   TRISA               ;Set pins in TRISA
    44.         movlw   b'10111111'         ;Set TRISB pins
    45.     movwf   TRISB               ;Set pins in TRISB
    46.     bsf INTCON,GIE          ;Global interrupt enable
    47.  
    48. ;-----------------------------------------------------------------------------
    49. ;Analog to Digital Converter
    50.  
    51.     clrf    ANSEL               ;Clear analog select
    52.  
    53.     movlw   b'00000100'         ;Set pin to analog
    54.     movlw   ANSEL               ;Analog pin select register
    55.  
    56.     movlw   b'10000000'         ;Reference voltage to external pins
    57.     movwf   ADCON1              ;ADC control register
    58.  
    59.     movlw   b'10000101'         ;Reference voltage to external pins
    60.     movwf   ADCON0              ;ADC control register
    61.  
    62. ;----------------------------------------------------------------------------- 
    63. ;Motor Speed Control
    64.  
    65. ;    btfss  ADCON0,GO_DONE      ;This bit will change to zero when the conversion is complete  
    66. ;    goto   $-1                 ;So loop till it does.
    67.  
    68. ;-----------------------------------------------------------------------------
    69. ;End of Program
    70.  
    71.     goto $                      ;Endless loop
    72.  
    73.     end                         ;End the program
    Can someone please help me to finish my code
    I would love to see my fan in action

    Thanks so much!
    Refugees
     
  2. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    I can tell you one thing after briefly looking at your code...

    Your A/D result should not be going into the PR2 register. The PR2 register sets your PWM frequency and should be left alone after initialization, unless you mean to be changing your frequency. If you are trying to change your frequency, then you probably need to go back through PWM again. ;)

    Your result should be going to the CCPR1L register and to the CCP1CON<5:4> bits as stated in the PIC16F88 datasheet pg. 86.

    Also, you are going to need to setup your CCP module, look at pages 86 & 87....
     
    Last edited: Nov 19, 2012
  3. John P

    AAC Fanatic!

    Oct 14, 2008
    1,632
    224
    I'm very reluctant to get into someone else's assembly code, even if you have used the <code> tags and written a literate message. This would be a lot easier if you started using a compiler.

    But one thing I noticed immediately--shouldn't the interrupt start with
    ORG 0x0004

    ?
     
  4. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    I have to agree with this. The only reason I even looked at your code, OP, is because you named the registers so as to be readable... :)

    The XC8 compiler from Microchip has a free version based off of the older HiTech compiler. It is quite nice and allows you to program your μC in C as opposed to assembly...

    Yes, it should.. I missed that when I looked at this...
     
  5. nigelwright7557

    Senior Member

    May 10, 2008
    487
    71
    btfss ADCON0,GO_DONE ;This bit will change to zero when the conversion is complete
    ; goto $-1 ;So loop till it does.

    this should be btfsc.
     
Loading...