help needed: motor speed control with pic chip and potentiometer

Discussion in 'Embedded Systems and Microcontrollers' started by Rene01, Nov 18, 2012.

  1. Rene01

    Thread Starter New Member

    Oct 31, 2012
    1
    0
    have been doing this small project for a short while. Using 4 LEDs, a potentiometer, PIC16f88 microcontroller. I am having some trouble with setting up the analogue to digital converter to run the motor and light up the LEDs as the motor runs faster
    Code ( (Unknown Language)):
    1. List p=PIC16F88
    2. #INCLUDE <P16F88.INC>
    3.  
    4. __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
    5. __CONFIG    _CONFIG2, _IESO_OFF & _FCMEN_OFF
    6.  
    7. ;-----------------------------------------------------------------------------
    8. ;Start of the inital program
    9.  
    10.   ORG 0x0000                    ;
    11.  
    12.   goto start                    ;Go to the start loop
    13.  
    14. start:                          ;Begin the start loop
    15.  
    16.     nop                         ;No operation
    17.     bsf STATUS,RP0              ;Go to bank 1
    18.     movlw b'00000001'           ;Set ping
    19.     movwf TRISA                 ;
    20.     movlw b'10111111'           ;
    21.     movwf TRISB                 ;
    22.  
    23. ;-----------------------------------------------------------------------------
    24. ;Analog to Digital Converter
    25.  
    26.     clrf ANSEL
    27.  
    28.     movlw b'00000100'           ;Set pin to analog
    29.     movlw ANSEL
    30.  
    31.     movlw b'00110000'           ;Ref Voltage to external pins
    32.     movwf ADCON1
    33.  
    34.     movlw .1                    ;AD format select bits
    35.     movwf ADFM
    36.  
    37.     movlw b'10000000'           ;Analog Clock
    38.     movwf ADCON0
    39.     bsf ADON,1                  ;ADC switch on
    40.  
    41. ;----------------------------------------------------------------------------- 
    42. ;Motor Speed Control
    43.  
    44.     bsf     STATUS,RP0          ;Go to bank 1
    45.     movlw   b'00000000'         ;Set the corrct Port
    46.     movwf   TRISB               ;Get to TRISB
    47. ;   movlw   .100                ;Set the speed of the motor
    48.     movf    ADRESH
    49.     movwf   PR2                 ;Period Register
    50.     bcf     STATUS,RP0          ;Go to back 0
    51.     movlw   b'00001100'         ;
    52.     movwf   CCP1CON             ;
    53.     bsf     T2CON, TMR2ON       ;
    54.     movlw   .100                ;Set the speed of the motor
    55.     movwf   CCPR1L
    56.    
    57. ;-----------------------------------------------------------------------------
    58. ;End of Program
    59.  
    60.      goto $                     ;Endless loop
    61.  
    62.      end                        ;End the program
    This is the code that i have so far

    Any assistance will be greatly appreciated
     
Loading...