Haberler:

Forum kuralları güncellendi LÜTFEN  okuyunuz:  https://bit.ly/2IjR3ME

Ana Menü

PWM Yardım

Başlatan elektrnk, 06 Haziran 2007, 13:39:40

elektrnk

Assemblyde Bir Hız Kontrol Devresi için  tek kanallı bir pwm yapacam   2 butonlu olacak butonlardan biri hız azaltırken diger buton hız artırmakta kullanılacak yani 255 - 0  ve 0 - 255  boyle bir calısması olan arkadaslar varmı ;

  Pic16F628A  cıkıs ucu rb0  20 mhz kristal
  Butonlar Ra0 artırma tusu
               Ra1 azaltma tusu

forumda arkadaslar guzel ornekler gondermişler yalnız butonlu olarak nasıl yapacagımı anlayamadım asagıdaki ornekte forumdan ama buton olayını çözemedim  bunu nasıl uyarlıyabılırım 628A için ?

;******************************************************
     LIST      P=16F876A
     INCLUDE      "P16F876A.INC"
;******************************************************
     CBLOCK      0x20
PWM_DUTY
LOW_PWM
HIGH_PWM
PWM_SAYAC
DLY1
DLY2
     ENDC
;******************************************************
#DEFINE      PWM_OUT      PORTC,0  ;pwm cıkısı
;******************************************************
     ORG         0x00
     GOTO      START
;******************************************************
START
     BSF         STATUS,5
     MOVLW      0x07
     MOVWF      ADCON1
     CLRF      TRISC
     BCF         STATUS,5
     CLRF      PORTC
     CLRF      PWM_SAYAC
;******************************************************
MAIN
     MOVF      PWM_SAYAC,W
     MOVWF      PWM_DUTY
     CALL      START_PWM
     INCF      PWM_SAYAC,F    
     CALL      DELAY
     GOTO      MAIN
;******************************************************
START_PWM
     MOVF      PWM_DUTY,W
     BCF         PWM_OUT
     BTFSC      STATUS,Z
     RETURN
     MOVWF      HIGH_PWM
     SUBLW      .255
     MOVWF      LOW_PWM
     BSF         PWM_OUT
     BTFSC      STATUS,Z
     RETURN
     DECFSZ      HIGH_PWM,F
     GOTO      $-1
     BCF         PWM_OUT
     DECFSZ      LOW_PWM,F
     GOTO      $-1
     RETURN
;******************************************************
DELAY
     MOVLW      .1
     MOVWF      DLY1
LOOP1
     MOVLW      .10
     MOVWF      DLY2
LOOP2
     DECFSZ      DLY2,F
     GOTO      LOOP2
     DECFSZ      DLY1,F
     GOTO      LOOP1
     RETURN
;******************************************************
     END

zafzaf82

#include <16f628.h>
#device *=16
#FUSES NOWDT                    //Watch Dog Timer
#FUSES INTRC_IO                 //Internal RC Osc, no CLKOUT
#FUSES NOCPD                    //No EE protection
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOMCLR                   //Master Clear pin used for I/O
#FUSES NOPUT                    //No Power Up Timer
#FUSES NOLVP                      //No Low Voltage Programming on B3(PIC16) or B5(PIC18)
#FUSES NOBROWNOUT               //No brownout reset

#use delay(clock=4000000,RESTART_WDT)



#byte PORT_A = 0x05
#bit RA0 = 0x05.0
#bit RA1 = 0x05.1
#bit RA2 = 0x05.2
#bit RA3 = 0x05.3
#bit RA4 = 0x05.4
#bit RA5 = 0x05.5
#bit RA6 = 0x05.6
#bit RA7 = 0x05.7

#byte PORT_B = 0x06
#bit RB0 = 0x06.0
#bit RB1 = 0x06.1
#bit RB2 = 0x06.2
#bit RB3 = 0x06.3
#bit RB4 = 0x06.4
#bit RB5 = 0x06.5
#bit RB6 = 0x06.6
#bit RB7 = 0x06.7

