Help with multiple SPWM


Closed Thread
Results 1 to 3 of 3
  1. #1

    Default Help with multiple SPWM

    I have the below program and want it to generate the following pwm signals.

    1) 2khz HPWM this is working fine as shown by scope.
    2) 25hz 50% duty SPWM this is working fine as shown by scope.
    3) 25hz 7% duty SPWM this is not working correctly and is broken up and irregular.
    4) 12hz Manual pause defined PWM, again this is not working correctly and the led I have to check the loop is not working
    The loop1 is is not executing for some reason.

    Perhaps something in my config/register setup?

    It uses Darrells Instant interrupts and SPWM but I can't see anything obviously wrong. Can you?

    Code:
    '------------------------------ General configuration --------------------------
    
    #config
    
     __config _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _PWRTE_OFF & _MCLRE_OFF & _BOREN_OFF & _CLKOUTEN_OFF & _FCMEN_OFF
     __config _CONFIG2, _PLLEN_OFF & _LVP_OFF
    
    #ENDCONFIG
    
    
    DEFINE OSC 16			'Set PicBasic Pro processor speed to 16 Mhz (Must match oscillator value)  
    OSCCON = %01111010		'Sets internal osc to 16 Mhz (Default)   
    TRISA  = %00000000		'PortA All Outputs 
    
    
    ; Initialize your hardware first
    
    CLEAR
    
    INCLUDE "DT_INTS-14.bas"            ; Base Interrupt System
    INCLUDE "SPWM_INT.bas"              ; Software PWM module
    
    DEFINE SPWM_FREQ  25                ; SPWM Frequency
    DEFINE SPWM_RES   100               ; SPWM Resolution
    
      DutyVar1 VAR BYTE          
      DutyVar2 VAR BYTE    
      
      'Port Aliases
    
    MotFsb   VAR PORTA.4		'Define Pin A4 as MOTFSB
    RedLed   VAR PORTA.1        'Define Pin A1 as RedLed
     
    ASM
    SPWM_LIST  macro                    ; Define Pin's to use for SPWM
         SPWM_PIN  PORTA, 0, _DutyVar1  ; and the associated DutyCycle variables
         SPWM_PIN  PORTA, 5, _DutyVar2  ; Notice the underscore before variables     
      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
    
    ;_____________________________________________________________________________
    
    Main:                               ; Simple Demo 
        HPWM 1, 127, 2000     	         'Start 2khz 50% Duty HPWM     
        DutyVar1 = 7                     'Set MOTSTB to 7% Duty  SPWM 
        DutyVar2 = 50                    'Set MOTFSA to 50% Duty SPWM  
            
    Loop1:                                 'Bit Bang 12hz PWM
    
        HIGH MotFsb
        Pause 37 
        LOW MotFsb
        Pause 45
        toggle RedLed
        goto Loop1

  2. #2
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: Help with multiple SPWM

    Your 25 Hz 50% signal won’t be accurate either because it’s not evenly divisible by your instruction time 16/4 = 4 MHz.
    Only the 2kHz 50% signal can be free of resolution error with the 16 MHz clock.

  3. #3


    Did you find this post helpful? Yes | No

    Default Re: Help with multiple SPWM

    I've managed to fix it, appears I had not disabled the Adc and the analog inputs and they were somehow causing issues.

Similar Threads

  1. Spwm signals
    By sangaboy in forum Test Area
    Replies: 3
    Last Post: - 7th January 2012, 19:09
  2. Spwm
    By sangaboy in forum General
    Replies: 0
    Last Post: - 23rd December 2011, 06:09
  3. DT-int and SPWM
    By Macgman2000 in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 20th October 2011, 19:39
  4. SPWM and DEBUG
    By Homerclese in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 2nd August 2010, 00:07
  5. Darrel's SPWM and LCDOUT
    By Wirecut in forum mel PIC BASIC Pro
    Replies: 22
    Last Post: - 23rd April 2008, 22:30

Members who have read this thread : 2

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