PDA

View Full Version : Controlling OG-4 Decathron with PBP in an efficient way.



CuriousOne
- 29th April 2020, 20:18
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



'************************************************* ***************
'* 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

tumbleweed
- 29th April 2020, 21:40
One simple thing you can do is to combine commonly occurring sequences into a sub, for example


hl2:
pause x
high two
low one
return


doing that (and making variables 'byte' instead of 'word') drops it down from 1K to 330


'************************************************* ***************
'* 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.

CuriousOne
- 29th April 2020, 21:56
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....

HenrikOlsson
- 30th April 2020, 09:18
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.

CuriousOne
- 30th April 2020, 10:09
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.

HenrikOlsson
- 30th April 2020, 18:12
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.

CuriousOne
- 30th April 2020, 20:44
I have only Russian book about it. But principle of operation is nicely shown in animation here:

https://threeneurons.wordpress.com/dekatron-stuff/

Ioannis
- 30th April 2020, 20:47
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

richard
- 30th April 2020, 23:23
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

mpgmike
- 30th April 2020, 23:30
Most everything PIC made in the past decade features LATx Registers;
LATB.0 = 1
(Of course you could also insert a bit of ASM if FOSC cycles are important:)
@ BANKSEL LATB
@ BSF LATB,0

CuriousOne
- 1st May 2020, 04:31
For this particular case, speed is not an issue, since these tubes have couple of KHz max operating frequency, and in my case there are Pause 30 and Pause 1000 statements :)

CuriousOne
- 5th May 2020, 06:40
Run into strange problem - setting GPIO.5 as input messes with GPIO.4 - it becomes high when GPIO.5 is read, so disrupts complete code routine. I'm using TRISIO=%00100000 to make GPIO.5 as input. If I disable it as input, then other code works fine.

mpgmike
- 5th May 2020, 08:32
In your code at the top of the page you list TRISIO=%00001000. Of course GPIO.3 is MCLR and is Input only. In the previous post you state you are having problems with TRISIO=%00100000. It's probably not your issue, but try TRISIO=%00101000.

CuriousOne
- 5th May 2020, 08:43
It does not helps. And I'm not using MCLR pin for anything except programming. Tried TRISIO=%00101000 but that does not helps. Tried disabling MCLR from config, also no change. Making a pin input creates issues with others being output.

CuriousOne
- 5th May 2020, 09:02
I tried to replace HIGH/LOW statements with TRISIO.X=1 or 0, it does not helps. In fact, say TRISIO.0=1 does not make GPIO.0 pin high.

mpgmike
- 5th May 2020, 09:03
Did you try a new PIC? I've never seen what you're describing. Thinking something internal might be whacked.

richard
- 5th May 2020, 09:10
its a classic rmw problem.
can also be caused by excessive load on output pin (capacitive or resitive) causing pin to not achieve proper logic level.

CuriousOne
- 5th May 2020, 09:18
Yes tried new chip. Output pins are connected to MPSA42 transistor via 10K resistor.

CuriousOne
- 5th May 2020, 09:23
If I swap chip with 12F1840, will problem still exist?

CuriousOne
- 5th May 2020, 09:45
I decided to put it aside, to give my mind some rest, and back to DS3231.
I found that it does not return seconds properly.

Have two different example codes, they work fine for minutes and hours, but does not work for seconds - seconds increase like 02 04 08 10 12 14 16 till 28, then 29 and again increase in 2 and so on.



SecondsMSB=BCDSeconds & $70
SecondsMSB=SecondsMSB>>4
SecondsLSB=BCDSeconds & $0F '
Seconds=(SecondsMSB*10)+SecondsLSB 'combines DECMinutes MSB and LSB


x=RTCSEC >> 4
Y=RTCseC // 16
z=X*10+Y

richard
- 5th May 2020, 09:50
If I swap chip with 12F1840, will problem still exist?
more than likely , you need to understand and remedy the situation.

http://www.picbasic.co.uk/forum/showthread.php?t=15843&highlight=shadow
http://www.picbasic.co.uk/forum/showthread.php?t=15013&highlight=shadow

