Shop OBEX P1 Docs P2 Docs Learn Events
Squarewave creation — Parallax Forums

Squarewave creation

CenlasoftCenlasoft Posts: 265
edited 2011-09-06 17:14 in Propeller 1
Hello,
I know how to produce squarewaves with the counters, but I need to produce two squarewaves that are out of phase. I have looked through the OBEX, manuals, and the counter note (AN001). I cannot seem to figure out how to create two squarewaves that are out of phase without some hardware.
Any help would be great.
Thank you,
Curtis

Comments

  • kuronekokuroneko Posts: 3,623
    edited 2011-09-05 17:20
    Cenlasoft wrote: »
    I know how to produce squarewaves with the counters, but I need to produce two squarewaves that are out of phase. I have looked through the OBEX, manuals, and the counter note (AN001). I cannot seem to figure out how to create two squarewaves that are out of phase without some hardware.
    The basic idea is to use two counters, one of which has a phase offset (preset) applied to its phsx register.
    PUB null
    
      dira[16..17]~~
      ctra := constant(%0_00100_000 << 23 | 16)          ' NCO
      ctrb := constant(%0_00100_000 << 23 | 17)          ' NCO
    
      phsb := $4000_0000                                 ' 25% shift
      frqa := frqb := NEGX/-clkfreq*2                    ' 1Hz
    
      waitpne(0, 0, 0)                                   ' keep cog alive
    
  • Mark_TMark_T Posts: 1,981
    edited 2011-09-06 01:58
    Isn't there a counter mode that generates a square wave and its inverted form on the two pins? Or by out of phase do you mean a particular phase difference?
  • CenlasoftCenlasoft Posts: 265
    edited 2011-09-06 06:04
    Mark_T,
    I acually want a specific phase shift.
    Thanks,
    Curtis
  • Tracy AllenTracy Allen Posts: 6,667
    edited 2011-09-06 08:36
    Curtis, if Kuroneko's reply did not answer your question, please be more specific. Is it to be one particular shift set forever, or are you going to need to tune it or modulate it in some way at run time?
  • CenlasoftCenlasoft Posts: 265
    edited 2011-09-06 09:06
    Hi,
    Thanks everyone, kuroneko reply looks like it might work. I am still trying to understand the spin code. There are a few methods in that code I have never used yet. I will experiment with it today. @Tracy, This is part of my ultrasound project. I am needing this to experimentally test my phase shift measurement circuit using two flip-flops and an XOR IC. That is why I need two 50% duty squarewaves with one having a phase shift. I want to test my circuit at different frequencies and phase shifts and compare data from the prop and the scope in order to prove my concept. If this works than I will need to take the echo from the ultrasonic transducer (sinewave) and convert it to a squarewave of 50% duty and measure its phase shift from the reference squarewave from the transmitter.
    Thanks,
    Curtis
  • CenlasoftCenlasoft Posts: 265
    edited 2011-09-06 13:31
    Hello,
    I tried the code that kuroneko posted and for for counter A it gives me a nice square wave, but for counter B it gives me a square wave that is stepped. Looks like two squarewaves superimposed. I tested these on separate scope channels.
    Thanks,
    Curtis
  • kuronekokuroneko Posts: 3,623
    edited 2011-09-06 16:36
    Cenlasoft wrote: »
    ... but for counter B it gives me a square wave that is stepped. Looks like two squarewaves superimposed.
    Both pins use the same (NCO) counter setup. Only difference is the phase offset. What do you have connected to those pins? What happens if you don't enable counter A?
  • CenlasoftCenlasoft Posts: 265
    edited 2011-09-06 17:14
    kuroneko,
    I tried your code on a Parallax QuickStart Board and then when I went home, I tried the same code on a GadgetGangster Prop Board and the Prop Professional Board and it worked on both. The scope showed a phase shift (24 us difference between two waves with the period 100 us). I used (frqa := frqb := 536871 ) for 10 khz before at work and after at home. I think it was the QuickStart Board.
    I'll use this and let everyone know.
    Thanks,
    Curtis
Sign In or Register to comment.