Creating a Square wav
I am kinda stuck on this one. I know it's simple, but I just can't get my head around it.
We have our stamp connected directly to a R2R network with no chip.. We managed to generate a sine wave with this code, but we can't figure out howto get a Square wave or a Saw Tooth wave.
Any ideas would be greatly appreciated.
·
We have our stamp connected directly to a R2R network with no chip.. We managed to generate a sine wave with this code, but we can't figure out howto get a Square wave or a Saw Tooth wave.
Any ideas would be greatly appreciated.
' {$STAMP BS2}
' {$PBASIC 2.5}
DIRS = %0000111100000000
Degr VAR Word ' Define variables.
Sine VAR Word
'%%%%%%%%%%%%%%%%% Begin Sine Wave %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FOR Degr = 0 TO 359 ' Use degrees.
Sine = SIN (Degr * 128 / 180) ' Convert to brads, do SIN.
sine = sine + 127
sine = sine / 17
OUTC = sine
DEBUG "Sine: ", BIN sine,CR
PAUSE 15
DEBUG "Angle: ", DEC Degr, TAB, "Sine: ", SDEC Sine, CR ' Display.
NEXT
'%%%%%%%%%%%%%%%% End Sine Wave %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'%%%%%%%%%%%%%%%% Begin Square Wave %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
·

Comments
Make_Sqare:
· OUTC = %0000
· DO
··· PAUSE halfCycle
··· OUTC = ~OUTC···
· LOOP WHILE (MakeWave = 1)
· RETURN
Make_Saw:
· OUTC = %0000
· DO
··· PAUSE delayTime
··· OUTC = OUTC + 1
· LOOP WHILE (MakeWave = 1)
· RETURN
The subroutines above have a test input that allows you to jump out of the routine when you're ready to quit.·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas Office
Make_Saw2:
· OUTC = %1111
· DO
··· PAUSE delayTime
··· OUTC = OUTC·+ 15 // 16
· LOOP WHILE (MakeWave = 1)
· RETURN
Make_Tri:
· OUTC = %0000
· change = 1
· DO
··· PAUSE delayTime
··· OUTC = OUTC·+ change // 16
··· IF (OUTC = %1111) THEN change = 15··· ' ramp down
··· IF (OUTC = %0000) THEN change = 1···· ' ramp up
· LOOP WHILE (MakeWave = 1)
· RETURN
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas Office