controlling speed of multiple DC motors with single microcontroller

Thread Starter

Abdo_pc_dr

Joined Apr 3, 2010
13
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.
 
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.

Rich (BB code):
;;Set up the assembler options (Chip type, clock source, other bits and pieces)
 LIST p=18F26K22, r=DEC
#include <P18F26K22.inc>
 CONFIG LVP = OFF, MCLRE = INTMCLR, PBADEN = OFF, CCP2MX = PORTB3, WDTEN = OFF, BOREN = OFF, FOSC = INTIO67
 
;********************************************************************************
 
;Set aside memory locations for variables
ABCED    EQU    256
ZEROX    EQU    257
 
;********************************************************************************
 
;Vectors
    ORG    0
    goto    BASPROGRAMSTART
    ORG    8
    retfie
 
;********************************************************************************
 
;Start of program memory page 0
    ORG    12
BASPROGRAMSTART
;Call initialisation routines
    rcall    INITSYS
 
;Start of the main program
    bcf    TRISA,5,ACCESS
    bcf    TRISC,1,ACCESS
    bcf    TRISC,2,ACCESS        ;CCP1 default
    bcf    TRISB,3,ACCESS        ;CCP2 with mux config PortB,3
    bcf    TRISB,5,ACCESS        ;CCP3 default
    bcf    TRISC,6,ACCESS
    movlw    112                ;16MHz
    movwf    OSCCON,ACCESS
    bsf    OSCTUNE,PLLEN,ACCESS    ;enable 4xPLL for 16mips
;******** CCP1 *****************
    movlw    12        ;std PWM mode
    movwf    CCP1CON,ACCESS
    movlw    0        ;16 MHz (PRx + 1)*1/16000000*TMRx prescale
    movwf    PR2,ACCESS
    movlw    0        ;D.C. 50% (CCPRxL:CCPxCON<5:4>)/4(PRx+1)
    movwf    CCPR1L,ACCESS
    bsf        CCP1CON,DC1B1,ACCESS
    bcf        CCP1CON,DC1B0,ACCESS
    bsf        T2CON,TMR2ON,ACCESS        ;no prescale
;******** CCP2 *****************
    movlw    12        ;std PWM mode
    movwf    CCP2CON,ACCESS
    movlw    8        ;set CCP2 PWM timer as TMR4
    banksel CCPTMRS0
    iorwf    CCPTMRS0
    movlw    50        ;50 instr cycles * 16 prescale * 1/16000000 = 50 us or freq. of 20kHz
    banksel PR4
    movwf    PR4
    movlw    20        ;40% D.C. with PR4=50: 20 (instr cycles) * 16 (prescale) * 1/16000000 = 20 us
    movwf    CCPR2L,ACCESS
    movlw    7        ;Prescale is 16, TMR4ON=1
    banksel T4CON
    movwf    T4CON
;******** CCP3 *****************
    movlw    12        ;std PWM mode
    banksel CCP3CON
    movwf    CCP3CON
    movlw    128        ;set CCP3 PWM timer as TMR6
    banksel CCPTMRS0
    iorwf    CCPTMRS0
    movlw    100        ;100 instr cycles * 16 prescale * 1/16000000 = 100 us or freq. of 10kHz
    banksel PR6
    movwf    PR6
    movlw    50        ;50% D.C. with PR4=100: 50 (instr cycles) * 16 (prescale) * 1/16000000 = 50 us
    banksel    CCPR3L
    movwf    CCPR3L
    movlw    7        ;Prescale is 16, TMR6ON=1
    banksel T6CON
    movwf    T6CON
;*******************************
    clrf    TRISA,ACCESS    ;just keeping some leds off
    movlw    223
    movwf    LATA,ACCESS
START
    movlw    255        ;nonsense stuff
    banksel    ABCED
    movwf    ABCED,BANKED
    movlw    123
    movwf    ZEROX,BANKED
    bra    START
BASPROGRAMEND
    sleep
    bra    BASPROGRAMEND
 
;********************************************************************************
 
INITSYS
    clrf    BSR,ACCESS
    clrf    TBLPTRU,ACCESS
    bcf    ADCON0,ADON,ACCESS
    bcf    ADCON2,ADFM,ACCESS
    movlw    0
    banksel    ANSELA
    movwf    ANSELA
    movwf    ANSELB
    bcf    CM2CON0,C2ON,ACCESS
    bcf    CM1CON0,C1ON,ACCESS
    clrf    PORTA,ACCESS
    clrf    PORTB,ACCESS
    clrf    PORTC,ACCESS
    clrf    PORTE,ACCESS
    return
 
;********************************************************************************
 
 
 END
 
Yes there is a lot of pic's with more then 3 channels of pwm nice code nick.
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:).
 
Top