Dual PWM's using 12F683? Failure, Suggestions?


Closed Thread
Results 1 to 13 of 13
  1. #1
    Join Date
    Dec 2012
    Location
    Tennessee
    Posts
    262

    Question Dual PWM's using 12F683? Failure, Suggestions?

    Ive got a project that has some issues, what the project is suppose to do is have 2 pots that control 2 FET's via Software or Hardware PWM's to control LED light strings.

    Here is the results
    Trial 1 - Get a single unit to work, both Software and hardware work fine as a single unit with code for only 1 being used, the software version can use about any chip with a adc converter.
    Here is some code that was working with
    Code:
    DEFINE ADC_BITS 10 ' A/D number of bits
    DEFINE ADC_CLOCK 1 ' Use A/D internal RC
    DEFINE ADC_SAMPLEUS 50 ' Set sampling ti
    TRISIO = %000101 ' AN0 & AN2 is Analog input
    CNT VAR byte
    POT1 VAR WORD
    POT2 VAR WORD
    CNT=0
    AGAIN:
        ADCIN 0, POT1 ' Read Channel 0 data
        POT1 = POT1 / 256
        if POT1 < 10 then POT1 = 0
        ADCIN 2, POT2 ' Read Channel 0 data
        POT2 = POT2 / 256
        if POT2 < 10 then POT2 = 0
        
    RUNNER:
        if POT1 > CNT then 
     GPIO.1 = 1 
     ELSE 
     GPIO.1 = 0
     endif
        if POT2 > CNT then 
     GPIO.3 = 1 
     ELSE 
     GPIO.3 = 0
     ENDIF
        CNT = CNT + 1
        if CNT > 255 then CNT = 0
        if CNT = 0 then goto again
    GOTO runner
    end
    Now this is the software version of PWM, its low tech and maybe theres another way better for software PWM.
    ----------------------------------
    Here is my hardware version I am using a 12F683 for this one
    Code:
    DEFINE ADC_BITS 8 ' A/D number of bits
    DEFINE ADC_CLOCK 1 ' Use A/D internal RC clock
    DEFINE ADC_SAMPLEUS 50 ' Set sampling time in us
    ADCON0.7 = 0 ' Justify Result to 10 & 8 bit Side
    CCP1CON = %00001100 ' Set ADC Port
    RES1 Var Word ' A/D converter result
      
    TRISIO = %00000010
    AGAIN:
    ADCIN 1, Res1 ' Read Channel 0 data
    if res1 < 10 then res1 = 0 ' Low Auto Shutoff
    HPWM 1, res1, 18000 ' PWM Pin, Setting, Frequency (20k Max)
    pause 25
    goto again
    end
    Again this one works fine by itself.
    I did try to merge both into one chip and have both hardware and software but that didnt go so well, they interact with each other, im not sure why as the pins they use and code are seperate but it happens, and I erased the code that was messed up.

    So what I would like is some sample code for dual PWMs that do not interfere with each other, I only have legacy 8bit processors right now (629, 675, 683, 4550) and although I do have a PicKit3 Available I am using pbp2.6 and mcs4. I will be getting PBP 3gold soon, perhaps in a couple of months and will have access to other chips then too.

    So any ideas are welcome.
    Chris


    Any man who has accomplished anything in electronics at one time or another has said... " STOP! WAIT! NOOO! Dangit.... Oh Well, Time to start over..."

  2. #2
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Default Re: Dual PWM's using 12F683? Failure, Suggestions?

    Darrel's SSPWM , may be ???
    http://www.pbpgroup.com/modules/wfse...p?articleid=12

    too late to thank him ... Halas.

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  3. #3


    Did you find this post helpful? Yes | No

    Default Re: Dual PWM's using 12F683? Failure, Suggestions?

    Quote Originally Posted by Acetronics2 View Post
    too late to thank him ... Halas.

    Alain
    Yes. But his spirit lives and we can thank him by keeping his work alive!

    @WDMAGIC

    Have a look at Darrel's MBAM routine. The example has three pwm outputs, controlling a RGB led. I experimented with it a
    while back. You can change pulse width and rate with the adc. Only draw back, it only has 8 bits of resolution vs 10 bits using the
    hpwm module. Dimming appeared smooth to my eyes.

    http://www.picbasic.co.uk/forum/showthread.php?t=10564

  4. #4
    Join Date
    Dec 2012
    Location
    Tennessee
    Posts
    262


    Did you find this post helpful? Yes | No

    Default Re: Dual PWM's using 12F683? Failure, Suggestions?

    Darrels Passed , I didnt know

    I found that link to the sspwm right after I posted, will give it a try. wish i could find a 8pin package with 2 hpwm's
    Chris


    Any man who has accomplished anything in electronics at one time or another has said... " STOP! WAIT! NOOO! Dangit.... Oh Well, Time to start over..."

  5. #5
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Default Re: Dual PWM's using 12F683? Failure, Suggestions?

    Try to get one of those ...
    http://ww1.microchip.com/downloads/e.../40001723C.pdf

    alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  6. #6
    Join Date
    Jan 2014
    Posts
    84


    Did you find this post helpful? Yes | No

    Default Re: Dual PWM's using 12F683? Failure, Suggestions?

    Exist a way to compile 12f1571/1572 with PBP ?

  7. #7
    Join Date
    Dec 2012
    Location
    Tennessee
    Posts
    262


    Did you find this post helpful? Yes | No

    Default Re: Dual PWM's using 12F683? Failure, Suggestions?

    I'm Back! ok its been awhile, work has bogged me down along with training someone in VB, also I just got sidetracked. But I'm much better now I ordered some of the 12f1572 's but since its been so long I've lost them and need to order more, I do have a PicKit3, hovever i need to order PBP3. I was going to order the Gold but I cant seem to find my discount link. there is a link that gives you $30 - 50 off but its been so long I've changed PC's and lost the link Can Anyone provide? anything cheaper than the list price would be good. thanks. Did I mention how hard it is to start this back up after a year of not programming and losing code notes! hehe. make backups!
    Chris


    Any man who has accomplished anything in electronics at one time or another has said... " STOP! WAIT! NOOO! Dangit.... Oh Well, Time to start over..."

  8. #8
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default Re: Dual PWM's using 12F683? Failure, Suggestions?

    Midali, PBP 3.0 will compile for 12F1571/12F1572.
    Dave Purola,
    N8NTA
    EN82fn

  9. #9
    Join Date
    Jan 2014
    Posts
    84


    Did you find this post helpful? Yes | No

    Default Re: Dual PWM's using 12F683? Failure, Suggestions?

    Thx Dave for your attention,
    I saw that PBP update have 12F157x compiler.

  10. #10
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: Dual PWM's using 12F683? Failure, Suggestions?

    Quote Originally Posted by wdmagic View Post
    Ive got a project that has some issues, what the project is suppose to do is have 2 pots that control 2 FET's via Software or Hardware PWM's to control LED light strings.

    So any ideas are welcome.
    How about using a PCA9685 PWM chip to controll the LEDS. OK 16 channels may be overkill, but I use one in a project that controlled the LEDs over my marine reef tank. In my case I can program the ramp up and down periods for each of four channels, with 0 to 4095 steps which makes for smooth dimming. I'm sure it would be easy to use an AtoD option for a POT to give the PWM range rather than a simple time loop.

    Also, if you are looking at controlling strings of high power LEDs then a simple way is to use Meanwell LDD drivers. These are constant current devices between 300mA and 1500ma, and can be used with 6v - 50v power supplies.

  11. #11
    Join Date
    Dec 2012
    Location
    Tennessee
    Posts
    262


    Did you find this post helpful? Yes | No

    Default Re: Dual PWM's using 12F683? Failure, Suggestions?

    thanks for the ideas, I'm dead set right now with only using microchip pics to do controlling, as I have a surplus of these. I did break down and buy the full version of pbp 3 gold, and so far its awesome, I also have a pickit 3. I'm messing around with it tonight using a 12f1572 was wondering if there was a way similar to a IRQ (interrupt) to detect a change in the ADC input? that way i could just call up the code when someone turned a knob.
    Chris


    Any man who has accomplished anything in electronics at one time or another has said... " STOP! WAIT! NOOO! Dangit.... Oh Well, Time to start over..."

  12. #12
    Join Date
    Dec 2012
    Location
    Tennessee
    Posts
    262


    Did you find this post helpful? Yes | No

    Default Re: Dual PWM's using 12F683? Failure, Suggestions?

    OK I got it to work using a 12F1572. I wanted to post my code and see if anyone can spot something I need to clean up or rework. please note a small problem i ran into noted after code. DEFINE OSC 4 DEFINE ADC_BITS 8 ' A/D number of bits DEFINE ADC_CLOCK 1 ' Use A/D internal RC clock DEFINE ADC_SAMPLEUS 50 ' Set sampling time in us 50 ADCON0.7 = 0 ' Justify Result to 10 & 8 bit Side RES1 Var byte ' A/D converter result RES0 VAR BYTE AGAIN: ADCIN 2, Res0 ' Read Channel 3 data ADCIN 3, Res1 ' Read Channel 3 data if res1 < 10 then res1 = 0 ' Low Auto Shutoff if res0 < 10 then res0 = 0 ' Low Auto Shutoff HPWM 2, res0, 10000 ' PWM Pin, Setting, Frequency (20k Max) HPWM 1, res1, 10000 ' PWM Pin, Setting, Frequency (20k Max) pause 5 goto again ----------------- sorry not in code block, my page doesnt show those options. ok the problem i ran into is that the 12f1572 is supposed to be capable of running up to 32mhz using internal clock I thought it read. however if i change the define to 32, then it slowwwws way down, also even when set to 4mhz i had to make my pause at the end 5, where it used to be 100 with older chips? any ideas on how i can specify a higher internal clock freq, and why i have to use such a low pause (if i use a 100 my leds flash, with a 5 they change fairly smoothly.)
    Chris


    Any man who has accomplished anything in electronics at one time or another has said... " STOP! WAIT! NOOO! Dangit.... Oh Well, Time to start over..."

  13. #13
    Join Date
    May 2013
    Location
    australia
    Posts
    2,389


    Did you find this post helpful? Yes | No

    Default Re: Dual PWM's using 12F683? Failure, Suggestions?

    Note that "DEFINE OSC" doesn't set or change the actual clock frequency. It only
    tells PBP what to expect. The actual frequency is set by selecting a crystal,
    changing the device configuration, setting registers in your program, or (most
    commonly) a combination of all of these.

    you need to set the OSCCON reg appropriately and the PLL config too to use the 32mhz clock

Similar Threads

  1. using the pwm's in pic18f2431-2331-4331-4431
    By jorge_jaqa in forum mel PIC BASIC Pro
    Replies: 27
    Last Post: - 17th February 2018, 09:05
  2. Replies: 1
    Last Post: - 4th March 2013, 21:57
  3. PIC 16F690 PWM's ports selection - How to?
    By flotulopex in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 8th September 2011, 20:08
  4. ADCIN failure
    By brid0030 in forum General
    Replies: 6
    Last Post: - 6th November 2007, 16:20
  5. Can you use 2 PWM's simultaneously?
    By peterdeco1 in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 30th June 2006, 18:50

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