a (http://www.picbasic.co.uk/forum/showthread.php?t=15843&highlight=shadow)nd post your code and a schematic so we don't just keep guessing

CuriousOne
- 5th May 2020, 10:08
Code is posted above.

Schematic is simple, there are 4 MPSA42 transistors, each of which is connected via 10K resistor to corresponding ports (ZERO, ONE, TWO, TRE) as shown in code. GPIO.5 is tied via 10K resistor to VDD, and button pulls it to zero.

Only addition to code above is



koka:

if GPIO.5=0 THEN 'if pin pressed
goto tavi 'launch rotation
ENDIF
pause 1
GOTO KOKA

richard
- 5th May 2020, 10:16
and post your code and a schematic so we don't just keep guessing
i mean post the code you are using now!
i'm likely to make mistakes going back through several pages of add infested forum to try and patch together what i think you may be using.
and even a hand drawn schematic makes things clearer

CuriousOne
- 5th May 2020, 10:18
OK one moment, let me finish this first, figured DS3231 error reason now, it was due to re-using variable. I need rest, serious rest :D

CuriousOne
- 5th May 2020, 10:23
Here it is:

if I change TRISIO config so port 5 is no longer input and directly launch the code, it works properly.



'************************************************* ***************
'* 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 'disable analog
CMCON0 = 7 'disable comparators
TRISIO=%00101000 'input config
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 byte 'loop variable
x var byte 'delay variable
increment var byte 'incremental variable
lop var byte 'also variable
increment=0 'temp
sub var byte 'intracounter variable
sub=9
x=44 '22 x and 295 y for 30 second loop
y var word 'showdelay 44 and 590 for 1 minute loop
y=590
'INIT tube and reset to 0
inika:
LOW ONE
LOW TWO
LOW TRE
HIGH ZERO
PAUSE x
high one
LOW ZERO
pause x
high two
low one
pause x
high tre
low two
pause x
high zero
low tre
pause x
low zero
koka:
if GPIO.5=0 THEN
goto tavi
ENDIF
pause 1
GOTO KOKA
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 Y'delay for display
low zero
sta2:
'stage 2 ______________________________________________
gosub sub9
gosub subzero
Pause Y
low one
'stage 3____________________________________________
gosub sub9
gosub subzero
pause x
high two
low one
Pause Y
high tre
low two
pause x
low tre
'stage 4____________________________________________
sub=8
gosub sub9
gosub subzero
gosub sub2
Pause Y
low tre
'stage 5____________________________________________
gosub sub9
gosub subzero
gosub sub2
pause x
high one
low tre
Pause Y
low one
'stage 6____________________________________________
gosub sub9
gosub subzero
gosub sub2
pause x
high one
low tre
pause x
high two
low one
Pause Y
high tre
low two
'stage 7____________________________________________
pause x
low tre
sub=7
gosub sub9
gosub subzero
gosub sub2
pause x
high one
low tre
pause x
high two
low one
pause x
high tre
low two
Pause Y
low tre
'stage 8____________________________________________
gosub sub9
gosub subzero
gosub sub2
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 Y
low one
'stage 9____________________________________________
'X=100
gosub sub9
gosub subzero
gosub sub2
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 Y
high tre
low two
pause x
'stage 10____________________________________________
low tre
sub=6
gosub sub9
gosub subzero
gosub sub2
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 Y
low tre
'stage 11____________________________________________
low tre
sub=6
gosub sub9
gosub subzero
pause x
high two
low one
pause x
high tre
low two
pause x
gosub sub1
high one
low tre
Pause Y
low ONE
'stage 12____________________________________________
low tre
sub=6
gosub sub9
gosub subzero
pause x
high two
low one
pause x
high tre
low two
pause x
gosub sub1
high one
low tre
pause x
high two
low ONE
Pause Y
low two
'stage 13____________________________________________
high tre
pause x
low tre
sub=5
gosub sub9
gosub subzero
gosub sub2
pause x
'-----
gosub sub1
'------
high one
low tre
pause x
high two
low ONE
pause x
high tre
low two
Pause Y
low tre
'stage 14____________________________________________
sub=5
gosub sub9
gosub subzero
gosub sub2
pause x
'-----
gosub sub1
'------
high one
low tre
pause x
high two
low ONE
pause x
high tre
low two
pause x
high one
low tre
Pause Y
low one
'stage 15____________________________________________
sub=5
gosub sub9
gosub subzero
gosub sub2
pause x
'-----
gosub sub1
'------
high one
low tre
gosub sub2
pause x
high one
low tre
pause x
high two
low one
Pause Y
low two
'stage 16____________________________________________
high tre
pause x
low tre
sub=4
gosub sub9
gosub subzero
gosub sub2
pause x
'-----
gosub sub1
'------
high one
low tre
gosub sub2
pause x
high one
low tre
pause x
high two
low one
pause x
high tre
low two
Pause Y
low tre
'stage 17____________________________________________
sub=4
gosub sub9
gosub subzero
gosub sub2
pause x
'-----
gosub sub1
'------
high one
low tre
gosub sub2
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 Y
low one
'stage 18____________________________________________
sub=4
gosub sub9
gosub subzero
gosub sub2
pause x
'-----
gosub sub1
'------
high one
low tre
gosub sub2
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 Y
low two
'stage 19____________________________________________
high tre
pause x
low tre
sub=3
gosub sub9
gosub subzero
gosub sub2
pause x
'-----
gosub sub1
'------
high one
low tre
gosub sub2
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 Y
low tre
'stage 20____________________________________________
sub=3
gosub sub9
gosub subzero
gosub sub2
pause x
'-----
gosub sub1
'------
high one
low tre
gosub sub2
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 x
high one
low tre
Pause Y
low one

'stage 21____________________________________________
sub=3
gosub sub9
gosub subzero
gosub sub2
pause x
'-----
gosub sub1
'------
high one
low tre
gosub sub2
pause x
gosub sub1
high one
low tre
pause X
high two
low one
Pause Y
low two
'stage 22____________________________________________
high tre
pause x
low tre
sub=2
gosub sub9
gosub subzero
gosub sub2
pause x
'-----
gosub sub1
'------
high one
low tre
gosub sub2
pause x
gosub sub1
high one
low tre
pause X
high two
low one
pause x
high tre
low two
Pause Y
low tre

'stage 23____________________________________________
sub=2
gosub sub9
gosub subzero
gosub sub2
pause x
'-----
gosub sub1
'------
high one
low tre
gosub sub2
pause x
gosub sub1
high one
low tre
gosub sub2
pause X
high one
low tre
Pause Y
low one
'stage 24____________________________________________
sub=2
gosub sub9
gosub subzero
gosub sub2
pause x
'-----
gosub sub1
'------
high one
low tre
gosub sub2
pause x
gosub sub1
high one
low tre
gosub sub2
pause X
high one
low tre
pause X
high two
low one
Pause Y
low two
'stage 25____________________________________________
high tre
pause x
low tre
sub=1
gosub sub9
gosub subzero
gosub sub2
pause x
'-----
gosub sub1
'------
high one
low tre
gosub sub2
pause x
gosub sub1
high one
low tre
gosub sub2
pause X
high one
low tre
pause X
high two
low one
pause x
high tre
low two
Pause Y
low tre
'stage 26____________________________________________
sub=1
gosub sub9
gosub subzero
gosub sub2
pause x
'-----
gosub sub1
'------
high one
low tre
gosub sub2
pause x
gosub sub1
gosub sub1
high one
low tre
Pause Y
low one
'stage 27____________________________________________
sub=1
gosub sub9
gosub subzero
gosub sub2
pause x
'-----
gosub sub1
'------
high one
low tre
gosub sub2
pause x
gosub sub1
gosub sub1
high one
low tre
pause x
high two
low one
Pause Y
low two
'stage 28____________________________________________
high tre
pause x
low tre
'sub=1
'gosub sub9
gosub subzero
gosub sub2
pause x
'-----
gosub sub1
'------
high one
low tre
gosub sub2
pause x
gosub sub1
gosub sub1
high one
low tre
pause x
high two
low one
pause x
high tre
low two
Pause Y
low tre
'x=400
'stage 29____________________________________________
high one
pause x
high two
low one
pause x
high zero
low two
pause x
low zero
sub=9
gosub sub9
high one
Pause Y
low one
'x=400
'stage 30____________________________________________
high two
pause x
high zero
low two
pause x
low zero
sub=9
gosub sub9
high one
pause x
high two
low one
Pause Y
low two

'stage 31____________________________________________
high zero
pause x
low zero
sub=9
gosub sub9
high one 'proper finish? one and two
pause x
low one
high two
pause x
low two
high zero
Pause Y
low zero
goto koka
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
sub1: 'smaller sub
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 x
return
sub2: 'even smaller sub
pause x
high two
low one
pause x
high tre
low two
return

richard
- 5th May 2020, 11:00
the code compiles and runs flawlessly in proteus, thats not the issue , check your circuit

8848

CuriousOne
- 5th May 2020, 11:02
Check for what?

If I replace TRISIO=%00101000 with TRISIO=%00001000, it will also work fine (but without a button).

richard
- 5th May 2020, 11:48
put an oscilloscope/logic analyser on gpio.4 and see what the signal looks like or if you don't have one
put a led on gpio.4 in lieu of whats there now if it does not change state when gpio.5 is read then whatever is on gpio.4 is loading pin excessively.
or else your description of the problem maybe unclear or inaccurate

there are several of these
gosub sub9

i cant see a sub9 anywhere in your code

CuriousOne
- 5th May 2020, 12:41
sub9 'subroutine for spinning - it is there :)

The whole circuit is assembled into box and potted with epoxy, so have no access to pins, except GPIO.5, I can check it with scope if needed.

richard
- 5th May 2020, 12:47
sub9 'subroutine for spinning - it is there

only by mcs's good grace to call anything unknown a label, the colon is missing


The whole circuit is assembled into box and potted with epoxy,
that would be me out .

CuriousOne
- 5th May 2020, 13:16
I potted it because it worked very fine, until I added that input parsing code :D
I can build another one, that is not an issue...

mpgmike
- 5th May 2020, 14:48
low
tre
next
return
subzero:
What is "next" doing? Is that a forgotten relic from previous versions?

CuriousOne
- 5th May 2020, 15:31
Look a bit above: for cik=1 to sub 'amount needed for full loop

CuriousOne
- 5th May 2020, 18:32
Here is the main code, from which all this started. This is simple spinner, pausing at certain position after whole loop.



'************************************************* ***************
'* 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
x var word
cok var word
lop var word


x=50


'INIT
LOW ONE
LOW TWO
LOW TRE
HIGH ZERO
PAUSE x
LOW ZERO


'this loop does smooth full turn


xoxi:
for cik=1 to 9
high one
pause x
high two
low one
pause x
high tre
low two
pause x
low tre
next


high one 'proper finish? one and two
pause x
low one
high two
pause x
low two
high zero
pause 1000
low zero
goto xoxi


It works fine, provides smooth looped animation.

Now let's add something. Changed TRISIO=%00101000. Code works fine. Added button check loop, and it becomes messed - triggering of certain pin no longer works.



kuku:
if gpio.5=0 then goto xoxi
pause 1
goto kuku

CuriousOne
- 6th May 2020, 09:57
Tried to change control pin to GPIO.3 (MCLR). No change, as long as reading of port occurs in software, the glitches come on.

CuriousOne
- 6th May 2020, 11:58
I think I've nailed it, and it appears to be both software and hardware issue. If input is activated, at startup, there is small pulse on random pin, which is short enough for not to be noticeable by eye, but enough to trigger dekathron (traced using scope). Solved by pulling down outputs via 10K to GND. S

CuriousOne
- 6th May 2020, 15:27
8850

Almost there :)

