Shop OBEX P1 Docs P2 Docs Learn Events
Cogs and counter placement question — Parallax Forums

Cogs and counter placement question

yarisboyyarisboy Posts: 245
edited 2011-07-23 19:25 in Propeller 1
I've uploaded the code I'm working on. It works as designed but I don't understand why counter B of cog 0 works fine inside the main loop at line 118 but doesn't work at line 81 where the other three counters are launched. I/O is working fine for the cog that generates my Vehicle speed sensor signal and the dash lights dimmer signal. Counter A of cog 0 can be anywhere and it works fine. My O-scope decided to take the night off but the PST reports everything working as planned.

Comments

  • JonnyMacJonnyMac Posts: 9,208
    edited 2011-07-22 19:07
    The cog you're calling with cognew stops, killing the counters that it had previously launched. If you want a Spin method to run in a cog you need to set it as an infinite loop, otherwise when you get to the end of the method that cog -- and its associated hardware -- is shutdown.
  • yarisboyyarisboy Posts: 245
    edited 2011-07-22 20:18
    By putting cog 0 counter A and B back in the PST loop both outputs became active. I'm still trying options on the launched cog. The O-scope is fine. I paid so little for it on ebay that I suspect it when I shouldn't.
  • yarisboyyarisboy Posts: 245
    edited 2011-07-22 20:56
    The changes I've tried latest are obviously not right yet. It loads ok but I've lost my outputs again and now I have garbage on my PST. I've generated one or more run-time errors.
  • JonnyMacJonnyMac Posts: 9,208
    edited 2011-07-22 21:08
    You just need to keep that cog running, you don't need to restart the counters over and over; try this:
    pub extras(po1,freq1,po2,freq2)
    
      freq.Synth("A",po1,freq1)
      dira[po1] := 1
      freq.Synth("B",po2,freq2)
      dira[po2] := 1   
      
      repeat
        waitcnt(0)
    
  • JonnyMacJonnyMac Posts: 9,208
    edited 2011-07-22 21:16
    How many PWM outputs do you need and what is the frequency requirement of them? Your code seems to be written as if you want the synth objects to follow ADC inputs -- that won't happen without additional code.
  • kuronekokuroneko Posts: 3,623
    edited 2011-07-22 21:19
    JonnyMac wrote: »
    You just need to keep that cog running, you don't need to restart the counters over and over; try this:
    I think the reason for this is that he wants the frequency to change depending on the ADC values (live update).

    Anyway, I noticed that the stack for the extras method is too small (try 32 each). Also, assuming I'm right with the live update, the extras method takes parameters by value. There is no way that they get updated once you're in the method. Try changing it to:
    pub extras(po1,freq1,po2,freq2)
    
      repeat
        freq.Synth("A",po1,long[freq1])
        freq.Synth("B",po2,long[freq2])
    
    and call it with
    cognew(extras(VPIN,@freqvss,IPIN,@freqdim),@stack[0])
    cognew(extras(TPIN,@freqtach,NPIN,@freqtach),@stack[32])
    
    or use a dedicated object which can handle multi-pin PWM. IIRC, JonnyMac has one of those somewhere.
  • JonnyMacJonnyMac Posts: 9,208
    edited 2011-07-22 21:47
    or use a dedicated object which can handle multi-pin PWM

    Agreed.
  • yarisboyyarisboy Posts: 245
    edited 2011-07-22 22:00
    It was working that way for just two outputs with cog 0 counter A and B. I have the output 16 putting out a frequency proportional to the position of a pot on input 7 of the ADC chip. The Propeller based dash display module correctly interprets this frequency and drives a digital display of RPM. I've got the Prop tach working in my car right now. I also have a program that also correctly displays miles per hour that works correctly in the car from the VSS but I haven't put both programs in separate cogs yet for the in-car prop. Getting my cogs merit-badge on this bench signal generator will help with that and save gas. On this simulator I launched counter B/cog 0 to drive output 20 hooked to a piezo speaker for that engine RPM sound. I now have pots on channel 6 and 5 of the ADC chip so that I can add a speedometer signal and a display dimmer signal. My son has GPS on his phone so calibrating the speedometer display in the car prop won't be hard and I have all the gear ratios for the vehicle so RPM calibration is just math at that point. You've quickly surmised the intent of the contraption.
  • yarisboyyarisboy Posts: 245
    edited 2011-07-22 22:09
    Thanks a bunch. Taking Java last spring helped a lot when it comes to understanding memory addressing. I'll go look in the morning for JonnyMac's object. Good catch on the stack size. At 8,000 RPM the ignition system generates a frequency just under 277 Hz. The VSS tone ring pitch is slightly lower than that. That may make this do-able in just Spin.
  • JonnyMacJonnyMac Posts: 9,208
    edited 2011-07-23 08:01
    That may make this do-able in just Spin.

    Wouldn't it be helpful to have multiple outputs from one cog? In the code above you seem to want three frequency outputs that you can change at will.
  • yarisboyyarisboy Posts: 245
    edited 2011-07-23 19:25
    The thing works perfectly now. Many thanks to both JonnyMac and kuroneko. There is, no doubt, better ways to do what the program does but now that it meets my needs on the bench I'll save the object as a reference and use the hardware. A change to any one pot shows up on the PST or scope independent of the other two. With two counters in each cog I have cogs 1 & 2 generating 4 frequencies out. Two of them are actually the same frequency but the piezo pulls so much power from the prop on pin 20 that I'm glad the same frequency is going out pin 16 to the op-amp. What you two have taught me will come in handy when I have to run multiple cogs in the in-car Prop to drive four displays. Thanks again Jon for your help with the MC14498 LED driver driver. I will always have much to learn but I'll have to mark this one "solved"
    I do indeed have three frequency outputs that I can change at will and that was the design goal.
Sign In or Register to comment.