Cos'è ElectroYou | Login Iscriviti

ElectroYou - la comunità dei professionisti del mondo elettrico

Controllo Retroazione Motore, problemi col PWM

Tipologie, strumenti di sviluppo, hardware e progetti

Moderatore: Foto UtentePaolino

0
voti

[1] Controllo Retroazione Motore, problemi col PWM

Messaggioda Foto Utentetorla91 » 21 mar 2013, 17:53

Buongiorno, sto realizzando un sistema di feedback per il controllo della velocità di un more in corrente continua regolato con sistema PWM.

Uso un PIC16F690, programmando in ambiente MPLAB con linguaggio assembly.
La prima parte di codice configura l' ADC per acquisire un potenziale analogico che rappresenta la velocità del motore, viene quindi convertito a 8bit e memorizzato. Quello che vorrei fare ora è trasferire la lettura convertita nel registro del PWM per definirne il dutycicle ma il risultato non torna.
Potreste aiutarmi a capire dov'è il problema? Il convertitore ADC dovrebbe funzionare, ho plottato il risultato su una matrice a led e leggevo valori corretti.


Codice: Seleziona tutto
;    list      p=16F689           ; list directive to define processor
;    include <p16F689.inc>        ; processor specific variable definitions
;   radix       DEC
;    ERRORLEVEL  -302              ; suppress message 302 from list file

      include    "p16f690.inc"
      processor   16F690
      radix       DEC
       ERRORLEVEL  -302
   

   __CONFIG   _CP_OFF & _CPD_OFF & _BOR_OFF & _MCLRE_ON & _WDT_OFF & _PWRTE_ON & _INTRC_OSC_NOCLKOUT & _FCMEN_OFF & _IESO_OFF

; '__CONFIG' directive is used to embed configuration word within .asm file.
; The lables following the directive are located in the respective .inc file.
; See data sheet for additional information on configuration word settings.

;***** VARIABLE DEFINITIONS (examples)

      CBLOCK 20H
w_temp         :1
status_temp      :1
pclath_temp     :1
CONVH         :1
CONVL         :1
        ENDC
;
;*********************************************
;Start point al reset della CPU

         ORG  00H
             goto INIZIO_CODICE


         ORG 04
;VETTORE INTERRUZIONI
;cominciano le grane....
      movwf   w_temp            ; salva l'accumulatore in variabile tmp
       movf   STATUS,w          ;
      movwf   status_temp       ; salva registro di stato
      ;.......                  ; e salvo eventualmente altri registri
   ;   call RICONOSCI_SORGENTE
      ;codice isr
      
      movf    status_temp,w     ;recupera il registro di stato
      movwf   STATUS            ;
      swapf   w_temp,f          ;il recupero di w vieene fatto 
      swapf   w_temp,w          ; in questo modo poiché la movfw influenza il bit Z
      retfie                   ;torno dalla interruzione    
       
        retfie          ;torno dalla interruzione

;********************************************
;Procedure

;********************************************




;**************************************************************
               
INIZIO_CODICE

;inizializzare porte
   clrf   STATUS
   bsf      STATUS,RP1
   movlw   1
   movwf   ANSEL
   movlw   0
   movwf   ANSELH
   clrf   STATUS
   bsf      STATUS,RP0
   movlw   1
   movwf   TRISA            ;PORTA RA1 ANALOGIN ALTRE OUTPUT
   CLRW
   CLRF   TRISC            ;PORTC E PORTB OUTPUT
   CLRF   TRISB
   
;CONVERSIONE AD,INGRESSO SU CH0(AN0 RA0) ECC...
   CLRF   STATUS
   clrf   ADCON0
   bsf      ADCON0,ADON
   BSF      STATUS,RP0
   clrf   ADCON1
   BSF      ADCON1,ADCS0
   
   
MainLoop                                ;ciclo di loop     
       
;INIZIO CONVERSIONE AD
   NOP
   NOP   
   NOP
   CLRF   STATUS      
   BSF      ADCON0,GO   
;CONTROLLA CHE LA PROCEDURA DI CONVERSIONE SIA TERMINATA ELSE ASPETTA
CONVERTING
   BTFSC   ADCON0,1
   GOTO   CONVERTING
;CONVERSIONE TERMINATA, ELABORAZIONE DATI, USO SOLO 8BIT ADRESH COPIATI IN CONV
   CLRF   STATUS
   MOVFW   ADRESH
   MOVWF   CONVH
   BSF      STATUS, RP0
   MOVFW   ADRESL
   CLRF   STATUS   
   MOVWF   CONVL
   
;ACQUISITO IL VALORE ANALOGICO E CONVERTITO IN DIGITALE LO TRASFORMO IN PWM
;0V=>0% 5V=>100%
   

   ; Routine di setup del PWM

; 1. Impostare il periodo dell'onda PWM mediante il registro PR2.
   CLRF   STATUS
   BSF      STATUS,RP0
   MOVLW   255
   MOVWF   PR2
; 2. Impostare il duty-cycle, mediante il registro CCPR1L
;    ed i bit5 e 4 del registro CCP1CON.
   CLRF   STATUS
   MOVFW   CONVH
   MOVWF    CCPR1L
;   bcf     CCP1CON,DC1B1
;   bcf     CCP1CON,DC1B0
;
; 3. Mettere il modulo CCP1 in grado di generare un output sul pin RC2,
;    agendo sul registro TRISC (bit 2)
   
   
; 4. Impostare il valore del prescaler di TMR2 ed abilitare il Timer2
;    agendo sul registro T2CON (bir T2ON).
   CLRF   STATUS      
   movlw   b'00000100'
   movwf   T2CON

; 5. Configurare il modulo CCP1 affinchè operi come PWM.
   
   movlw   b'00001100'
   movwf   CCP1CON
   movlw   160
   movwf    CCPR1L
      

   goto    MainLoop

      END
Avatar utente
Foto Utentetorla91
45 1 6
Frequentatore
Frequentatore
 
Messaggi: 100
Iscritto il: 8 feb 2012, 19:10

Torna a Realizzazioni, interfacciamento e nozioni generali.

Chi c’è in linea

Visitano il forum: Nessuno e 19 ospiti