Triangle wave???
Moderator: frank
Triangle wave???
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.
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
For triangle wave see this thread http://www.spinsemi.com/forum/viewtopic ... t=triangle
Frank Thomson
Experimental Noize
Experimental Noize
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.
Frank Thomson
Experimental Noize
Experimental Noize
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.
Frank Thomson
Experimental Noize
Experimental Noize
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
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
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.
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.
Frank Thomson
Experimental Noize
Experimental Noize