12F683 2 x PWM Outputs


Closed Thread
Results 1 to 30 of 30

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by retepsnikrep View Post
    Thanks for the reply. I do plan on doing something with this in due course.
    Great confidence I have now ... NOT!

    Oh well, more things to do tomorrow I have ....
    Tonight, I do this ...
    Next year, you may try it.

    Name:  Retep_2PWM.JPG
Views: 13485
Size:  135.1 KB

    Code:
    DEFINE OSC 8
    
    SPWMpin  var GPIO.5     ' Output Pin for SSPWM
    INCLUDE "SSPWM.inc"     ' include the SSPWM module
    
    ;----[Constants]------------------------------------------
    HPWMfreq        CON 20000
    Freq = 2000             ' 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
        gosub SetSPWM                    ' Change SSPWM DutyCycle
    GOTO Main
    Dutycycle of the 2Khz is 10% in the image.
    Both dutycycles are adjustable from the pots, and works from 10% to 90%, (0 to 100% for the HPWM).

    Don't forget to comment the wsave vars not used by the 683 in the .inc file.

    Happy Holidays.
    DT

  2. #2


    Did you find this post helpful? Yes | No

    Default

    Incredible I was envisaging pages of code! many thanks to Darrel

    Could you post that Isis code and hex code as i have it and would like to look at the simulation.
    Last edited by retepsnikrep; - 17th December 2010 at 16:57.

  3. #3
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Could you post that Isis code and hex code...
    Here ya go.
    Attached Files Attached Files
    DT

  4. #4


    Did you find this post helpful? Yes | No

    Default

    Darrel

    Can you tell me the version of issis/proteus you are using i can't load it, my version is 7.4 SP2

    Cheers

  5. #5
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    7.8 SP0 (beta)

    If your license is up to date, you should be able to run the update manager and get the latest version.
    DT

  6. #6


    Did you find this post helpful? Yes | No

    Default

    Back to breadboard then it will cost be a fortune to upgrade suffciently to run it. Thanks anyway.
    I only have the picaxe VSM lite software which doesnt support simulating plain pics etc anyway.

  7. #7


    Did you find this post helpful? Yes | No

    Talking Thanks

    Thanks to all those who helped with this i have had this breadboarded and working in my pic on bench today, it works great. What a forum incredible. Now to design my pcb.

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 : 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