Page 1 of 1
Triangle wave???
Posted: Fri Jun 11, 2010 8:17 am
by sad1024
Is there anyway to generate a triangle wave, based on the analog model of a comparator followed by an integrator? You could also get a square wave if you sampled the comparator rather than the integrator.
Posted: Fri Jun 11, 2010 9:51 am
by frank
Why try to model the analog method in a digital chip?
For triangle wave see this thread
http://www.spinsemi.com/forum/viewtopic ... t=triangle
Posted: Fri Jun 11, 2010 11:19 am
by sad1024
Not as an lfo. As a large range function generator.
Posted: Sun Jun 13, 2010 4:37 pm
by sad1024
equ x reg0
sof 0,0
rdax x, 1
skp gez, 1
sof 0, -1
skp neg, 1
sof 0, 0.999
sof 1, 0
mulx pot0
rdax x,1
wrax x,1
wrax dacl,0
Why doesn't this work?
Posted: Sun Jun 13, 2010 5:03 pm
by frank
Please comment code, makes it much easier to understand your intent at each step and we don't have to try to reverse engineer your thoughts.
Posted: Mon Jun 14, 2010 4:33 am
by sad1024
equ x reg0 ;setup registry
sof 0,0 ;clear acc
rdax x, 1 ;read x
skp gez, 1 ;if negative let acc =-1
sof 0, -1
skp neg, 1 ;if positive let acc =0.999
sof 0, 0.999
mulx pot0 ;attenuate acc
rdax x,1 ;integrate acc
wrax x,1 ;write x
wrax dacl,0 ;write to output
Posted: Mon Jun 14, 2010 11:32 am
by frank
What are you trying to do here? You don't read any inputs nor initialize the "x" register so if it is a negative value it stays negative and if it is positive it stays positive. There is no input to integrate.
Posted: Mon Jun 14, 2010 2:34 pm
by sad1024
Sorry, my error. This oscillates but is unstable.
equ x reg0
equ y reg1
equ z reg2 ;setup registry
sof 0,0 ;clear acc
skp run,2
sof 0,-0.5 ; initialize oscillator
wrax x, 0
rdax z, -1 ; feedback from second integrator
mulx pot0 ; attenuate acc
rdax x,1 ; integrate
wrax x,1
wrax dacl,1 ; write to output
mulx pot0 ; attenuate
rdax y,1 ; integrate
wrax y,1
skp neg,2 ; turn into square wave
sof 0, 0.5
wrax z,0
skp gez,2
sof 0,-0.5
wrax z,0 ; write square wave feedback
Posted: Mon Jun 14, 2010 4:33 pm
by frank
Only had time to look at it quickly but you probably want to also attenuate the integrator feedback values (i.e. rdax x,0.9).
If this is to do a triangle wave I would just use a counter, count up to a fixed value then count down to 0 then back up to a fixed value, etc.