Shop OBEX P1 Docs P2 Docs Learn Events
cog usage question? — Parallax Forums

cog usage question?

yarisboyyarisboy Posts: 245
edited 2010-10-18 19:58 in Propeller 1
I'm going to be using jw_freqin.spin to monitor frequencies on pins 0, 1, and 2. Does that mean that I can use counters A and B and cog zero and then would need to launch another cog and use A on it to pick up pin 2? I'll be reading a serial input and writing to two serial outputs. I'm using Synth.spin to generate a clock pulse for the serial outputs. I've never hit the limit on cog 0 yet but my program just keeps growing. With that many things going on I'm still a little fuzzy on when I need another cog and when I don't.

Yes, I meant jm_freqin.spin. Sorry

Comments

  • kwinnkwinn Posts: 8,697
    edited 2010-10-17 08:39
    Since I could not find jw_freqin.spin in the obex I am not sure but I suspect it may launch it's own cog to run a pasm program for this function. The serial object and Synth.spin probably do so as well. Look in the individual objects and see if they have a "cognew" command.
  • hover1hover1 Posts: 1,929
    edited 2010-10-17 09:25
    I think he meant to say jm_freqin.spin. It is in the OBEX here:

    http://obex.parallax.com/objects/479/

    Jim
    kwinn wrote: »
    Since I could not find jw_freqin.spin in the obex I am not sure but I suspect it may launch it's own cog to run a pasm program for this function. The serial object and Synth.spin probably do so as well. Look in the individual objects and see if they have a "cognew" command.
  • yarisboyyarisboy Posts: 245
    edited 2010-10-17 09:34
    hover1 wrote: »
    I think he meant to say jm_freqin.spin. It is in the OBEX here:

    http://obex.parallax.com/objects/479/

    Jim

    How right you are. Jon Williams is an author name. Here he goes by JonnyMac. It runs in the background on counters looking for low to high and high to low transitions and returns the clock tics between the trigger points.
  • Mike GreenMike Green Posts: 23,101
    edited 2010-10-17 09:39
    If you read the comments at the beginning of jm_freqin, you'll see that it uses one cog for each frequency to be monitored. This includes the counters in the cog. For 3 frequencies, you'll need 3 cogs.

    Your description of the rest of your stuff doesn't make a lot of sense. Are your serial inputs and outputs asynchronous or synchronous? Asynchronous doesn't need a clock while Synth.spin is not intended for use as a clock source for a synchronous serial stream. Usually that's included in the code for the serial data handling so it's synchronous with the data.
  • kwinnkwinn Posts: 8,697
    edited 2010-10-17 10:03
    Thanks hover1.

    yarisboy, as mike confirms, it does launch a cog to measure the frequency. It uses both counters to measure one frequency so you will need 3 cogs for 3 frequencies unless you modify it.

    Perhaps there are other objects for multiple frequencies.
  • yarisboyyarisboy Posts: 245
    edited 2010-10-17 20:15
    When I modified BS2_functions.Spin to use with the MC14489 it could be made to work by adjusting its wait counts. How the timing was handled was not clear to me and it did not play well in the same program with the PST. The notes with BS2_functions.shiftout claimed it would communicate at 16 KHz. When I wrote a PST friendly clone I got it to work well at 8 KHz. I'll take it. I grafted in the Enable pin and just kept experimenting until it worked. After that, I comb back through the spec sheet and glean a bunch of "so that's what they mean by thats". By establishing a hard clock pulse I got to play around with waitpne and waitpeq. When I do post code one can see experiments that make no sense at all except I get to see what happens when I just try things. To a seasoned veteran with a deep understanding, these things make no sense at all. I haven't written the driver for the serial 32-channel controller yet and, from reading the spec sheet, I see that it differs in almost every way from the com rules that apply to the Motorola MC14489. The temperature/humidity sensor I got from WBA consulting is also serial but the objects for it look like I will have to make few (if any) changes to use it. The tachometer software was the easiest to finish. So far the speedometer application has turned out to be way more complex to do well. The dash dimmer "reostat" on my Yaris communicates over the CAN buss with a duty signal square wave. Reading that with a third cog should allow my extra serial displays to have intensity control matching that of the rest of the dash instruments even though Toyota holds their firmware secrets close to the vest. Every day that I thrash on this project results in more highlighting of the PE lab book and the Prop manual with copious margin notes.
    When learning to walk, you crawl first.
  • kwinnkwinn Posts: 8,697
    edited 2010-10-18 06:58
    yarisboy, I have to admire your persistence and the challenge of the project you are undertaking. Some suggestions.

    Explain what you are trying to do as clearly and in as much detail as possible. For example, the 3 frequencies you are trying to measure, what is the maximum frequency expected and how often do you need to update it. Measuring 3 frequencies of a few KHz could be done in one cog, whereas frequencies in the MHz range might require 2 or 3 cogs.

    Look in the OBEX for drivers. Even if there is no driver for your specific IC or function there is probably something close that will provide a good starting point as well as code examples.

    The IC data sheets are your friend. They usually provide all the information you need to use an IC. If you do not understand all the details ask this forum, and please, provide details.
  • yarisboyyarisboy Posts: 245
    edited 2010-10-18 18:56
    The tachometer at 8000 RPM has an ignition pulse frequency of 266.66....Hz
    The speedometer at 50 MPH is getting a pulse frequency of 57 Hz
    Neither of those applications is any challenge for the Propeller. The temp sensor can also be run at low baud rates. Its the perfect project-set to get a handle on the Spin fundamentals.
    The Prop can run so fast that Op-amps left over from the BS2 stuff gives square waves if run slow, trapazoid waves on medium, and triangle waves on fast. My cheapy legacy chips just don't have the slew rate of the modern stuff. I'm just dazzled by the performance even with just Spin. Back in '69 my transmitter and receiver consisted of vacuum tubes. Whoda thought we would have such a cheap source of fun like this today. Once I've released the current objects I'll be converting them to PropBasic openly on the forum. They say to slow down alzheimers one must stay mentally challenged. This is my challenge. Then maybe I can draw Bean into the PITA club. (HeHe..)
    In a year I may be able to challenge the Prop in PSAM or PropBasic with some high frequency applications but for now I'm having fun putting stuff on the Yaris that would have cost thousands from the dealer and at a BS2 level of difficulty. NickMaClick got me off the BS2 because it just costs too much.
  • kwinnkwinn Posts: 8,697
    edited 2010-10-18 19:58
    OK, so all less than 500Hz and no pasm required. You will still need to get another cog running for each frequency you want to measure. That would mean running 3 copies of jm_freqin.
Sign In or Register to comment.