Ioannis
- 6th May 2020, 17:01
Truly amazing!

Ioannis

CuriousOne
- 6th May 2020, 19:47
Thanks, this is so called "deluxe" version, with OG-4. I'm also developing simple version, with less brass and using simpler tubes. Will also make it's design plans public :)

CuriousOne
- 7th May 2020, 06:20
Here's fixed code. Besides code, you need also 10k pulldown resistors from transistor bases to GND.



;----[12F683 Hardware Configuration]--------------------------------------------
#IF __PROCESSOR__ = "12F683"
#DEFINE MCU_FOUND 1
#CONFIG
cfg = _INTOSCIO ; INTOSCIO oscillator: I/O function on RA4/OSC2/CLKOUT pin, I/O function on RA5/OSC1/CLKIN
cfg&= _WDT_OFF ; WDT disabled
cfg&= _PWRTE_OFF ; PWRT disabled
cfg&= _MCLRE_OFF ; MCLR pin function is digital input, MCLR internally tied to VDD
cfg&= _CP_OFF ; Program memory code protection is disabled
cfg&= _CPD_OFF ; Data memory code protection is disabled
cfg&= _BOD_OFF ; BOR disabled
cfg&= _IESO_ON ; Internal External Switchover mode is enabled
cfg&= _FCMEN_ON ; Fail-Safe Clock Monitor is enabled
__CONFIG cfg


