Spin Semiconductor Forum Index Spin Semiconductor
Support forum
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

COUNTER

 
Post new topic   Reply to topic    Spin Semiconductor Forum Index -> Algorithm development
View previous topic :: View next topic  
Author Message
Mcfly



Joined: 08 Mar 2013
Posts: 45
Location: Argentina

PostPosted: Sat Aug 29, 2015 6:25 am    Post subject: COUNTER Reply with quote

Hi! i would like to know how to make a counter that finish counting at 1, and takes X seconds to get there.

Thanks!
Back to top
View user's profile Send private message Send e-mail
frank



Joined: 19 Oct 2005
Posts: 958

PostPosted: Sun Aug 30, 2015 8:26 am    Post subject: Reply with quote

Just increment a register every time through the code and when it hits the value you want do what you need. Since it will increment every sample period the time it takes will be (1/samplerate)* count seconds.
_________________
Frank Thomson
Experimental Noize
Back to top
View user's profile Send private message Visit poster's website
Mcfly



Joined: 08 Mar 2013
Posts: 45
Location: Argentina

PostPosted: Sat Sep 05, 2015 6:33 am    Post subject: Reply with quote

frank wrote:
Just increment a register every time through the code and when it hits the value you want do what you need. Since it will increment every sample period the time it takes will be (1/samplerate)* count seconds.


Frank, this is my code for turning a led to its full bright in 10 seconds. Dacl it is attached to a led:

equ counter reg1

rdax counter,1
sof 1,1/327680
wrax counter,1
wrax dacl,0

The problem is that led is always off.
Back to top
View user's profile Send private message Send e-mail
frank



Joined: 19 Oct 2005
Posts: 958

PostPosted: Sat Sep 05, 2015 12:06 pm    Post subject: Reply with quote

sof only accepts a S.10 bit value for the adder so 1/327680 is getting rounded to 0. You will want to clear the acc then OR the value into it since you will need 19 magnitude bits to represent 1/327680 then add the current count value.
_________________
Frank Thomson
Experimental Noize
Back to top
View user's profile Send private message Visit poster's website
Mcfly



Joined: 08 Mar 2013
Posts: 45
Location: Argentina

PostPosted: Tue Sep 08, 2015 9:48 pm    Post subject: Reply with quote

frank wrote:
sof only accepts a S.10 bit value for the adder so 1/327680 is getting rounded to 0. You will want to clear the acc then OR the value into it since you will need 19 magnitude bits to represent 1/327680 then add the current count value.


Frank, i tried your suggestion but Asm says: <0000>[ Pass 2] [ 1005] Line: 15 "sof 1,count " - ERROR:Coefficient out of range - 34.000000

equ counter reg1
equ count reg2
equ increment 1/327680

skp run,endclr

clr
rdax increment,1 ;read the increment
or %00000000000001111111111 ;mask 10 bits
wrax count,0

endclr:

rdax counter,1
sof 1,count
wrax counter,1
wrax dacl,0
Back to top
View user's profile Send private message Send e-mail
frank



Joined: 19 Oct 2005
Posts: 958

PostPosted: Wed Sep 09, 2015 10:33 am    Post subject: Reply with quote

The sof will not work in this case, also you cannot pass sof the address of a register. Try an RDAX.
_________________
Frank Thomson
Experimental Noize
Back to top
View user's profile Send private message Visit poster's website
Mcfly



Joined: 08 Mar 2013
Posts: 45
Location: Argentina

PostPosted: Wed Sep 09, 2015 6:38 pm    Post subject: Reply with quote

frank wrote:
The sof will not work in this case, also you cannot pass sof the address of a register. Try an RDAX.


Ok so i tried this, but led is always off. I assume that mi increment is rounded to zero again:

equ counter reg1
equ increment 0.00001 ;this coefficient turns the led on in 2 secs.)

rdax counter,1
rdax increment,1
wrax counter,1
wrax dacl,0
Back to top
View user's profile Send private message Send e-mail
frank



Joined: 19 Oct 2005
Posts: 958

PostPosted: Thu Sep 10, 2015 8:57 am    Post subject: Reply with quote

"rdax increment,1" requires a register as an argument, not a static value. Read the SpinAsm docs for what each instruction accepts as a parameter.

Do what I said in the past:
clear the accumulator
OR in the value to increment with
Add the counter register

This is as simple as:
sof 0,0
or 0x00000f ;what ever number
rdax counter, 1

acc now has the incremented value
_________________
Frank Thomson
Experimental Noize
Back to top
View user's profile Send private message Visit poster's website
Digital Larry



Joined: 12 Nov 2012
Posts: 266

PostPosted: Tue Jun 07, 2016 6:30 am    Post subject: Reply with quote

Hi Frank,

I think I get what is going on with your suggestion. (I am trying to develop something like an envelope generator).

e.g.

equ counter1 reg0
equ max1 0x0ff ; reset limit for counter 1