int16 value;

#int_RB
RB_isr()
{
delay_ms(30);
   if(input(PIN_B4)==0)
   {
   value=value+100;
      if(value>=1023)
      value=1023;
   }

   if(input(PIN_B5)==0)
   {
   value=value-100;
      if(value<=0)
      value=0;
   }

   if(input(PIN_B6)==0)
   {
   value=value+10;
      if(value>=1023)
      value=1023;
   }

   if(input(PIN_B7)==0)
   {
   value=value-10;
      if(value<=0)
      value=0;
   }
   set_pwm1_duty(value);
}


void main()
{
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DIV_BY_1,255,1);
   setup_ccp1(CCP_PWM);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   enable_interrupts(INT_RB);
   enable_interrupts(GLOBAL);
   port_b_pullups(TRUE);

   set_tris_b(0xF0);

   value=500;
   set_pwm1_duty(value);
   for(;;)
   {
   }
}
Mikroişlemci bi araçtır, amaç değil.....

elektrnk

Hocam C bilmiyorum ,  assembly biliyorum az

  Assembly olarak yapabılecegim bir orneğiniz varmı ?

zafzaf82

malasef yaa bende pic asm de pek iyi değilim.
Mikroişlemci bi araçtır, amaç değil.....

kemalguler

Sevgili  Zafzaf82 yukarıdaki 16f628 için hazırlanmış dosyanın hex derlenmişini ekleyebilir misiniz.PICBasicPro programı da olabilir.

zafzaf82

Mikroişlemci bi araçtır, amaç değil.....

XX_CİHAN_XX

