DT Instant Interrupts


Closed Thread
Results 1 to 39 of 39

Hybrid View

  1. #1
    Join Date
    Sep 2007
    Posts
    50


    Did you find this post helpful? Yes | No

    Default

    Hay Darrel,

    In the DT_INTS-14 (SPWM_INT - Multiple Software PWM) It says:

    Code:
    DutyVars   VAR BYTE[3]              ; DutyCycle Variables
      DutyVar1 VAR DutyVars[0]          ; group them in an array for easy access
      DutyVar2 VAR DutyVars[1]          ; with FOR loops etc.
      DutyVar3 VAR DutyVars[2]
    I do not know how to use arrays or how it can benefit in loops. The way I am doing it now is very cumbersome and code intensive. I have searched the forum and RTFM but I can't get my head around how this concept. Can anyone point me in the correct direction.
    Best Regards,

    Kurt A. Kroh
    KrohTech

    “Goodbye and thanks for all the fish”

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


    Did you find this post helpful? Yes | No

    Default Simple example ...

    If you wanted to set all LED's to the same brightness, you could ...
    Code:
    LoopCount  VAR BYTE
    
    FOR LoopCount = 0 to 15         ; 16 channels
        DutyVars(LoopCount) = 50    ; 50% (0-100)
    NEXT LoopCount
    <br>
    DT

  3. #3
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    If you wanted to set all LED's to the same brightness, you could ...
    Code:
    LoopCount  VAR BYTE
    
    FOR LoopCount = 0 to 15         ; 16 channels
        DutyVars(LoopCount) = 50    ; 50% (0-100)
    NEXT LoopCount
    <br>
    Hi Darrel,
    could you please explain DutyVars(LoopCount) = 50 ; 50% (0-100), I understand the counter loop but do not understand the operation here. Thank You
    JS
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  4. #4
    Join Date
    Sep 2007
    Posts
    50


    Did you find this post helpful? Yes | No

    Default

    Hi Derrel,

    Thanks for the code, Unfortunately I was hoping for something that would allow me to set different values to the duty cycle of each channel. The way I have it configured I use CH# as the var name:

    Code:
    DEFINE SPWM_FREQ  100               ; SPWM Frequency
    DEFINE SPWM_RES   101               ; SPWM Resolution
    
    DutyVars   VAR BYTE[16]             ; DutyCycle Variables
      CH1 VAR DutyVars[0]          ; group them in an array for easy access
      CH2 VAR DutyVars[1]          ; with FOR loops etc.
      CH3 VAR DutyVars[2]
      CH4 VAR DutyVars[3]
      CH5 VAR DutyVars[4]
      CH6 VAR DutyVars[5]
      CH7 VAR DutyVars[6]
      CH8 VAR DutyVars[7]
      CH9 VAR DutyVars[8]          
      CH10 VAR DutyVars[9]         
      CH11 VAR DutyVars[10]
      CH12 VAR DutyVars[11]
      CH13 VAR DutyVars[12]
      CH14 VAR DutyVars[13]
      CH15 VAR DutyVars[14]
      CH16 VAR DutyVars[15]
    and change the duty in this manor:

    Code:
    Main: 
    gosub CKINPUT
                                 
    CH1 = 100
    CH2 = 0
    CH3 = 0
    CH4 = 0
    CH5 = 0
    CH6 = 0
    CH7 = 0
    CH8 = 0
    CH9 = 0
    CH10 = 0
    CH11 = 0
    CH12 = 0
    CH13 = 0
    CH14 = 0
    CH15 = 0
    CH16 = 0
    gosub CKINPUT
    PAUSE T5
    CH1 = 100
    CH2 = 100
    CH3 = 0
    CH4 = 0
    CH5 = 0
    CH6 = 0
    CH7 = 0
    CH8 = 0
    CH9 = 0
    CH10 = 0
    CH11 = 0
    CH12 = 0
    CH13 = 0
    CH14 = 0
    CH15 = 0
    CH16 = 0
    gosub CKINPUT
    PAUSE T5
    and so on... If anyone can suggest a better method I would be very interested in learning better ways to program.
    Best Regards,

    Kurt A. Kroh
    KrohTech

    “Goodbye and thanks for all the fish”

  5. #5
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by krohtech View Post
    Code:
    DEFINE SPWM_FREQ  100               ; SPWM Frequency
    DEFINE SPWM_RES   101               ; SPWM Resolution
    DutyVars   VAR BYTE[16]             ; DutyCycle Variables
      CH1 VAR DutyVars[0]          ; group them in an array for easy access
      CH2 VAR DutyVars[1]          ; with FOR loops etc.
    ...............
      CH15 VAR DutyVars[14]
      CH16 VAR DutyVars[15]
    and change the duty in this manor:
    Code:
    Main: 
    gosub CKINPUT
    CH1 = 100
    CH2 = 0
    ............
    CH15 = 0
    CH16 = 0
    gosub CKINPUT
    PAUSE T5
    CH1 = 100
    CH2 = 100
    CH3 = 0
    CH4 = 0
    ...........
    CH15 = 0
    CH16 = 0
    gosub CKINPUT
    PAUSE T5
    and so on... If anyone can suggest a better method I would be very interested in learning better ways to program.
    I don't see what the problem is...
    You've already got CH1 an as alias to DUTYCYCLE[0]...therefore:
    CH1 = 0 (or whatever)
    is equal to
    DUTYCYCLE[0] = 0 (or whatever)
    They are functionally equivalent....

    Therefore, if you had to use a loop:

    for temp = 0 to 16 : dutycycle[ temp ] = 0 : next temp

    would be equal to

    ch1 = 0
    ch2 = 0
    and so on until....
    ch15 = 0
    ch16 = 0

  6. #6
    Join Date
    Sep 2007
    Posts
    50


    Did you find this post helpful? Yes | No

    Default

    Hi Skymask,

    Maybe I can clarify what I am trying to do. I didn’t post my entire code because it is very long. I will attach as a text file. I am designing a sign controller AKA sign animator AKA sign speller. What I need to do is CH1 ON pause X, add CH2 on Pause X, add CH3 pause X … This is an oversimplification but you can get the idea. It will allow me to program patterns left to right, right to left, center out, outside in, fade from left to right etc.

    I guess I was hoping for was some kind of nested for next loop with an array?

    I probably am not phrasing it correctly as I am a beginning programmer. Most of my experience is in programming large theatrical RGB lighting clusters which is not really programming in the same use of the word. I really haven’t “written code” since high school.

    I do appreciate all the help and am enjoying the journey!!!
    Attached Files Attached Files
    Best Regards,

    Kurt A. Kroh
    KrohTech

    “Goodbye and thanks for all the fish”

  7. #7
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by krohtech View Post
    Hi Skymask,
    Maybe I can clarify what I am trying to do. I didn’t post my entire code because it is very long. I will attach as a text file. I am designing a sign controller AKA sign animator AKA sign speller. What I need to do is CH1 ON pause X, add CH2 on Pause X, add CH3 pause X … This is an oversimplification but you can get the idea. It will allow me to program patterns left to right, right to left, center out, outside in, fade from left to right etc.
    I guess I was hoping for was some kind of nested for next loop with an array?
    I probably am not phrasing it correctly as I am a beginning programmer. Most of my experience is in programming large theatrical RGB lighting clusters which is not really programming in the same use of the word. I really haven’t “written code” since high school.
    I do appreciate all the help and am enjoying the journey!!!
    Where do you plan on storing all of this data? On chip eeprom, program memory, off chip serial eeprom, CF card?
    I can see using a FONT table to store all of the characters, each character being a mini-array of points. Then depending on how you read out those points from that array, it may look like the character is shifting left/right/up/down, whatever.

    I think you need to setup an array of data and do matrix operations on that array when dealing with the full screen.
    I.E.
    4 x 4 array = 16 data points, array var byte[16]
    x / y = 4 / 4 = 16
    point 0,0
    x + (y*4) = point in array, in this case point 0, first byte in array
    point 3,3
    x + (y*4) = point in array, in this case point 15, last byte in array
    PBP doesn't do multi-dimensional arrays but you can easily overcome that with some simple math.

  8. #8
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Joe S. View Post
    Hi Darrel,
    could you please explain DutyVars(LoopCount) = 50 ; 50% (0-100), I understand the counter loop but do not understand the operation here. Thank You
    JS
    Anybody ???
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  9. #9
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Joe S. View Post
    Anybody ???
    Nothing more than an index'd variable.

    DutyVars(LoopCount) = 50

    (not code below...)
    If loopcount = 1 then the following two lines are equivalent

    -DutyVars(1) = 50

    -loopcount = 1 : DutyVars(loopcount) = 50

    At least I think that's what you were asking about.
    If that's what you were asking, the book explanation is in Chapter 4.5 of the manual...if not...whoops! My bad

  10. #10
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    OK, so dutyvars is an array holding the changing value loopcount and that = 50 ? This really is Fuzzy . . .
    Code:
     label VAR size[number of elements]
    label = DutyVar
    size = Loopcount
    what does = 50 do exactly?
    Does it give you a 16 byte array all having the value of 50?
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  11. #11
    Join Date
    Sep 2007
    Posts
    50


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Joe S. View Post
    what does = 50 do exactly?
    Does it give you a 16 byte array all having the value of 50?

    Hi Joe,

    50 would be the duty cycle of the PWM. In this example the SPWM_INT duty cycle was setup to be 0 - 100 so 50 would be roughly 50% at 100 Hz. See Below

    DEFINE SPWM_FREQ 100 ; SPWM Frequency = 100 Hz
    DEFINE SPWM_RES 101 ; SPWM Resolution = 0-100
    Best Regards,

    Kurt A. Kroh
    KrohTech

    “Goodbye and thanks for all the fish”

Similar Threads

  1. DT instant interrupts with mister_e keypad
    By Tomexx in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 26th November 2008, 20:02
  2. DT Instant Interrupts help
    By perides in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 26th November 2008, 18:41
  3. 12F683 and DT Instant Interrupts
    By jderson in forum mel PIC BASIC Pro
    Replies: 26
    Last Post: - 22nd November 2008, 12:47
  4. 18F1220 and DT Instant Interrupts
    By jderson in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 30th June 2008, 05:37
  5. Replies: 1
    Last Post: - 1st November 2006, 03:11

Members who have read this thread : 0

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