clr
or 0x01
rdax counter1, 1.0
wrax counter1, 1.0
xor max ; this will be all zeroes if counter1 == max
skp zro, reset
ldax counter1
skp run, output
reset:
wrax counter1, 0 ; acc was zero when we jumped here, so counter1=0
output:
wrax dacl, 0

1 registers, 10 instructions

I didn't actually try running this but I think it would make a very low amplitude ramp-up sawtooth waveform.

I could do this slightly differently by allowing myself to use SOFs. The question then is, what is my resolution? And the next question is, how certain am I that I can hit zero exactly (so I can use skp zro) by decrementing by 1/count?

Actually, since I can't start at +1.0 using SOF, I could start at -1.0 and increment upwards.

So, for example:

equ counter1 reg0
equ increment 1/256

skp run, end_init
sof 0.0, -1.0
wrax counter1, 0
end_init:

rdax counter1, 1.0
sof 1.0, increment ; add the increment to count upwards towards zero
wrax counter1, 1.0
skp zro, reset ; or, skp gez, if I'm not sure I can hit zero exactly
skp run, output
reset:
sof 0,-1.0
wrax counter1, 1.0
output:
wrax dacl, 0

1 register, 11 instructions

Conceptually the first approach uses 1 fewer instructions and is a bit easier to grasp, as integers are thought of as integers, rather than fractions. Under some circumstances one might wish to use that -1.0 to 0 ramp in some way other than just for counting.

I just wrote the counter to the DACL as an example, and I understand the amplitude of the second case will be much higher than the first. In fact I'm not planning to use the counter this way - only for counting time during which other things will happen when the timers expire.

Thanks for any perspective.

DL


Last edited by Digital Larry on Tue Jun 07, 2016 1:54 pm; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
frank



Joined: 19 Oct 2005
Posts: 958

PostPosted: Tue Jun 07, 2016 1:35 pm    Post subject: Reply with quote

Personally I like to load a negative count and count to zero so I can use a GEZ in a skip and it doesn't matter if I hit zero exactly or not since the skip will happen on any positive value. As far as resolution the max would be 1/8388608 assuming you load a 0x800000 into a reg (max negative number) and add 0x000001 each period and the terminal count is 0. At a sample rate of 32768 that is 256 seconds to time out, over 4 minutes.

Could be longer if you use a positive value as the terminal count but that gets messy with more instructions.
_________________
Frank Thomson
Experimental Noize
Back to top
View user's profile Send private message Visit poster's website
Digital Larry



Joined: 12 Nov 2012
Posts: 266

PostPosted: Sat Jun 18, 2016 3:54 pm    Post subject: Reply with quote

I've found that using decimal representation for counters and increments is a little easier to debug as I can hang my scope on the FV-1 output pin (to avoid AC coupling effects) and observe the counter as it ramps from -1.0 to 0.0. I was trying to do the same simply incrementing a 24-bit value by 1 (lowest bit) and it's not possible to view the waveform as the amplitude is way down for typical counts (I'm trying to make pulses in the 100 to 500 msec range).
Back to top
View user's profile Send private message Visit poster's website
MacroMachines



Joined: 12 Dec 2014
Posts: 70
Location: Detroit,MI

PostPosted: Sat Jun 18, 2016 5:20 pm    Post subject: Reply with quote

Digital Larry wrote:
I've found that using decimal representation for counters and increments is a little easier to debug as I can hang my scope on the FV-1 output pin (to avoid AC coupling effects) and observe the counter as it ramps from -1.0 to 0.0. I was trying to do the same simply incrementing a 24-bit value by 1 (lowest bit) and it's not possible to view the waveform as the amplitude is way down for typical counts (I'm trying to make pulses in the 100 to 500 msec range).


I was trying to scope a direct pot output the other day to see if my ADC for POT0 was working and it seems like there is a DC filter on the outs, is this AC coupled or can it output DC?
_________________
http://MacroMachines.net
Digital Control for your Analog Soul.
Back to top
View user's profile Send private message Visit poster's website AIM Address
Digital Larry



Joined: 12 Nov 2012
Posts: 266

PostPosted: Sat Jun 18, 2016 7:42 pm    Post subject: Reply with quote

The FV-1 dev board definitely AC couples the outputs. I soldered a clipped off resistor lead to one of the coupling caps connected to the FV-1 right channel out so I could attach a scope lead.
Back to top
View user's profile Send private message Visit poster's website
MacroMachines



Joined: 12 Dec 2014
Posts: 70
Location: Detroit,MI

PostPosted: Mon Jul 11, 2016 6:05 am    Post subject: Reply with quote

Cool, I ended up soldering a lead to the dacl pin directly. I am suprised at how much slew is on the pots. Also this thread is very useful stuff, it may be helpful to some of my programs.
_________________
http://MacroMachines.net
Digital Control for your Analog Soul.
Back to top
View user's profile Send private message Visit poster's website AIM Address
Display posts from previous:   
Post new topic   Reply to topic    Spin Semiconductor Forum Index -> Algorithm development All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group