Pwm portb in pic 16f628 in same time


Closed Thread
Results 1 to 23 of 23

Hybrid View

  1. #1
    Join Date
    May 2010
    Posts
    43


    Did you find this post helpful? Yes | No

    Default Pwm portb in pic 16f628 in same time

    Thks.so much!
    yes, I need 8 Different PWM signals!!!
    I looking this site,I found code for PWM,
    but when I tried COMPILE,
    I have so many errors,I dont now what is happed!!
    Code is:
    Code:
    '****************************************************************
    '*  Name    : Test_SPWM.pbp                                     *
    '*  Author  : Darrel Taylor                                     *
    '*  Date    : 9/30/2006                                         *
    '*  Version : 1.0                                               *
    '*  Notes   :                                                   *
    '*          :                                                   *
    '****************************************************************
    ; Initialize your hardware first
    
    DEFINE OSC 20
    CLEAR
    
    INCLUDE "DT_INTS-14.bas"         ; Base Interrupt System
    INCLUDE "SPWM_INT.bas"              ; Software PWM module
    
    DEFINE SPWM_FREQ  40                ; SPWM Frequency
    DEFINE SPWM_RES   256               ; SPWM Resolution
    
    DutyVars   VAR BYTE[3]              ; DutyCycle Variables
      DutyVar1 VAR DutyVars[0]          ; group them in an array for easy access
      DutyVar2 VAR DutyVars[1]          ; with FOR loops etc.
      DutyVar3 VAR DutyVars[2]
    
    ASM
    SPWM_LIST  macro                    ; Define PIN's to use for SPWM
         SPWM_PIN  PORTB, 0, _DutyVar1
         SPWM_PIN  PORTB, 1, _DutyVar2
         SPWM_PIN  PORTB, 2, _DutyVar3
      endm
      SPWM_INIT  SPWM_LIST              ; Initialize the Pins
    ENDASM
    
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler   TMR1_INT,  SPWMhandler,  ASM,  yes
        endm
        INT_CREATE                      ; Creates the interrupt processor
    ENDASM
    
    @ INT_ENABLE  TMR1_INT              ; enable Timer 1 interrupts
    
    ;_____________________________________________________________________________
    
    RandVar   VAR WORD : RandVar = 12345
    LoopCount VAR WORD
    
    Main:                               ; Simple Demo to fade/flash some LED's
        DutyVar1 = 5                        ; Start with 3 LED's at different
        DutyVar2 = 50                       ; brightness
        DutyVar3 = 150
        pause 3000
         
        FOR LoopCount = 1 to 4              ; Reapeat 4 times
            for DutyVar1 = 0 to 150         ; Fade LED1 UP
                pause 10
                RANDOM  RandVar             
                DutyVar3 = RandVar & $3F          ; Give LED3 a random dutycycle
            next DutyVar1
             
            for DutyVar1 = 150 to 0 STEP -1 ; Fade LED1 Down
                pause 10
                RANDOM  RandVar
                DutyVar2 = RandVar & $3F         ; Give LED2 a random dutycycle
            next DutyVar1
        NEXT LoopCount     
    GOTO Main
    and to many errors
    Attached Images Attached Images  
    Last edited by dragan77; - 13th February 2011 at 18:35.

  2. #2
    Join Date
    May 2010
    Posts
    43


    Did you find this post helpful? Yes | No

    Default Re: Pwm portb in pic 16f628 in same time

    And I tried,compile in PicBasic,this code:
    Code:
    define OSC 20
    
    define SPWMFREQ  100           ' PWM frequency in Hz    
    
    DutyCycle1   VAR  byte    ' 0-255  0=Idle Low   255=Idle High
    DutyCycle2   VAR  byte 
    DutyCycle3   VAR  byte    
    
    SPWM1PIN  VAR PORTB.0          ' SPWM channel 1
    define SPWM1VAR  _DutyCycle1
    
    SPWM2PIN  VAR PORTB.1          ' SPWM channel 2
    define SPWM2VAR  _DutyCycle2
    
    SPWM3PIN  VAR PORTB.2          ' SPWM channel 3
    define SPWM3VAR  _DutyCycle3
     
    Include "Multi_SPWM.pbp"
    
    DutyCycle1 = 0
    DutyCycle2 = 127
    DutyCycle3 = 255
    
    Loop:
       Pause 100
    Goto Loop
    and I have errors:
    Code:
    ERROR: Variable wsave3 position request 416 beyond RAM_END 335.
    Can anybody now what is problem!!!

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts