Shop Learn
Using Objects (Synth.spin, SquareWave.spin — Parallax Forums

Using Objects (Synth.spin, SquareWave.spin

bbrienbbrien Posts: 431
edited 2022-01-06 00:10 in Propeller 1

I am trying to use the above objects to generate a 8 and 10 Hz signal on two counters of a single cog. My counters are declared in the con section of my program. the Pin numbers are declared separately. but I don't know where to put the needed frequency. I am including my Program.

Comments

  • PublisonPublison Posts: 12,255

    I think we need to move this to P1 thread to get a better response. I can do that if you wish.

  • If you think it will help.

  • JonnyMacJonnyMac Posts: 7,912
    edited 2022-01-06 18:43

    I am trying to use the above objects to generate a 8 and 10 Hz signal on two counters of a single cog.

    No objects required -- just some simple PASM running in its own cog.

    con
    
      P10HZ    =  1  { O }
      P08HZ    =  0  { O }
    
    
    dat { 8Hz / 10Hz synth }
    
                    org       0
    
    synth810        andn      outa, mask8                           '  8Hz output low
                    or        dira, mask8
    
                    andn      outa, mask10                          ' 10Hz output low
                    or        dira, mask10
    
                    mov       timer, tix                            ' start timer
                    add       timer, cnt
    
    :loop           waitcnt   timer, tix                            ' hold
    
                    add       ctr8, #1                              ' bump count           
                    cmpsub    ctr8, #5                      wz      ' at 1/2 cycle?
        if_z        xor       outa, mask8                           ' yes, toggle pin
    
                    add       ctr10, #1
                    cmpsub    ctr10, #4                     wz
        if_z        xor       outa, mask10   
    
                    jmp       #:loop
    
    ' ---------------------------------------------------------------------------------------
    
    mask8           long      1 << P08HZ
    mask10          long      1 << P10HZ
    tix             long      (CLK_FREQ / 10) / 8 - 28              ' 1/8 period @ 10Hz
    
    ctr8            long      0
    ctr10           long      0
    
    timer           res       1
    
                    fit       496
    
    1920 x 1040 - 57K
  • The waveforms are just like the ones I generated in Experiment1a. I would like to incorporate into the DH15 program . I will remove all of the stepper method since I can't get to work. ( it's in first post of this thread)

  • Tracy AllenTracy Allen Posts: 6,593
    edited 2022-01-07 22:04

    You say you want to use the two cog counters to generate frequencies of 8 Hz and 10 Hz, and that the counters are already defined in the CON section. Here is what I see in the CON section and I'm confused about all the numbers there, 50Hz, a couple of 8_0 and a 7.5% and a 9.5 Hz.

      PWM_FREQ  = 50                ' 50hz frequency : 50% dutycycle
      DEC_RATE  = 8_0               ' DEC base rate = 7.5% - Adjust as needed for desired slew rate
      DEC_AUTO  = DEC_RATE          ' DEC autoguider correction rate - currently set to base rate
    
      RA_RATE   = 8_0               ' RA base rate = 9.5 Hz - Adjust as needed to counteract Earth's rotation
      RA_AUTO   = RA_RATE           ' RA autoguider correction rate - currently set to base rate
    
    

    In any case, to set up a cog counters for 8 Hz and 10 Hz, you need

    ctra := %00100 << 26 + pinNumberA.   
    frqa := 430.   ' to produce 8 Hz (closer to 8.01 Hz)
    ctrb := %00100 << 26 + pinNumberB.   
    frqa := 537.   ' 10 Hz
    dira[pinNumberA] := 1
    dira[pinNumberB] := 1
    
    
  • Tracy , a lot of information is being disposed of in that program, a new partial program has been completed but untested, and incomplete. maybe you can take a look and help.

  • JonnyMacJonnyMac Posts: 7,912
    edited 2022-01-07 16:41

    Thanks for the reminder, @"Tracy Allen" -- I was tired when I posted last night, and trying to pay a little attention to "The Book of Boba Fett" as a member of the Parallax community works on the show (I occasionally provide bits of P1 code for him). I completely forgot about NCO mode, for which I have a method in my jm_io.spin object.

    Edit: Fixed freq_out() method to eliminate loss of bit0

    pub freq_out(ctrx, px, fx)
    
    '' Sets ctrx to frequency fx on pin px (NCO/SE mode)
    '' -- fx in 0.1Hz units (100_0 = 100Hz)
    '' -- use fx of 0 to stop counter that is running
    
      if (fx > 0)
        fx := ($4000_0000 / ((clkfreq >> 2) / fx))                  ' convert freq for NCO mode (modified)
        fx := (fx + 5) / 10                                         ' round up if needed (added)
    
        case ctrx
          0, "a", "A":
            ctra := (%00100 << 26) | px                             ' configure ctra for NCO on pin
            frqa := fx                                              ' set frequency
            dira[px] := 1                                           ' make pin an output
    
          1, "b", "B":
            ctrb := (%00100 << 26) | px
            frqb := fx
            dira[px] := 1
    
      else
        case ctrx
          0, "a", "A":
            ctra := 0                                               ' disable counter
            outa[px] := 0                                           ' clear pin/driver
            dira[px] := 0
    
          1, "b", "B":
            ctrb := 0
            outa[px] := 0
            dira[px] := 0
    

    Tested with:

      io.freq_out("A", P08HZ,  8_0)
      io.freq_out("B", P10HZ, 10_0)  
    

    Output attached.

    1920 x 1040 - 57K
  • JonnyMacJonnyMac Posts: 7,912
    edited 2022-01-07 16:36

    The next morning -- after a cup of coffee -- I coded manually:

      ctra := (%00100 << 26) | P08HZ                                ' nco mode
      frqa := 429                                                   ' 8Hz = 2^32 / (clkfreq / 8)
      dira[P08HZ] := 1                                              ' enable output
    
      ctrb := (%00100 << 26) | P10HZ
      frqb := 537                                                   ' 10Hz = 2^32 / (clkfreq / 10)   
      dira[P10HZ] := 1 
    

    The output is just a smidge more accurate than my original freq_out() method which always dropped bit0 of the frqx setting (fixed now).

    1283 x 358 - 20K
  • concerning post #7
    I tried to correct an error by adding a pair of phrases to the CON section and got another error ( see Attached File), What does it mean and how to fix.****

    1280 x 720 - 150K
  • JonnyMacJonnyMac Posts: 7,912

    Jumpin' Jiminy on a cracker... you can't make method calls from a CON block (only PUB and PRI blocks).

  • bbrienbbrien Posts: 431
    edited 2022-01-08 23:06

    so those phrases have to be used with objects, guess i'll have to use the SquareWave objects. Next error,What is and why do I get da "expected a sub routine name" error ?

  • The difference between this and my dh14 code is little and it works but the dh15 code doesn't. 15 is on first post and here is 14.

  • Another question; is this program a spin or a propC.

Sign In or Register to comment.