#ENDCONFIG


#ENDIF


;----[Verify Configs have been specified for Selected Processor]----------------
; Note: Only include this routine once, after all #CONFIG blocks
#IFNDEF MCU_FOUND
#ERROR "No CONFIGs found for [" + __PROCESSOR__ +"]"
#ENDIF


ANSEL = %00000000 'disable analog
CMCON0 = 7 'disable comparators
TRISIO=%00001000 'input config
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 byte 'loop variable
x var byte 'delay variable
increment var byte 'incremental variable
lop var byte 'also variable
increment=0 'temp
sub var byte 'intracounter variable
sub=9
x=22 '22 x and 295 y for 30 second loop
y var word 'showdelay 44 and 590 for 1 minute loop
y=295
pause 500
'INIT tube and reset to 0
'x=2000


inika:
LOW ONE
LOW TWO
LOW TRE
HIGH ZERO
PAUSE x
high one
LOW ZERO
pause x
high two
low one
pause x
high tre
low two
pause x
high zero
low tre
pause x
low zero


koka:


if GPIO.3=0 THEN
low tre
low two
low one
high zero
pause x
low zero
goto tavi
ENDIF
pause 1
GOTO KOKA


tavi:



'stage 1______________________________________________
'high zero
'pause x
'low zero
sub=9
gosub sub9
high one 'proper finish? one and two
pause x
low one
high two
pause x
low two
high zero
Pause Y'delay for display
low zero


