How to generate a square wave
inaki
Posts: 262
I need to generate·a square wave with 3·cycles of 854 us each. Then pause for a second and repeat.
Each cycle has payload of 50%, so each part of·a cycle takes 427 us.
I am using a BS2 to generate the train of 3 cycles on PIN 7 with the code shown bellow so I divide the time by 2 us.
The resulting signal has nothing to do which what I intended. Obviously the BS takes too much time to process the code and the wave is distorted.
Is there any better way to achieve this goal? Is it possible to achieve this in a BS at all ?
T CON 213 'About 427/2
Main:
· LOW 7
· PULSOUT 7,T
· HIGH 7
· PULSOUT 7,T
· LOW 7
· PULSOUT 7,T
··HIGH 7
· PULSOUT 7,T
· LOW 7
· PULSOUT 7,T
· HIGH 7
· PULSOUT 7,T
· PAUSE 1000
· GOTO Main
· END
·
Each cycle has payload of 50%, so each part of·a cycle takes 427 us.
I am using a BS2 to generate the train of 3 cycles on PIN 7 with the code shown bellow so I divide the time by 2 us.
The resulting signal has nothing to do which what I intended. Obviously the BS takes too much time to process the code and the wave is distorted.
Is there any better way to achieve this goal? Is it possible to achieve this in a BS at all ?
T CON 213 'About 427/2
Main:
· LOW 7
· PULSOUT 7,T
· HIGH 7
· PULSOUT 7,T
· LOW 7
· PULSOUT 7,T
··HIGH 7
· PULSOUT 7,T
· LOW 7
· PULSOUT 7,T
· HIGH 7
· PULSOUT 7,T
· PAUSE 1000
· GOTO Main
· END
·
Comments
Pulses········· PIN···· 7
Spare·········· PIN···· 15
HalfCyc········ CON···· 28
Main:
· HIGH·Pulses
· PULSOUT Spare, HalfCyc
· LOW Pulses
· PULSOUT Spare, HalfCyc
· HIGH Pulses
· PULSOUT Spare, HalfCyc
· LOW Pulses
· PULSOUT Spare, HalfCyc
· HIGH Pulses
· PULSOUT Spare, HalfCyc
· LOW Pulses
· PULSOUT Spare, HalfCyc
· PAUSE 1000
· GOTO Main
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax