12F683 2 x PWM Outputs


Closed Thread
Results 1 to 30 of 30

Hybrid View

  1. #1
    Join Date
    Feb 2012
    Posts
    2


    Did you find this post helpful? Yes | No

    Default Re: 12F683 2 x PWM Outputs

    Thank you very much for your answer!

    Of course I tried HPWM and I use 30 Projects Using PIC BASIC and PIC BASIC PRO as my Bible in programming, but it cannot give such low frequency as 85 Hz.

    Apologies again for posting in thread with other topic, and I know that is annoying to make first post with question… I searched the entire web for tips for that for a long time – and recently found DT SPWM (many thanks for that) where frequencies below 255 Hz are possible. I just didn’t find someone made it with 12F683…
    Anyway probably I will find time this weekend to try the code in this thread without changes in PWM, something like that:

    Code:
    DEFINE OSC 8
    
    SPWMpin var GPIO.5 ' Output Pin for SSPWM
    INCLUDE "SSPWM.inc" ' include the SSPWM module
    
    ;----[Constants]------------------------------------------
    ;HPWMfreq CON 20000
    Freq = 85 ' Set Frequency of SSPWM (word)
    
    ;----[Variables]------------------------------------------
    ;HPWMduty VAR BYTE
    ;LastHPWMduty VAR BYTE
    SSPWMduty VAR BYTE
    
    ;----[Initialize]-----------------------------------------
    OSCCON = %01110000 ' 8Mhz
    ;ANSEL = %000011 ' AN0 and AN1 ANALOG
    DutyCycle = 10 ' Set Duty Cycle of SSPWM
    gosub StartSPWM ' Start SSPWM @ Freq/DutyCycle
    ;HPWM 1, 127, HPWMfreq ' Start 20Khz PWM @ 50%
    
    ;----[Main Program Loop]---------------------------------
    Main:
    ;ADCIN 0, HPWMduty
    ;ADCIN 1, SSPWMduty
    
    ;IF HPWMDuty != LastHPWMduty THEN
    ;LastHPWMduty = HPWMDuty
    ;HPWM 1, HPWMDuty, HPWMfreq
    ; ENDIF
    
    
    ;DutyCycle = SSPWMduty*80/256+10 ' scale SSPWM dutycycle
    
    DutyCycle = 95        ' set 95% nominal SSPWM dutycycle
    gosub SetSPWM       ' Change SSPWM DutyCycle
    GOTO Main
    Maybe after all I will not need changes in ASM.

  2. #2
    Join Date
    Nov 2011
    Posts
    18


    Did you find this post helpful? Yes | No

    Default Re: 12F683 2 x PWM Outputs

    Hi,
    I copied the program into Microcode Studio and when I compile it I get
    the following errors:

    ERROR: Variable wsave3 position request 416 beyond RAM_END 191.
    ERROR: Variable wsave2 position request 288 beyond RAM_END 191.

    I Googled the errors and searched the forum but cant find an answer.

    Please help.
    Hebemabo

  3. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,623


    Did you find this post helpful? Yes | No

    Default Re: 12F683 2 x PWM Outputs

    Which program, exactly are you talking about? There are several ones in this thread - is it one of them?
    And what PIC are you aiming to use and have you selected that particular one in MicrocodeStudio?

    /Henrik.

  4. #4
    Join Date
    Nov 2011
    Posts
    18


    Did you find this post helpful? Yes | No

    Default Re: 12F683 2 x PWM Outputs

    Hello Henrik , its the code just before my reply. The one by deodeo.

    I am programming a 12F683 using PBPro , Microcode Studio , MPASM and Pickit2.
    I have selected 12F683 in MicrocodeStudio.
    Last edited by Hebemabo; - 23rd July 2021 at 16:31.

  5. #5


    Did you find this post helpful? Yes | No

    Default Re: 12F683 2 x PWM Outputs

    Just like DT's interrupt routines, you some times need to comment out a few lines in the include file

    Look inside "SSPWM.inc"

    Code:
    ' --- IF any of these three lines cause an error ??  Simply Comment them out to fix the problem ----
    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
    ' ------------------------------------------------------------------------------

  6. #6
    Join Date
    Nov 2011
    Posts
    18


    Did you find this post helpful? Yes | No

    Default Re: 12F683 2 x PWM Outputs

    Thank you very much Mark.

Similar Threads

  1. Variable PWM PIC18F2431
    By trr1985 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 12th June 2009, 07:03
  2. 2 PWM in 16F690 problems
    By ciendavila in forum mel PIC BASIC
    Replies: 9
    Last Post: - 27th April 2008, 10:03
  3. 12f683 comparator and pwm
    By Automan in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 23rd May 2007, 19:05
  4. Microcontroller with 2 way paging application problem
    By oneohthree in forum mel PIC BASIC Pro
    Replies: 30
    Last Post: - 20th April 2007, 18:27
  5. Variable PWM on 2 Channels using software.
    By Tissy in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 23rd September 2006, 02:34

Members who have read this thread : 1

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