sta2:
'stage 2 ______________________________________________


gosub sub9


gosub subzero
Pause Y
low one


'stage 3____________________________________________


gosub sub9


gosub subzero
pause x
high two
low one
Pause Y
high tre
low two
pause x
low tre


'stage 4____________________________________________
sub=8
gosub sub9


gosub subzero
gosub sub2
Pause Y
low tre


'stage 5____________________________________________


gosub sub9


gosub subzero
gosub sub2
pause x
high one
low tre
Pause Y
low one


'stage 6____________________________________________


gosub sub9


gosub subzero
gosub sub2
pause x
high one
low tre
pause x
high two
low one
Pause Y
high tre
low two


'stage 7____________________________________________
pause x
low tre
sub=7
gosub sub9


gosub subzero
gosub sub2
pause x
high one
low tre
pause x
high two
low one
pause x
high tre
low two
Pause Y
low tre


'stage 8____________________________________________
gosub sub9


gosub subzero
gosub sub2
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 Y
low one


'stage 9____________________________________________
'X=100
gosub sub9


gosub subzero
gosub sub2
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 Y
high tre
low two
pause x


'stage 10____________________________________________
low tre
sub=6
gosub sub9


gosub subzero
gosub sub2
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 Y
low tre


'stage 11____________________________________________
low tre
sub=6
gosub sub9


gosub subzero
pause x
high two
low one
pause x
high tre
low two
pause x


gosub sub1


high one
low tre
Pause Y
low ONE


'stage 12____________________________________________
low tre
sub=6
gosub sub9


gosub subzero
pause x
high two
low one
pause x
high tre
low two
pause x


gosub sub1


high one
low tre
pause x
high two
low ONE
Pause Y
low two


'stage 13____________________________________________
high tre
pause x
low tre
sub=5
gosub sub9


gosub subzero
gosub sub2
pause x
'-----
gosub sub1
'------
high one
low tre
pause x
high two
low ONE
pause x
high tre
low two
Pause Y
low tre


'stage 14____________________________________________
sub=5
gosub sub9


gosub subzero
gosub sub2
pause x
'-----
gosub sub1
'------
high one
low tre
pause x
high two
low ONE
pause x
high tre
low two
pause x
high one
low tre
Pause Y
low one


'stage 15____________________________________________
sub=5
gosub sub9


gosub subzero
gosub sub2
pause x
'-----
gosub sub1
'------
high one
low tre
gosub sub2
pause x
high one
low tre
pause x
high two
low one
Pause Y
low two


'stage 16____________________________________________
high tre
pause x
low tre
sub=4
gosub sub9


