Shop OBEX P1 Docs P2 Docs Learn Events
Freq generation — Parallax Forums

Freq generation

stilgarstilgar Posts: 47
edited 2015-01-24 18:41 in Propeller 1
I need to generate 2 separate freq but they must be output on single pin and use only 1 cog. I need to generate a 123.50 Hz and a 82.41 Hz signal at the same time and mixed, to be output on P10.

I was looking at the OBEX " http://obex.parallax.com/object/244" file of Frequency Synthesis/PWM X8 but not sure if it can do what I need.

Thank you

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2015-01-24 12:46
    What do you mean exactly by "mixed?" Superposed sine waves, two square waves ORed together, or ... ? IOW, what do you want the resulting signal to look like?

    -Phil
  • stilgarstilgar Posts: 47
    edited 2015-01-24 12:54
    What do you mean exactly by "mixed?" Superposed sine waves, two square waves ORed together, or ... ? IOW, what do you want the resulting signal to look like?

    -Phil
    both freq need to be generated at the same time, and put on the one pin. The signal will be used as a base tone for a vocoder unit. this signal would replace the instrument input.
    Hope this helps, not really familiar with tone gen on the propeller, onlt digital signals.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2015-01-24 13:53
    So you want mixed sine waves then, correct?

    -Phil
  • stilgarstilgar Posts: 47
    edited 2015-01-24 14:08
    So you want mixed sine waves then, correct?

    -Phil
    yes, I think so

    Thank you
  • ChrisGaddChrisGadd Posts: 310
    edited 2015-01-24 15:58
    Here's a quick hatchet job on my DTMF object, hardcoded for 123.5 and 82.41Hz on pin 10:

    DTMF.jpg

    {{
      Generates DTMF tones by combining two values retrieved from the sine lookup table
      The row tone and column tone are each updated once every degree    
    
              1KΩ            
      I/O ─┳──────┳───────          
           0.1µF 0.01µf
                    
    
    }}
    CON               
      _clkmode = xtal1 + pll16x                                                    
      _xinfreq = 5_000_000                                                                                                                           
    
    PUB Demo
      cognew(@DTMF_start,0)
        
    DAT                     org
    DTMF_start
                            movi      ctra,#%0_00110_000                            ' Set duty mode
                            movs      ctra,#10                                      ' Output on pin 10
                            or        dira,DTMF_mask                               
                            mov       row_target,row_delay
                            add       row_target,cnt
                            mov       column_target,column_delay
                            add       column_target,cnt
    :check_row
                            mov       cnt,row_target                                ' Determine if one degree has elapsed
                            sub       cnt,cnt
                            cmps      cnt,#0                      wc
              if_nc         jmp       #:check_column                                
                            add       row_target,row_delay                          ' Increment time to next degree
                            mov       sine,row_angle                                ' Find value for this degree
                            call      #Get_sine
                            mov       t1,sine
                            shl       t1,#14                                        ' Shift into upper word, -2 to make room for other tone and zero-crossing
                            call      #Set_duty                                     ' Set amplitude for this degree
                            add       row_angle,sine_step                           ' Increment angle to next degree
    :check_column
                            mov       cnt,column_target                            
                            sub       cnt,cnt
                            cmps      cnt,#0                      wc
              if_nc         jmp       #:check_row
                            add       column_target,column_delay
                            mov       sine,column_angle
                            call      #Get_sine
                            mov       t2,sine
                            shl       t2,#14                                       
                            call      #Set_duty
                            add       column_angle,sine_step
                            jmp       #:check_row
    '----------------------------------------------------------------------------------------------------------------------      
    Get_sine
                            test      sine,sine_90                wc                'get quadrant 2|4 into c
                            test      sine,sine_180               wz                'get quadrant 3|4 into nz
                            negc      sine,sine                                     'if quadrant 2|4, negate offset
                            or        sine,sine_table                               'or in sin table address >> 1
                            shl       sine,#1                                       'shift left to get final word address
                            rdword    sine,sine                                     'read word sample from $E000 to $F000
                            negnz     sine,sine                                     'if quadrant 3|4, negate sample
    Get_sine_ret            ret                          
    '----------------------------------------------------------------------------------------------------------------------      
    Set_duty
                            mov       t3,t1                                         
                            add       t3,t2
                            add       t3,zero_crossing
                            mov       frqa,t3
    Set_duty_ret            ret
    '----------------------------------------------------------------------------------------------------------------------      
    sine_table              long      $E000 >> 1
    sine_90                 long      $800                        
    sine_180                long      $1000
    zero_crossing           long      $8000_0000              
    sine_step               long      32                                            ' 1 degree is 32 counts in the table
    row_delay               long      2530                                          ' clkfreq / 123.5 / 256 = 2530.36
    column_delay            long      3792                                          ' clkfreq / 82.41 / 256
    DTMF_mask               long      |< 10
    sine                    res       1
    row_angle               res       1
    row_target              res       1
    column_angle            res       1
    column_target           res       1
    t1                      res       1
    t2                      res       1
    t3                      res       1
    
                            fit
    
    552 x 122 - 49K
  • stilgarstilgar Posts: 47
    edited 2015-01-24 18:41
    ChrisGadd , thank you.

    Phil Pilgrim (PhiPi) , thank you.
Sign In or Register to comment.