;*********************************************** 
LIST P=16F628A 
INCLUDE "P16F628A.INC" 
;*********************************************** 
__config(_CP_OFF & _PWRTE_OFF & _HS_OSC & _WDT_OFF & _BODEN_OFF & _LVP_OFF) 
ERRORLEVEL -302 
ERRORLEVEL -306 
;******************************************************* 
CBLOCK 0x20 
PWM_FLAG 
PWM_RED 
PWM_BLUE 
RISE_RED 
RISE_BLUE 
FALL_RED 
FALL_BLUE 
SAYAC
ENDC 
;******************************************************* 
#DEFINE PWMOUTR PORTB,0 
#DEFINE PWMOUTB PORTB,2 
;******************************************************* 
#DEFINE BT_RED_UP PORTB,4 
#DEFINE BT_BLUE_UP PORTB,6 
#DEFINE BT_RED_DOWN PORTB,5 
#DEFINE BT_BLUE_DOWN PORTB,7 
;******************************************************* 
#DEFINE END_BLUE PWM_FLAG,0 
#DEFINE END_RED PWM_FLAG,2 
#DEFINE END_BLUE2 PWM_FLAG,3 
#DEFINE END_RED2 PWM_FLAG,5 
;******************************************************* 
ORG 0x00 
GOTO SETUP 
ORG 0x04 
RETFIE 
;******************************************************* 
SETUP 
MOVLW 0x07 
MOVWF CMCON 
CLRF PORTB 
BSF STATUS,5 
MOVLW 0xF0 
MOVWF TRISB 
BCF STATUS,5 
CLRF PWM_RED 
CLRF PWM_BLUE 
;******************************************************* 
MAIN 
CALL BUTON_OKU 
CALL PWM_START
GOTO MAIN 
;******************************************************* 
PWM_START
MOVLW .10
MOVWF SAYAC
BEGIN
CALL RGB_PWM 
DECFSZ SAYAC,F
GOTO BEGIN
RETURN
;******************************************************* 
BUTON_OKU 
BTFSS BT_BLUE_UP 
GOTO MAVIYIARTIR
BTFSS BT_RED_UP 
GOTO KIRMIZIYIARTIR
BTFSS BT_BLUE_DOWN
GOTO MAVIYIEKSILT
BTFSS BT_RED_DOWN
GOTO KIRMIZIYIEKSILT
RETURN 
;******************************************************* 
MAVIYIARTIR
INCFSZ PWM_BLUE,F 
RETURN
COMF PWM_BLUE,F 
RETURN
;******************************************************* 
KIRMIZIYIARTIR
INCFSZ PWM_RED,F 
RETURN
COMF PWM_RED,F 
RETURN
;******************************************************* 
MAVIYIEKSILT
DECF PWM_BLUE,F
COMF PWM_BLUE,W
BTFSC STATUS,Z
MOVWF PWM_BLUE
RETURN
;******************************************************* 
KIRMIZIYIEKSILT
DECF PWM_RED,F
COMF PWM_RED,W
BTFSC STATUS,Z
MOVWF PWM_RED
RETURN
;******************************************************* 
RGB_PWM 
CLRF PWM_FLAG 
CALL RELOAD_BLUE 
CALL RELOAD_RED 
CLRF PWM_FLAG 
;******************************************************* 
BLUE_PWM 
MOVF PWM_FLAG,W 
SUBLW 0x3F 
BTFSC STATUS,Z 
RETURN 
;******************************************************* 
DECF RISE_BLUE,F 
COMF RISE_BLUE,W 
BTFSC STATUS,Z 
GOTO DOWN_BLUE 
BSF PWMOUTB 
GOTO RED_PWM 
;******************************************************* 
DOWN_BLUE 
CLRF RISE_BLUE 
DECF FALL_BLUE,F 
COMF FALL_BLUE,W 
BTFSS STATUS,Z 
BCF PWMOUTB 
BTFSC STATUS,Z 
CALL RELOAD_BLUE 
;******************************************************* 
RED_PWM 
DECF RISE_RED,F 
COMF RISE_RED,W 
BTFSC STATUS,Z 
GOTO DOWN_RED 
BSF PWMOUTR 
GOTO BLUE_PWM 
;******************************************************* 
DOWN_RED 
CLRF RISE_RED 
DECF FALL_RED,F 
COMF FALL_RED,W 
BTFSS STATUS,Z 
BCF PWMOUTR 
BTFSC STATUS,Z 
CALL RELOAD_RED 
GOTO BLUE_PWM 
;******************************************************* 
RELOAD_BLUE 
CLRF FALL_BLUE 
COMF PWM_FLAG,W 
ANDLW 0x07 
BTFSC STATUS,Z 
BSF END_BLUE2 
BTFSC STATUS,Z 
BCF PWMOUTB 
BTFSC STATUS,Z 
RETURN 
;******************************************************* 
MOVF PWM_BLUE,W 
MOVWF RISE_BLUE 
SUBLW .255 
MOVWF FALL_BLUE 
BSF END_BLUE 
RETURN 
;******************************************************* 
RELOAD_RED 
CLRF FALL_RED 
COMF PWM_FLAG,W 
ANDLW 0x07 
BTFSC STATUS,Z 
BSF END_RED2 
BTFSC STATUS,Z 
BCF PWMOUTR 
BTFSC STATUS,Z 
RETURN 
;******************************************************* 
MOVF PWM_RED,W 
MOVWF RISE_RED 
SUBLW .255 
MOVWF FALL_RED 
BSF END_RED 
RETURN 
;******************************************************* 
END
Yirmi yaşındaki bir insan, dünyayı değiştirmek ister . Yetmiş yaşına gelince , yine dünyayı değiştirmek ister, ama yapamayacağını bilir.

profahmet

geşen sene bir arkadaşıma hazırlamıştım. umarım işine yarar.
içinde proteus simülasyonu bulunmaktadır.
http://www.fileupyours.com/files/67239/pwm628.rar
kolay gelsin...

OG

FORUMU İLGİLENDİREN KONULARA ÖM İLE CEVAP VERİLMEZ.

protech06

Daha önceki bir devremde bende aynı yerde takılmıştım aşagıdaki linkte Bir örnek var incele belki  işine yarar kullanırsın
http://picproje.org/index.php/topic,15810