Controlling OG-4 Decathron with PBP in an efficient way.


Closed Thread
Results 1 to 40 of 40

Hybrid View

  1. #1
    Join Date
    Feb 2013
    Posts
    1,078

    Default Controlling OG-4 Decathron with PBP in an efficient way.

    Hello, I'm adding an OG-4 decathron tube to my open source nixie clock project. It being run by separate PIC and own power supply. The tube has following pins, which are being driven by MPSA42 transistors, controlled via PIC12F683. These pins are


    Z - reset pin,also lights up, let's call it "zero"
    A,B,C - enable pins


    So sequence is as follows:


    do
    pulse Z, then pulse A, B, C in repeating loop, 9 times, after that
    pulse A and then pulse B, to lit up remaining dots
    loop


    This code provides the spinning in clockwise direction (there are also PAUSE statements, to adjust the speed). To reverse the direction, sequence after Z should be C, B, A


    So what I want to achieve. It does 1 complete run and comes back to zero. Then starts at 1st dot at right to zero and again makes 1 complete run and comes back to 1st dot. After that, it starts from 2nd dot and makes turn till it reaches 2 again, then starts at 3 and goes to 3 and so on, including 29th dot. Then starts over


    I've developed very crude and inefficient code for that, which runs on 12F683. I only have made animation till 10th dot and it already using 1k of available chip memory. Of course, I can switch to say 12F1840, but code is still not that good - any attempt to add say 2 times making the same rotation needs complete code rewrite. So is there a way that my code can be optimized? or I have another idea, Decathron tube can be considered as a kind of shift register, so maybe there is another, more efficient approach of doing the above task?

    Here is my code

    Code:
    '****************************************************************
    '*  Name    : UNTITLED.BAS                                      *
    '*  Author  : [select VIEW...EDITOR OPTIONS]                    *
    '*  Notice  : Copyright (c) 2014 [select VIEW...EDITOR OPTIONS] *
    '*          : All Rights Reserved                               *
    '*  Date    : 15.05.2014                                        *
    '*  Version : 1.0                                               *
    '*  Notes   :                                                   *
    '*          :                                                   *
    '****************************************************************
    ANSEL = %00000000    
    CMCON0 = 7 
    TRISIO=%00001000
    OSCCON = %01110111
    'Include "Modedefs.bas"
    Define	OSC	8		' Set Xtal Frequency
    
    
    '	Clk     Var	GPIO.5		' Data is clocked on rising edge of this pin            kviteli
    '	Dta  	Var	GPIO.4		' Bits are shifted out of this pin          stafilosferi
    
    
    ZERO    var     GPIO.0
    ONE     VAR     GPIO.4
    TWO     VAR     GPIO.1
    TRE   VAR      GPIO.2
    cik var word  'loop variable
    x   var word   'delay variable
    increment var word 'incremental variable
    lop var word  'also variable
    increment=0  'temp
    sub var word 'intracounter variable
    sub=9
    x=30
    
    
    'INIT tube and reset to 0
    inika:
    LOW ONE
    LOW TWO
    LOW TRE
    HIGH ZERO
    PAUSE x
    LOW ZERO
    
    
    tavi:         
    
    
    'stage 1______________________________________________
    sub=9
    gosub sub9
    high one  'proper finish?  one and two
    pause x
    low one
    high two
    pause x
    low two
    high zero
    pause 1000'delay for display
    low zero
    
    
    
    
    'stage 2 ______________________________________________
    
    
    gosub sub9
    
    
    gosub subzero
    pause 1000
    low one
    
    
    'stage 3____________________________________________
    
    
    gosub sub9
    
    
    gosub subzero
    pause x
    high two
    low one
    pause 1000
    high tre
    low two
    pause x
    low tre
    
    
    'stage 4____________________________________________
    sub=8
    gosub sub9
    
    
    gosub subzero
    pause x
    high two
    low one
    pause x
    high tre
    low two
    pause 1000
    low tre
    
    
    'stage 5____________________________________________
    
    
    gosub sub9
    
    
    gosub subzero
    pause x
    high two
    low one
    pause x
    high tre
    low two
    pause x
    high one
    low tre
    pause 1000
    low one
    
    
    'stage 6____________________________________________
    
    
    gosub sub9
    
    
    gosub subzero
    pause x
    high two
    low one
    pause x
    high tre
    low two
    pause x
    high one
    low tre
    pause x
    high two
    low one
    pause 1000
    high tre
    low two
    
    
    'stage 7____________________________________________
    pause x
    low tre
    sub=7
    gosub sub9
    
    
    gosub subzero
    pause x
    high two
    low one
    pause x
    high tre
    low two
    pause x
    high one
    low tre
    pause x
    high two
    low one
    pause x
    high tre
    low two
    pause 1000
    low tre
    
    
    'stage 8____________________________________________
    gosub sub9
    
    
    gosub subzero
    pause x
    high two
    low one
    pause x
    high tre
    low two
    pause x
    high one
    low tre
    pause x
    high two
    low one
    pause x
    high tre
    low two
    pause x
    high one
    low tre
    pause 1000
    low one
    
    
    'stage 9____________________________________________
    'X=100
    gosub sub9
    
    
    gosub subzero
    pause x
    high two
    low one
    pause x
    high tre
    low two
    pause x
    high one
    low tre
    pause x
    high two
    low one
    pause x
    high tre
    low two
    pause x
    high one
    low tre
    pause x
    high two
    low one
    pause 1000
    high tre
    low two
    pause x
    
    
    'stage 10____________________________________________
    low tre
    sub=6
    gosub sub9
    
    
    gosub subzero
    pause x
    high two
    low one
    pause x
    high tre
    low two
    pause x
    high one
    low tre
    pause x
    high two
    low one
    pause x
    high tre
    low two
    pause x
    high one
    low tre
    pause x
    high two
    low one
    pause x
    high tre
    low two
    pause 1000
    low tre
    
    
    
    
    goto tavi
    
    
    sub9 'subroutine for spinning
    
    
    for cik=1 to sub 'amount needed for full loop
    high one
    pause x
    high two
    low one
    pause x
    high tre
    low two
    pause x
    low tre
    next
    
    
    return
    
    
    
    
    subzero:
    
    
    high one  'proper finish?  one and two
    pause x
    high two
    low one
    pause x
    high zero
    low two
    pause x'delay for display
    high one
    low zero 'subzero here
    
    
    return

  2. #2
    Join Date
    Aug 2011
    Posts
    408


    Did you find this post helpful? Yes | No

    Default Re: Controlling OG-4 Decathron with PBP in an efficient way.

    One simple thing you can do is to combine commonly occurring sequences into a sub, for example
    Code:
    hl2:
        pause x
        high two
        low one
    return
    doing that (and making variables 'byte' instead of 'word') drops it down from 1K to 330
    Code:
    '****************************************************************
    '*  Name    : UNTITLED.BAS                                      *
    '*  Author  : [select VIEW...EDITOR OPTIONS]                    *
    '*  Notice  : Copyright (c) 2014 [select VIEW...EDITOR OPTIONS] *
    '*          : All Rights Reserved                               *
    '*  Date    : 15.05.2014                                        *
    '*  Version : 1.0                                               *
    '*  Notes   :                                                   *
    '*          :                                                   *
    '****************************************************************
    'device=PIC12F683
    
    'Include "Modedefs.bas"
    Define  OSC 8       ' Set Xtal Frequency
    
    cik var byte       'loop variable
    x   var byte        'delay variable
    sub var byte        'intracounter variable
    
    ZERO    var     GPIO.0
    ONE     VAR     GPIO.4
    TWO     VAR     GPIO.1
    TRE     VAR     GPIO.2
    
    ANSEL = %00000000    
    CMCON0 = 7 
    TRISIO = %00001000
    OSCCON = %01110111
    
    
    sub=9
    x=30
    
    'INIT tube and reset to 0
    inika:
    LOW ONE
    LOW TWO
    LOW TRE
    HIGH ZERO
    PAUSE x
    LOW ZERO
    
    tavi:         
    
    'stage 1______________________________________________
    sub=9
    gosub sub9
    
    high one  'proper finish?  one and two
    gosub hl2
    gosub hl0
    pause 1000  'delay for display
    low zero
    
    'stage 2 ______________________________________________
    gosub sub9
    gosub subzero
    pause 1000
    low one
    
    'stage 3____________________________________________
    gosub sub9
    gosub subzero
    gosub hl2
    pause 1000
    gosub hl3
    low tre
    
    'stage 4____________________________________________
    sub=8
    gosub sub9
    gosub subzero
    gosub hl2
    gosub hl3
    pause 1000
    low tre
    
    'stage 5____________________________________________
    gosub sub9
    gosub subzero
    gosub hl2
    gosub hl3
    gosub hl1
    pause 1000
    low one
    
    'stage 6____________________________________________
    gosub sub9
    gosub subzero
    gosub hl2
    gosub hl3
    gosub hl1
    gosub hl2
    pause 1000
    high tre
    low two
    
    
    'stage 7____________________________________________
    pause x
    low tre
    sub=7
    gosub sub9
    gosub subzero
    gosub hl2
    gosub hl3
    gosub hl1
    high two
    low one
    gosub hl3
    pause 1000
    low tre
    
    'stage 8____________________________________________
    gosub sub9
    gosub subzero
    gosub hl2
    gosub hl3
    gosub hl1
    gosub hl2
    gosub hl3
    gosub hl1
    pause 1000
    low one
    
    
    'stage 9____________________________________________
    'X=100
    gosub sub9
    gosub subzero
    gosub hl2
    gosub hl3
    gosub hl1
    gosub hl2
    gosub hl3
    gosub hl1
    gosub hl2
    pause 1000
    high tre
    low two
    pause x
    
    'stage 10____________________________________________
    low tre
    sub=6
    gosub sub9
    gosub subzero
    gosub hl2
    gosub hl3
    gosub hl1
    gosub hl2
    gosub hl3
    gosub hl1
    gosub hl2
    gosub hl3
    pause 1000
    low tre
    
    goto tavi
    
    hl0:
        pause x'delay for display
        high zero
        low two
    return
        
    hl1:
        pause x
        high one
        low tre
    return
    
    hl2:
        pause x
        high two
        low one
    return
    
    hl3:
        pause x
        high tre
        low two
    return
    
    sub9: 'subroutine for spinning
        for cik=1 to sub 'amount needed for full loop
            gosub hl1
            gosub hl2
            gosub hl3
        next
        low tre
    return
    
    
    subzero:
        high one  'proper finish?  one and two
        gosub hl2
        high zero
        low two
        pause x'delay for display
        high one
        low zero 'subzero here
    return
    I've bound to have goofed that up somewhere so it's up to you to fix whatever I screwed up, but you get the idea.

  3. #3
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: Controlling OG-4 Decathron with PBP in an efficient way.

    Yeah I already started that, but had no idea, going from word to byte will save that much space
    I'm still thinking, decathron is a ring counter/shift register, so maybe there is some other ways of controlling it....

  4. #4
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,519


    Did you find this post helpful? Yes | No

    Default Re: Controlling OG-4 Decathron with PBP in an efficient way.

    And stop using HIGH/LOW, those waste both time and space.

    The animation can most likely be done with two FOR loops. An outer that steps thru the starting position from 1 to 29 and an inner that "sweeps the circle" one revolution starting/stopping at the dot pointed to by the outer loop.

    If I'm not mistaken the effect you're after is similar to the the common "please wait the computer is busy" circle thingy you see on Windows systems?

    /Henrik.

  5. #5
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: Controlling OG-4 Decathron with PBP in an efficient way.

    You can't do it with two FOR loops, because you have to consider the reset pin and fact that number of dots is even, but number of control pins is odd. So it is always required to add an extra step out of loop, depending on even/odd current position.

    The effect I'm making is as follows. Rotation starts from dot 1 and comes again to dot 1, stops there for a second, then quickly rotates one full loop, but stops at dot #1. Waits for a second, full spin and stop at dot #2 and so on, till it makes full turn.

  6. #6
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,519


    Did you find this post helpful? Yes | No

    Default Re: Controlling OG-4 Decathron with PBP in an efficient way.

    If you say so :-)
    Do you have a datasheet describing the driving signals, I'm having some difficulties understanding how it works based on your description.

    /Henrik.

  7. #7
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,802


    Did you find this post helpful? Yes | No

    Default Re: Controlling OG-4 Decathron with PBP in an efficient way.

    Quote Originally Posted by HenrikOlsson View Post
    And stop using HIGH/LOW, those waste both time and space....
    /Henrik.
    Well, I have some doubts about this. If it relates to output port registers I think it is necessary to use High/Low commands. Or at least this used to be the case with older versions of PBB.

    Direct control of port registers like this portb.0=1 may cause problems when the program is long because of memory page issues. I may be wrong here. Anyone?

    Ioannis

  8. #8
    Join Date
    May 2013
    Location
    australia
    Posts
    2,386


    Did you find this post helpful? Yes | No

    Default Re: Controlling OG-4 Decathron with PBP in an efficient way.

    If it relates to output port registers I think it is necessary to use High/Low commands.
    the only problem with high/low is that they waste time and code space setting/clearing the tris register ,every time they are invoked.


    Direct control of port registers like this portb.0=1 may cause problems when the program is long because of memory page issues.
    the only issue with direct port writes once you have the tris reg set appropriately is the potential for rmw issues , especially at high clock speeds.
    always use lat regs if possible and a shadow reg otherwise if rapid sequential port manipulation of individual pins will be employed
    Warning I'm not a teacher

Similar Threads

  1. Subroutine or repeated code, which is more memory efficient?
    By CuriousOne in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 5th June 2014, 22:38
  2. large & efficient electro magnet
    By therian in forum Off Topic
    Replies: 13
    Last Post: - 19th October 2012, 06:53
  3. Making code more efficient, any ideas please?
    By BobEdge in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 26th July 2011, 13:28
  4. Efficient comparison on data (iButton)
    By enigma in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 27th August 2010, 13:37
  5. Is there a more efficient way?
    By markedwards in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 25th July 2005, 23:38

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