Shop OBEX P1 Docs P2 Docs Learn Events
A Change to Frequency Synthesizer Demo Ver 1.1 — Parallax Forums

A Change to Frequency Synthesizer Demo Ver 1.1

W8VKW8VK Posts: 30
edited 2011-03-10 15:31 in Propeller 1
Hello All!
I guess I'm not any good at changing spin code in programs at all, as i can't see a method to make a change to the FrequencySynth.spin code that would allow the orginal Con of frequency and Pin to load, and continously repeat the frequency, but give an option in a subroutine to be asked for a new Input for frequency that would run in the repeated loop but again ask for a new change in frequency!
Does this also require a change to the Synth.spin to incorporate such a reoccurring input?
Thanks for reading my post!

Rich W8VK
«1

Comments

  • kuronekokuroneko Posts: 3,623
    edited 2011-02-12 00:46
    Not sure yet what exactly you're after but the Synth object only (re)programs the counter(s) of the calling cog. Once the method returns it doesn't need hand-holding. So feel free to call it with different parameters later.

    For example you could run a loop which reads a frequency value from a serial object. Once you press Enter this frequency value is passed to the Synth object and then the loop waits for new input.
  • W8VKW8VK Posts: 30
    edited 2011-02-12 01:15
    Yes! What you described is exactly what I'm trying to accomplish!

    But I'm not versed enough in spin programming to add this component! I've dealt with basic and going to subroutines, but i'm lost here! Thanks for your reply!

    Rich W8VK
  • kuronekokuroneko Posts: 3,623
    edited 2011-02-12 01:57
    Something like this should get you started:
    CON
      _clkmode = XTAL1|PLL16X
      _xinfreq = 5_000_000
    
    CON
      pin = 16
    
    OBJ
      serial: "Parallax Serial Terminal"
      source: "Synth"
      
    PUB null : frequency
    
      serial.start(115200)                                  ' use default serial pins (31/30)
      waitcnt(clkfreq*2 + cnt)
    
      repeat
        [COLOR="blue"]serial.Str(string("frequency: "))[/COLOR]                   ' user prompt
        [COLOR="red"]frequency := serial.DecIn[/COLOR]                           ' read decimal value
        [COLOR="blue"]serial.Dec(frequency)[/COLOR]                               ' |
        [COLOR="blue"]serial.Char(serial#NL)[/COLOR]                              ' local echo
        [COLOR="orange"]source.Synth("A", pin, frequency)[/COLOR]                   ' set counter (only uses A)
    
    Blue indicates user prompts/info, red reads user input from the serial terminal and orange (re)programs counter A. Current setting is for an LED on pin 16 (demoboard).
  • W8VKW8VK Posts: 30
    edited 2011-02-12 07:19
    Kuroneko!
    Thank you very much for this idea and I will "play with coding" and see how far i get on this and then share it here with you!
    Rich W8VK
  • rogersydrogersyd Posts: 223
    edited 2011-02-12 12:17
    Hi Rich, here is my take on this if it helps.

    synth_prompt.zip

    -rogersyd
  • W8VKW8VK Posts: 30
    edited 2011-02-12 14:34
    Kuroneko!
    That worked out very well! I attached 2 files! One is for my comm port Prop, and I guess you have the USB version! I will now play
    with a Visual Basic Express 2010 Version to take the place of the Serial Port Program! Many thanks for the help and i'm sure others
    will want to play too!

    Rich W8VK
  • W8VKW8VK Posts: 30
    edited 2011-02-12 14:38
    Rogersyd!
    Thanks for replying and i'll check it out and get back with a post to you!
    Rich W8VK
  • kuronekokuroneko Posts: 3,623
    edited 2011-02-12 15:20
    @W8VK: please check your PMs.
  • W8VKW8VK Posts: 30
    edited 2011-02-13 05:00
    Kuroneko and Viewers!
    The attached (2) spin files are corrections to authoring of this project! Thanks!

    Rich W8VK
  • W8VKW8VK Posts: 30
    edited 2011-02-13 05:07
    Hello Rogersyd and Viewers!
    I'm getting back with you Rogersyd to let you know I was able to run your program fine!
    I set the speed faster for me and perfer the other program because of less return info to the
    Serial terminal and amount of response time!
    Great job in codeing and appreciate the excellent help and your codeing method provided!
    Well done and Thanks!

    Rich W8VK
  • rogersydrogersyd Posts: 223
    edited 2011-02-13 06:38
    Hi Rich,
    It was fun writing it. I learned a bit about the synth object in the process. While looking in to this I found very well written tutorial and example code recently posted by Nick over at Gadget Gangster:
    http://forums.parallax.com/showthread.php?129413-New-Tutorial-Make-a-Propeller-Synthesizer

    His code use SIDSynth instead, and adds TV output and keyboard input (the approach i prefer over PC/Terminal). For my purposes I will modify the interface a bit to replace the piano key interface with a more flexible direct frequency input mechanism of some sort. I have always been fascinated with brain wave synchronization technologies like those developed by Robert Monroe and hope to build a device that essentially amounts to a portable synth tailed to generating those types of tones.

    Good luck on your project!
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2011-02-13 08:55
    Since your requesting to change an original program labelled with a 'demo' status, and not the core object itself, you should really change the name of your program to something that better suits your application and not rev the demo program.
  • W8VKW8VK Posts: 30
    edited 2011-02-13 10:54
    Thanks Beau!
    I will do that soon and have another 2 versions with 2 synthesizers running at the same time!
    I didn't really know how to approach the Modifications! Will Update soon!

    Rich W8VK
  • W8VKW8VK Posts: 30
    edited 2011-02-20 10:55
    Hi Kuroneko!
    I have made the following changes to this program in the attached files! I am wanting to create a menu system that will let me make several types of frequency entries and keep them going and have the choice to move to the menu to do other things!
    Also i think i'd like to have some kind of Pub Ini setup to set all the Frequencies to a particular start point! Please review the changes and let me know what you think so far!
    Any and all ideas, suggestions, and examples of menus are very much welcome! Thank you all for your help and intrust in this project!

    Attached are the Comm Port and USB (new) Programs!

    Rich_W8VK
  • kuronekokuroneko Posts: 3,623
    edited 2011-02-20 16:12
    If you want me to review the code then please provide something I can actually compile.
  • W8VKW8VK Posts: 30
    edited 2011-02-23 12:57
    Hello All!
    I have included 4 Files on the FrequencySynth.spin that has been modified in D to enter two frequencies continously!
    Part C has a change to enter frequency1 and frequency2 together, or individually and the method to do that is Questionable as to being even possible! Only Frequency1 will run in this.
    Part A is frequency1 code that works by itself ok! Part B is Frequency2 code that works by itself! Part A and Part B are made into Part C to see if a method is possible to devolope to selsect input to both frequency 1 and frequency 2, or just frequency 1 by itself, or frequency 2 by itself?
    Does anybody think this is possible to do? Can anybody suggest working exampls of spin files, or references that might be a key to a working method to make Part C a workable program? Thanks for reading this post!

    Rich W8VK
  • kuronekokuroneko Posts: 3,623
    edited 2011-02-23 17:38
    Try this. The main loop prompts for VFO selection and then updates the relevant channel. Note that the DecIn method ignores backspace, i.e. entering 2<BS>100 will still result in 2100.
    CON
      _CLKMODE = XTAL1 + PLL16X
      _XINFREQ = 5_000_000
    
    CON
      PinA = 16                                             'RX VFO A
      PinB = 17                                             'RX VFO B
      
    OBJ
       serial: "Parallax Serial Terminal"
       source: "Synth"
    
    PUB main | c
    
      serial.start(57600)                                   'use default pins  (31/30)       
      waitcnt(clkfreq*2 + cnt)
      serial.Char(serial#CS)
    
      repeat
        serial.RxFlush
        serial.Str(string("Select VFO (a/b): "))
        repeat until (c := serial.CharIn & !$20) == "A" or c == "B"
        VFO(c)
        
    PRI VFO(chn) | frequency, pin
    
      serial.Str(string("RX VFO "))                         '
      serial.Char(chn)                                      '
      serial.Str(string(": "))                              'user prompt
      
      frequency := serial.DecIn                             'read decimal value
      serial.Dec(frequency)                                 '
      serial.Char(serial#NL)                                'local echo
    
      pin := lookupz(chn - "A": PinA, PinB)                 'select pin
      source.synth(chn, pin, frequency)                     'set counter
    
    
  • W8VKW8VK Posts: 30
    edited 2011-03-01 20:59
    kuroneko,
    I did get this to work ok! But I have an earlier version that does the same boring thing basically! I think i'm seeing the limitations in spin language as compaired to what i made as an actual menu with subroutines with the Basic Stamp 2. I believe at this point it's probably time for me to investigate the PBasic for the Propeller as it can do subroutines where this language is so difficult to write in and i haven't seen anything for the propeller like this. I have written in the orginal Basic 3.22 and the Stamp Basic along with Visual Basic and Visual Studio which are easy to me. Spin language either isn't developed far enough yet or isn't based that way. Thanks for the effort!
    I wanted to be able to select only one at a time and then be able to change that choice to another choice with both still running. I believe that takes a Menu system with subroutines. I don't know much about PBasic yet but it's propably much like the BS2 Basic which i have written menu programs with subroutines in the BS2. But i don't see subroutines and actual menu stuff in spin language.
    The two things i saw accomplished here in spin language were entry into A and B rotating continously for frequency updates, or just entries into A continously updating A.. But i need to be able to do much more for a good design for a frequency synthesizer. And i think other people want to play but its too limited at this time. Who knows, maybe i'll have to deal with a different microprocessor. But i think that programming really looked difficult in a different processors too. Thats why hobbiest arent playing with those processors. You about need a 4 year computer sience degree to play with them. Thanks again!

    Rich W8VK
  • kuronekokuroneko Posts: 3,623
    edited 2011-03-01 21:11
    W8VK wrote: »
    I wanted to be able to select only one at a time and then be able to change that choice to another choice with both still running.
    It does exactly that. You pick A or B then set their respective frequency. The counter(s) then keep(s) running until you override its setting with a new frequency. Also, B isn't affected while you change A and vice versa. How is that not what you expressed above? Just curious ...

    If the main loop is supposed to handle other input then this has to be added. ATM it only deals with setting channels A and/or B.
  • W8VKW8VK Posts: 30
    edited 2011-03-02 15:46
    kuroneko!
    Thanks for replying! maybe i don't have the program constructed correctly from the code you posted in #18 posting. I tried doing the code in two programs which i don't think they are operating for me the way you intended! I will try to attach 2 ways i wrote this up and tried running them. Please explain total operation of program and if the codeing is correct! Appreciate you hanging arround and applying your expertise! Thanks!

    Rich W8VK
  • kuronekokuroneko Posts: 3,623
    edited 2011-03-02 17:24
    Can you confirm: both programs effectively do the same thing, one of them has two (inactive) public methods added (Null1, Null2)?

    I'm not entirely sure why you added those methods. As they are effectively the same (ignoring outa behaviour as there was no dira setup in the original code) I merged them into a single method, VFO(chn).

    The main loop does the following (posting #18):
    1. flush the input buffer
    2. prompt for command (setting VFO A or VFO B), press "a" or "b"
    3. in a local repeat loop get the command character, uppercase it and repeat if we didn't get "A" or "B"
    4. call VFO setup/update with either "A" or "B" (channel)
    5. get next command character
    If you have more commands in the future steps 3 and 4 could become either a method call with a case statement or you could embed the case statement in the main loop and call the relevant command handlers from there. For example:
    PUB main | c
    
      serial.start(115200)                                  'use default pins  (31/30)       
      waitcnt(clkfreq*2 + cnt)
    
      repeat
        serial.RxFlush
        [COLOR="blue"]' display menu
        serial.Char(serial#CS)
        serial.Str(string("configure VFO A: a", 13))
        serial.Str(string("configure VFO B: b", 13))
        serial.Str(string("         unused: c..z", 13, 13))[/COLOR]
        [COLOR="orange"]' read command
        serial.Str(string("Select function: "))
        repeat until (c := serial.CharIn & !$20) => "A" and c =< "Z"[/COLOR]
        case c
          "A".."B": VFO(c)
          other:
            serial.Char(c)
            serial.Char(serial#NL)
        waitcnt(clkfreq + cnt)
    
    I'm still puzzled about your menu comments in the source, e.g. which menu would you escape to? Are you saying that VFO control is a sub menu which is initially selected from an as yet unspecified main menu? Maybe we should get this program flow sorted first. Having what looks like 2 methods/functions doesn't justify any complexity :)
  • W8VKW8VK Posts: 30
    edited 2011-03-02 20:28
    kuroneko!
    attached on this reply will be the program ill correct to try and get it to operate your way! please look at the file attachment and see what needs corrected! Thanks for all! Your a great person to be working with!

    Rich W8VK
  • kuronekokuroneko Posts: 3,623
    edited 2011-03-02 20:38
    Sorry, I'm somewhat lost. That's posting #18 with modified pin numbers and added header/footer. What do you want me to correct here?

    As for its intended function see posting #22 (numeric list).
  • W8VKW8VK Posts: 30
    edited 2011-03-07 16:40
    kuroneko!
    Here is the 2 versions i got working for the USB and Comm Port. Very nice indeed!

    The only thing not interfaced into the programming is the CON PinR = 20 that is high when a is selected, and low when b is selected!
    But it does a nice job switching from a and b entries! Cool Beans!

    I have had family things keeping me away for a time but maybe will settle down here now! Way to go!

    Rich_W8VK
  • kuronekokuroneko Posts: 3,623
    edited 2011-03-07 16:44
    W8VK wrote: »
    The only thing not interfaced into the programming is the CON PinR = 20 that is high when a is selected, and low when b is selected!
    How is that supposed to work when counter A and B running in parallel? Does pin 20 alternate or does it only indicate last updated VFO?
  • W8VKW8VK Posts: 30
    edited 2011-03-08 08:52
    kuroneko!
    The PinR works this way! If you type a and Hit the enter key then backspace to update VFO A Frequency, PinR 20 goes high and stays high until you type b and hit the enter key for b and backspace to set in a new frequency entry for b which PinR then stays low until you would type a and hit the return key again which sets PinR high again!

    Rich W8VK
  • kuronekokuroneko Posts: 3,623
    edited 2011-03-08 17:13
    Odd behaviour but easy enough to do. Just add the following to the VFO method.
    PRI VFO(chn) | frequency, pin
    
      serial.Str(string("RX VFO "))                         '
      serial.Char(chn)                                      '
      serial.Str(string(": "))                              'user prompt
      
      frequency := serial.DecIn                             'read decimal value
      serial.Dec(frequency)                                 '
      serial.Char(serial#NL)                                'local echo
    
      pin := lookupz(chn - "A": PinA, PinB)                 'select pin
      source.synth(chn, pin, frequency)                     'set counter
    
      [COLOR="red"]dira[PinR] := 1                                       'only needed once -> move to cog setup
      outa[PinR] := chn                                     '"A" = %0100000[/COLOR][COLOR="blue"]1[/COLOR][COLOR="red"], "B" = %0100001[/COLOR][COLOR="blue"]0[/COLOR]
    
  • W8VKW8VK Posts: 30
    edited 2011-03-08 20:42
    kuroneko!
    That works perfect for the vfo switch! I have taken the program to 2 versions. One for use as a Receiver VFO and The second for use as a Transmitter VFO. Also included is the USB Port Versions!
    They work great! Nice programming job following my thoughts! Check out the Pin changes between the versions! Please continue to the next posting! Thanks!
    I think these 4 programs are ready for archive! Don't you?

    Rich W8VK
  • W8VKW8VK Posts: 30
    edited 2011-03-08 20:52
    kuroneko!
    The last part of this project is to combine Posting #29 Programs. To try and take the PinA, PinB, and PinR from the first version and combine with the second version PinC, PinD, and PinT for the posted file i've started on this reply. See the 2 attached files i've started.

    In the past, I could only run 2 synthesizers! Don't know why 4 wouldn't run as an entry in order to the 3rd and 4th shut down the first 2. Please take a look at the attached 2 files. Is this possible to do? Thanks!

    Rich W8VK
  • kuronekokuroneko Posts: 3,623
    edited 2011-03-09 00:32
    Yes, it can be done. But you have to remember that there are only 2 counters per cog. Which means you need a helper cog for every additional 2 channels. The attached example accepts A..D as an input. RX is handled in the main cog (A/B), TX is delegated to a helper method (C/D). You'll have to redefine the pin numbers again, mine are setup for the demoboard LED bar.
Sign In or Register to comment.