gosub subzero
gosub sub2
pause x
'-----
gosub sub1
'------
high one
low tre
gosub sub2
pause x
high one
low tre
pause x
high two
low one
pause x
high tre
low two
Pause Y
low tre


'stage 17____________________________________________
sub=4
gosub sub9


gosub subzero
gosub sub2
pause x
'-----
gosub sub1
'------
high one
low tre
gosub sub2
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 Y
low one


'stage 18____________________________________________
sub=4
gosub sub9


gosub subzero
gosub sub2
pause x
'-----
gosub sub1
'------
high one
low tre
gosub sub2
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 Y
low two


'stage 19____________________________________________
high tre
pause x
low tre
sub=3
gosub sub9


gosub subzero
gosub sub2
pause x
'-----
gosub sub1
'------
high one
low tre
gosub sub2
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 Y
low tre


'stage 20____________________________________________
sub=3
gosub sub9


gosub subzero
gosub sub2
pause x
'-----
gosub sub1
'------
high one
low tre
gosub sub2
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 x
high one
low tre
Pause Y
low one






'stage 21____________________________________________
sub=3
gosub sub9


gosub subzero
gosub sub2
pause x
'-----
gosub sub1
'------
high one
low tre
gosub sub2
pause x
gosub sub1


high one
low tre
pause X
high two
low one
Pause Y
low two


'stage 22____________________________________________
high tre
pause x
low tre
sub=2
gosub sub9


gosub subzero
gosub sub2
pause x
'-----
gosub sub1
'------
high one
low tre
gosub sub2
pause x
gosub sub1


high one
low tre
pause X
high two
low one
pause x
high tre
low two
Pause Y
low tre




'stage 23____________________________________________
sub=2
gosub sub9


gosub subzero
gosub sub2
pause x
'-----
gosub sub1
'------
high one
low tre
gosub sub2
pause x
gosub sub1


high one
low tre
gosub sub2
pause X
high one
low tre
Pause Y
low one


'stage 24____________________________________________
sub=2
gosub sub9


gosub subzero
gosub sub2
pause x
'-----
gosub sub1
'------
high one
low tre
gosub sub2
pause x
gosub sub1


high one
low tre
gosub sub2
pause X
high one
low tre
pause X
high two
low one
Pause Y
low two


'stage 25____________________________________________
high tre
pause x
low tre
sub=1
gosub sub9


gosub subzero
gosub sub2
pause x
'-----
gosub sub1
'------
high one
low tre
gosub sub2
pause x
gosub sub1
high one
low tre
gosub sub2
pause X
high one
low tre
pause X
high two
low one
pause x
high tre
low two
Pause Y
low tre


'stage 26____________________________________________
sub=1
gosub sub9


gosub subzero
gosub sub2
pause x
'-----
gosub sub1
'------
high one
low tre
gosub sub2
pause x
gosub sub1
gosub sub1
high one
low tre
Pause Y
low one


'stage 27____________________________________________
sub=1
gosub sub9


gosub subzero
gosub sub2
pause x
'-----
gosub sub1
'------
high one
low tre
gosub sub2
pause x
gosub sub1
gosub sub1
high one
low tre
pause x
high two
low one
Pause Y
low two


'stage 28____________________________________________
high tre
pause x
low tre
'sub=1
'gosub sub9


gosub subzero
gosub sub2
pause x
'-----
gosub sub1
'------
high one
low tre
gosub sub2
pause x
gosub sub1
gosub sub1
high one
low tre
pause x
high two
low one
pause x
high tre
low two
Pause Y
low tre


'x=400
'stage 29____________________________________________
high one
pause x
high two
low one
pause x
high zero
low two
pause x
low zero
sub=9
gosub sub9
high one
Pause Y
low one


'x=400
'stage 30____________________________________________
high two
pause x
high zero
low two
pause x
low zero
sub=9
gosub sub9
high one
pause x
high two
low one
Pause Y
low two




'stage 31____________________________________________
high zero
pause x
low zero
sub=9
gosub sub9


high one 'proper finish? one and two
pause x
low one
high two
pause x
low two
high zero
Pause Y
'low zero


goto koka


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


sub1: 'smaller sub
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 x
return


sub2: 'even smaller sub
pause x
high two
low one
pause x
high tre
low two
return