SPWM and Elapsed Timer


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

    Default SPWM and Elapsed Timer

    Is it possible to run these two beasts together since they both use TMR1?

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


    Did you find this post helpful? Yes | No

    Default

    You could change the Elapsed Timer to a different timer fairly easily.

    SPWM should stay on Timer1, because it needs a 16-bit timer, and is harder to modify.
    <br>
    DT

  3. #3


    Did you find this post helpful? Yes | No

    Default

    Darrel,

    What files would need to be modified? Just the Elapsed_INT.bas? Would you be able to help with the ASM part of it as it is for the most part greek to me. Oh yeah, the PIC I'm using it the 16F88 @ 10 MHz.

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


    Did you find this post helpful? Yes | No

    Default Elapsed Timer for TMR2

    Quote Originally Posted by CocaColaKid View Post
    Would you be able to help with the ASM part of it as it is for the most part greek to me.
    That's too bad....
    ASM is the Best part of Picbasic Pro.

    Learning one without the other is like buying a space shuttle without the solid rocket boosters.
    It looks nice, but it's not going to take you where you want to go. <hr>
    Ok, here ya go.

    The Elapsed Timer for use with Timer 2.

    Code:
    <font color="#0000FF"><b><i>; Initialze your hardware and LCD first
    
    </i></b></font><font color="#008000"><b>INCLUDE </b></font><font color="#FF0000">&quot;DT_INTS-14.bas&quot;     </font><font color="#0000FF"><b><i>' Required
    </i></b></font><font color="#008000"><b>INCLUDE </b></font><font color="#FF0000">&quot;Elapsed-T2.bas&quot;     </font><font color="#0000FF"><b><i>' Elapsed Timer for TMR2
    
    </i></b></font><font color="#008000"><b>ASM
    </b></font><font color="#000080">INT_LIST  macro    </font><font color="#0000FF"><b><i>; IntSource,        Label,  Type, ResetFlag?
            </i></b></font><font color="#000080">INT_Handler   TMR2_INT,  _ClockCount,   ASM,  yes
        endm
        INT_CREATE               </font><font color="#0000FF"><b><i>; Creates the interrupt processor
    
        </i></b></font><font color="#000080">INT_ENABLE  TMR2_INT      </font><font color="#0000FF"><b><i>; Enable TMR2 Interrupts  
    </i></b></font><font color="#008000"><b>ENDASM
    
    GOSUB </b></font><b>ResetTime
    </b><font color="#008000"><b>GOSUB </b></font><b>StartTimer
    
    Main</b>:
        <font color="#008000"><b>IF </b></font><b>SecondsChanged </b>= <font color="#800000"><b>1 </b></font><font color="#008000"><b>THEN
           LCDOUT </b></font><font color="#800000"><b>$FE</b></font>,<font color="#800000"><b>2</b></font>, <font color="#008000"><b>DEC </b></font><b>Days</b>,<font color="#FF0000">&quot;d-&quot;</font>,<font color="#008000"><b>DEC2 </b></font><b>Hours</b>,<font color="#FF0000">&quot;:&quot;</font>,<font color="#008000"><b>DEC2 </b></font><b>Minutes</b>,<font color="#FF0000">&quot;:&quot;</font>,<font color="#008000"><b>DEC2 </b></font><b>Seconds
           SecondsChanged </b>= <font color="#800000"><b>0
        </b></font><font color="#008000"><b>ENDIF
    GOTO </b></font><b>Main</b>
    Attached Files Attached Files
    DT

  5. #5


    Did you find this post helpful? Yes | No

    Default

    Oh thank you very much. Now I have to compare the two and see exactly what is different and figure out why.

    I know I have to learn ASM as it is the foundation on which PBP is built. It's just a lot harder to understand for us noobies.

  6. #6


    Did you find this post helpful? Yes | No

    Default

    Darrel,

    Is there a better way to output a 82Hz PWM single than using your software routine. Your routine works perfect however I also need to read a frequency of 0-1kHz at the same time. With the resolution of 256 steps @ 82Hz its pretty interrupt hungry.

    Here's what I'm trying to accomplish

    TMR1 is being used for SPWM - 0-24VDC @ 82Hz
    TMR2 is being used for HPWM - 0-10VDC

    If I use the COUNT command it works perfect, only if I disable the interrupts though. This in turn kills the SPWM which I can't have happen. Any suggestions? Not looking for a hand out by any means, just some help pointing in the right direction. The best way to learn is do it yourself I believe.

  7. #7
    Join Date
    Jul 2006
    Posts
    11


    Did you find this post helpful? Yes | No

    Default

    Many of the 18F devices have 2 HPWM ports. You may want to look at using a different pic.
    Regards,

    Ryan O'Hara
    www.ohararp.com

  8. #8


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by ohararp View Post
    Many of the 18F devices have 2 HPWM ports. You may want to look at using a different pic.
    The problem is space is limited on the board. Also the HPWM minimum frequency is 245Hz @ 4MHz.

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by CocaColaKid View Post
    Is there a better way to output a 82Hz PWM single than using your software routine. Your routine works perfect however I also need to read a frequency of 0-1kHz at the same time. With the resolution of 256 steps @ 82Hz its pretty interrupt hungry.
    I'm sure there's a way to get what you need, but can you give me some more info to work with.

    Which PIC?
    What OSC?
    How many SPWM channels?
    What Freq is HPWM running at?
    Is Timer0 available?
    Which Pin is the 0-1khz on, and can it be moved?
    Can whatever is on the T0CKI pin be moved?
    Does it HAVE to be 82hz?
    <br>
    DT

  10. #10


    Did you find this post helpful? Yes | No

    Default

    Oh, guess I missed posting all the relevant information.

    16F88 @ 10MHz
    Single 82Hz SPWM Channel
    Single 1kHz HPWM Channel
    Timer0 - Free, Timer1 - SPWM , Timer2 - HPWM
    The 1kHz HPWM is being output on portb.3, it could be either portb.0 or portb.3
    The porta.4/T0CKI can be made available for use, its just an input
    Unfortunately the 82Hz is required, its the control signal for an ECM motor

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by CocaColaKid View Post
    Oh, guess I missed posting all the relevant information.

    16F88 @ 10MHz
    Single 82Hz SPWM Channel
    Single 1kHz HPWM Channel
    Timer0 - Free, Timer1 - SPWM , Timer2 - HPWM
    The 1kHz HPWM is being output on portb.3, it could be either portb.0 or portb.3
    The porta.4/T0CKI can be made available for use, its just an input
    Unfortunately the 82Hz is required, its the control signal for an ECM motor
    There ya go. Now there's some room to play with.
    But now you'll regret saying you want to do it yourself.

    Since there's only 1 SPWM channel. I would recommend reverting the the original SSPWM program. It only uses 2 interrupts per cycle, 1 for the ON time, and 1 for the OFF time. But it would need to be modified to work at 82hz, since it currently runs at 100. And in the SSPWM routines, you can create a 1sec period for timing the input frequency's measurement.

    Then by feeding the 0-1khz into Timer 0 (T0CKI), you should get a real good count/frequency that works in the background, unlike the COUNT command.
    DT

  12. #12


    Did you find this post helpful? Yes | No

    Default

    Let me see if I get this right. Bare with me because I am still very green on the whole timer thing. I need to set Timer0 to count the pulses coming in on T0CKI for 1 second once a clock is seen. This 1 second interval will be determined from Timer1?

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


    Did you find this post helpful? Yes | No

    Default

    That's the plan.

    Of course, it doesn't have to be a 1 second sample period.
    As long as it's a constant time base, readings can be easily corrected to match the difference.
    <br>
    DT

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