Pwm portb in pic 16f628 in same time


Closed Thread
Results 1 to 23 of 23

Hybrid View

  1. #1
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

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

    Perhaps I am missing something.

    The code you show in post # 4 has no DT_INTS include file. It does have an include file named Multi_SPWM.pbp , which I gather is really SPWM_INT.BAS from this link: http://www.darreltaylor.com/DT_INTS-14/SPWM_INT.bas.txt .

    If this is correct, then you should have an include in your file for DT_INTS, really I think that is the only way to get a WSAVE error, but I could be wrong.

    Your might try something more along the lines of the example code, here: http://www.darreltaylor.com/DT_INTS-14/SPWM.html with both include files, etc. If you get a wsave error, make sure you are editing the right DT_INTS_14.bas file, whatever you call it in your include statement.

    For your chip, it should be edited so that:
    Code:
    ' --- IF any of these three lines cause an error ?? ------------------------
    '       Comment them out to fix the problem ----
    ' -- Which variables are needed, depends on the Chip you are using -- 
    wsave1  VAR BYTE    $A0     SYSTEM      ' location for W if in bank1
    wsave2  VAR BYTE    $120    SYSTEM      ' location for W if in bank2
    ;wsave3  VAR BYTE    $1A0    SYSTEM      ' location for W if in bank3
    ' --------------------------------------------------------------------------
    EDIT: A little late, but I found where Multi_SPWM.pbp came from http://www.pbpgroup.com/modules/wfse...p?articleid=12
    Last edited by ScaleRobotics; - 14th February 2011 at 00:25. Reason: a little late, but found Multi_SPWM.pbp

  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

    Yes,I have DT_INTS_14.bas file,I write correct name.
    I do what you tell me,but now I have errors.
    If I understudy you,i MUST WRITE THAT,CODE?

    ' --- IF any of these three lines cause an error ?? ------------------------
    ' Comment them out to fix the problem ----
    ' -- Which variables are needed, depends on the Chip you are using --
    wsave1 VAR BYTE $A0 SYSTEM ' location for W if in bank1
    wsave2 VAR BYTE $120 SYSTEM ' location for W if in bank2
    ;wsave3 VAR BYTE $1A0 SYSTEM ' location for W if in bank3

    ' --------------------------------------------------------------------------

    I do that but I have errors when I compile.

    This program in my PicBasic :
    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:
    wsave   VAR BYTE    $70     SYSTEM      ' location for W if in bank0
    ;wsave   VAR BYTE    $70     SYSTEM      ' alternate save location for W 
                                             ' if using $70, comment wsave1-3
    
    
                                   ; 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
    is correct?

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