controlling speed of multiple DC motors with single microcontroller

Discussion in 'Embedded Systems and Microcontrollers' started by Abdo_pc_dr, Sep 13, 2011.

  1. Abdo_pc_dr

    Thread Starter New Member

    Apr 3, 2010
    13
    0
    Need some help about this issue !
    I need to know how can I control 3 DC motors(Fans) speed using single micro-controller [PIC ]. each motor gonna have it's own speed and all of needs a supply of 36V while PIC needs only 5V.
     
  2. be80be

    Senior Member

    Jul 5, 2008
    431
    57
    Three channels of PWM and three motor drivers that can handle the motors
     
  3. nickelflipper

    Active Member

    Jun 2, 2010
    280
    35
    There are lots of PIC's with three or more hardware PWM modules. Take the PIC18f26k22 for instance, loads of timers and PWM's. Here is some code to adjust to your liking by changing the PRx register for frequency, and the CCPRxL and CCPRxH registers for duty cycle. Good luck.

    Code ( (Unknown Language)):
    1. ;;Set up the assembler options (Chip type, clock source, other bits and pieces)
    2.  LIST p=18F26K22, r=DEC
    3. #include <P18F26K22.inc>
    4.  CONFIG LVP = OFF, MCLRE = INTMCLR, PBADEN = OFF, CCP2MX = PORTB3, WDTEN = OFF, BOREN = OFF, FOSC = INTIO67
    5.  
    6. ;********************************************************************************
    7.  
    8. ;Set aside memory locations for variables
    9. ABCED    EQU    256
    10. ZEROX    EQU    257
    11.  
    12. ;********************************************************************************
    13.  
    14. ;Vectors
    15.     ORG    0
    16.     goto    BASPROGRAMSTART
    17.     ORG    8
    18.     retfie
    19.  
    20. ;********************************************************************************
    21.  
    22. ;Start of program memory page 0
    23.     ORG    12
    24. BASPROGRAMSTART
    25. ;Call initialisation routines
    26.     rcall    INITSYS
    27.  
    28. ;Start of the main program
    29.     bcf    TRISA,5,ACCESS
    30.     bcf    TRISC,1,ACCESS
    31.     bcf    TRISC,2,ACCESS        ;CCP1 default
    32.     bcf    TRISB,3,ACCESS        ;CCP2 with mux config PortB,3
    33.     bcf    TRISB,5,ACCESS        ;CCP3 default
    34.     bcf    TRISC,6,ACCESS
    35.     movlw    112                ;16MHz
    36.     movwf    OSCCON,ACCESS
    37.     bsf    OSCTUNE,PLLEN,ACCESS    ;enable 4xPLL for 16mips
    38. ;******** CCP1 *****************
    39.     movlw    12        ;std PWM mode
    40.     movwf    CCP1CON,ACCESS
    41.     movlw    0        ;16 MHz (PRx + 1)*1/16000000*TMRx prescale
    42.     movwf    PR2,ACCESS
    43.     movlw    0        ;D.C. 50% (CCPRxL:CCPxCON<5:4>)/4(PRx+1)
    44.     movwf    CCPR1L,ACCESS
    45.     bsf        CCP1CON,DC1B1,ACCESS
    46.     bcf        CCP1CON,DC1B0,ACCESS
    47.     bsf        T2CON,TMR2ON,ACCESS        ;no prescale
    48. ;******** CCP2 *****************
    49.     movlw    12        ;std PWM mode
    50.     movwf    CCP2CON,ACCESS
    51.     movlw    8        ;set CCP2 PWM timer as TMR4
    52.     banksel CCPTMRS0
    53.     iorwf    CCPTMRS0
    54.     movlw    50        ;50 instr cycles * 16 prescale * 1/16000000 = 50 us or freq. of 20kHz
    55.     banksel PR4
    56.     movwf    PR4
    57.     movlw    20        ;40% D.C. with PR4=50: 20 (instr cycles) * 16 (prescale) * 1/16000000 = 20 us
    58.     movwf    CCPR2L,ACCESS
    59.     movlw    7        ;Prescale is 16, TMR4ON=1
    60.     banksel T4CON
    61.     movwf    T4CON
    62. ;******** CCP3 *****************
    63.     movlw    12        ;std PWM mode
    64.     banksel CCP3CON
    65.     movwf    CCP3CON
    66.     movlw    128        ;set CCP3 PWM timer as TMR6
    67.     banksel CCPTMRS0
    68.     iorwf    CCPTMRS0
    69.     movlw    100        ;100 instr cycles * 16 prescale * 1/16000000 = 100 us or freq. of 10kHz
    70.     banksel PR6
    71.     movwf    PR6
    72.     movlw    50        ;50% D.C. with PR4=100: 50 (instr cycles) * 16 (prescale) * 1/16000000 = 50 us
    73.     banksel    CCPR3L
    74.     movwf    CCPR3L
    75.     movlw    7        ;Prescale is 16, TMR6ON=1
    76.     banksel T6CON
    77.     movwf    T6CON
    78. ;*******************************
    79.     clrf    TRISA,ACCESS    ;just keeping some leds off
    80.     movlw    223
    81.     movwf    LATA,ACCESS
    82. START
    83.     movlw    255        ;nonsense stuff
    84.     banksel    ABCED
    85.     movwf    ABCED,BANKED
    86.     movlw    123
    87.     movwf    ZEROX,BANKED
    88.     bra    START
    89. BASPROGRAMEND
    90.     sleep
    91.     bra    BASPROGRAMEND
    92.  
    93. ;********************************************************************************
    94.  
    95. INITSYS
    96.     clrf    BSR,ACCESS
    97.     clrf    TBLPTRU,ACCESS
    98.     bcf    ADCON0,ADON,ACCESS
    99.     bcf    ADCON2,ADFM,ACCESS
    100.     movlw    0
    101.     banksel    ANSELA
    102.     movwf    ANSELA
    103.     movwf    ANSELB
    104.     bcf    CM2CON0,C2ON,ACCESS
    105.     bcf    CM1CON0,C1ON,ACCESS
    106.     clrf    PORTA,ACCESS
    107.     clrf    PORTB,ACCESS
    108.     clrf    PORTC,ACCESS
    109.     clrf    PORTE,ACCESS
    110.     return
    111.  
    112. ;********************************************************************************
    113.  
    114.  
    115.  END
     
  4. be80be

    Senior Member

    Jul 5, 2008
    431
    57
    Yes there is a lot of pic's with more then 3 channels of pwm nice code nick.
     
  5. nickelflipper

    Active Member

    Jun 2, 2010
    280
    35
    I like the 18f1330 too. A habit of mine is to skate on the software PWM code, if there is a hardware module available out there somewhere. The code is a mix of a compiled asm file, and manual editing in MPASM:).
     
  6. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
Loading...