Generating 38kHz to drive an IrD LED while clocking the prop at 20kHz

I’m working on a battery project and doing everything I can to keep the prop running without a crystal at the RCSLOW speed of 20kHz. So far things are going very well. I can read infrared data using the NEC IrD data format sent to the prop with an IrD receiver just fine.

Now I want to transmit data. To do that I need to modulate a 38kHz signal sent to an infrared LED. Since I’m running my prop at 20kHz the fastest signal my counter can send using NCO is 10kHz. So, to bump up my frequency I thought I would run my counter in PLL mode. This multiplies the NCO frequency by 16 with optional divisors. Well it is not working as I hoped. I see a square wave on the pin that looks to be close to the frequency I want but it is extremely unstable. So much so my old CRT based scope can’t sync on the signal so I don’t know what is going on for sure. In reviewing the manual, it says the “PLL circuit is designed to accept PHS bit frequencies from 4 to 8 MHz” (my bit frequency is 2.375kHz).
Why does the manual say it is not designed for frequencies lower than 4 Mhz?
Any other ideas on how to modulate the infrared LED at 38kHz?
DAT
  '*******************************************
  '* Assembly language driver by John Rucker *
  '*******************************************
                        org       0                                
txStart
                        mov     t1, par
                        mov     cDAdd, t1
                        add     t1, #4
                        mov     cAAdd, t1
                        
                        mov     dira, M_OP              ' Set Pins to output
                        mov     ctra, M_ctra            ' Setup counter see M_ctra (ctra mask)

                        mov     frqa, m_frqa

chkTx
                        jmp     #chkTx                  ' Just loop here so I can inspect signal with scope.

' Initialized data
M_OP                    long |< TXp                     ' Cog's output pin mask
'                                  :-------------------------------------------   00010 = PLL single-ended mode
'                                  :   :---------------------------------------     111 = Divide by 1
'                                  :   :                         :-------------  011010 = pin 26 = txpin
'                                  :   :                         :
M_ctra                  long %0_00010_111_00000000_000000_000_011010            ' mask for PLL X 16 of NCO
M_frqa                  long 51_0027_366                                        ' NCO freq to generate 2,375Hz 1/16 of 38kHz

' set the following before starting cog
lg                      long 0                          ' Set this to address of the loging address before starting cog

' Uninitialized data
t1                      res     1
t2                      res     1
cAAdd                   res     1
cDAdd                   res     1

                        fit   496

Comments

  • 28 Comments sorted by Date Added Votes
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 21,129
    edited August 24 Vote Up0Vote Down
    The PLL's VCO won't operate at frequencies very much below 4 MHz x 16.

    -Phil
    “Perfection is achieved not when there is nothing more to add, but when there is nothing left to take away. -Antoine de Saint-Exupery
  • Switch to RCFAST to send the data?
    Aren't there chips to do this, probably with a shutdown pin too...
  • There are chips on the receiving side that is what I'm using. I bet there are on the TX side as well. I will start digging.

    Thanks
  • Why don't you just run the Prop from a 38kHz crystal in the first place? Use the output of the oscillator into a gate, simple.
    Tachyon Forth - compact, fast, forthwright and interactive
    useforthlogo-s.png
    TACHYON DEMONSTRATOR
    Brisbane, Australia
  • jmgjmg Posts: 10,345
    edited August 24 Vote Up0Vote Down
    JohnR2010 wrote: »
    I’m working on a battery project and doing everything I can to keep the prop running without a crystal at the RCSLOW speed of 20kHz. So far things are going very well. I can read infrared data using the NEC IrD data format sent to the prop with an IrD receiver just fine.

    The PLL is going to draw a LOT more power, and it will not lock at low PFD value, as you have found.

    What IR led current do you plan on ? -ie what is the tolerable MCU overhead as part of this ?

    Your choices would be something like
    * use 76kHz osc, or Xtal + with low power osc - cleanest, but 76kHz is something of no-mans-land.
    * Switch to RC fast only during Txmit, - this assumes you can calibrate RC fast & can tolerate the Icc.
    Maybe you can even flip during the modulation ?
    * Use an external small MCU as the IR tx, where hopefully the better RC osc tolerance is good enough.
    * Use an external Gated-Osc at 38KHz that the prop simply gates.
    A HEF4093 should make a nice low-power, 38kHz 3 pin RC oscillator ( 3 pin has better tolerance than 2 pin), with 3v3 or even lower Vcc.
    If you can receive at 20Khz, you probably can also generate the modulation at the same speed, and just need a 38kHz gated-osc.
  • “Perfection is achieved not when there is nothing more to add, but when there is nothing left to take away. -Antoine de Saint-Exupery
  • JohnR2010JohnR2010 Posts: 387
    edited August 25 Vote Up0Vote Down
    Why don't you just run the Prop from a 38kHz crystal in the first place? Use the output of the oscillator into a gate, simple.
    Here are some 76.8 kHz crystals:


    -Phil

    In my last prop battery project, I used a 5MHz external crystal and switched to internal fast and then down to 20kHz during sleep periods. Worked great and I’m comfortable doing it. But for this project I just don't need the horsepower of a faster clock (trying to make everything work at 20kHz) and I would like to avoid the power hit and extra cost of having an external crystal. I'm so close just need to generate a 38kHz signal. If I can't find some other way to get it, an external crystal may be the way I go. After all, at 38kHZ or even double that, the external crystal circuit shouldn’t take as much power as the 5MHz crystal does.

    Thanks Peter and Phil!


  • JohnR2010JohnR2010 Posts: 387
    edited August 25 Vote Up0Vote Down
    jmg wrote: »
    JohnR2010 wrote: »
    I’m working on a battery project and doing everything I can to keep the prop running without a crystal at the RCSLOW speed of 20kHz. So far things are going very well. I can read infrared data using the NEC IrD data format sent to the prop with an IrD receiver just fine.

    What IR led current do you plan on ? -ie what is the tolerable MCU overhead as part of this ?

    Your choices would be something like
    * use 76kHz osc, or Xtal + with low power osc - cleanest, but 76kHz is something of no-mans-land.
    * Switch to RC fast only during Txmit, - this assumes you can calibrate RC fast & can tolerate the Icc.
    Maybe you can even flip during the modulation ?
    * Use an external small MCU as the IR tx, where hopefully the better RC osc tolerance is good enough.
    * Use an external Gated-Osc at 38KHz that the prop simply gates.
    A HEF4093 should make a nice low-power, 38kHz 3 pin RC oscillator ( 3 pin has better tolerance than 2 pin), with 3v3 or even lower Vcc.
    If you can receive at 20Khz, you probably can also generate the modulation at the same speed, and just need a 38kHz gated-osc.
    I like the HEF4093 as a low-power oscillator. I will need to do some quick research and see what we are talking about for external components. I plan on producing several of these boards (by hand) and I’m trying my best to minimize external components. As for the IR LED current, I want to keep that to a minimum as well. The IR LED is going to only be used to acknowledge a data packet and to request data when the prop wakes up. My plan is to get everything working and do some testing with a receiver across the room and see what kind of current I need to drive the LED to reach it. I hope it is around 15 to 20mA but won’t know until I do some testing. The LED I have can take up to 100mA in very short burst.
    Thanks for your input!! Off to reading some data sheets.


  • How's that compare to the trusty triple-nickel? Even the antique 555s in my parts bin only draw ~3.6mA and I see Digikey advertising some at 30uA! A 430 and 1K6 resistor and a couple 0.01uF caps produces a 39.7KHz output with 52% duty cycle, powered directly from an IO pin.
  • Tracy AllenTracy Allen Posts: 6,082
    edited August 25 Vote Up0Vote Down
    About IR LEDs, the intensity depends on the half-angle distribution, more intensity into a narrow beam. For example, the Osram SFH4550 has a half-angle of +/- 3 degrees and at maximum gives 1100mW/sr when driven at 100mA. Proportional at lower currents. It is meant for data links or things like smoke detectors. Best when the optical path is fixed.

  • JohnR2010JohnR2010 Posts: 387
    edited August 25 Vote Up0Vote Down
    looks like a 555 timer is the most popular solution out there. Here is a simple circuit for an Arduino. I was hoping to find a single IR emitter with a 38kHz carrier frequency all in a nice 3 pin package. It is easy to find an 38kHz IR receiver like that but not the emitter.
  • Generate a 12.666 kHz signal to drive the IREDs. The detector might be able to respond to the third harmonic of the square wave it receives.

    -Phil
    “Perfection is achieved not when there is nothing more to add, but when there is nothing left to take away. -Antoine de Saint-Exupery
  • JohnR2010JohnR2010 Posts: 387
    edited August 25 Vote Up0Vote Down
    Generate a 12.666 kHz signal to drive the IREDs. The detector might be able to respond to the third harmonic of the square wave it receives.
    -Phil
    I just can’t get 12.666 kHz out of the counter in NCO mode with a 20-kHz clock. With a frqa value of 2,720,002,789 I should see 12.666 kHz. Instead I see an unstable 10 kHz to 7 kHz signal. Even at 9.5 kHz it is unstable. I think I read once the max frequency you can get with NCO mode is ½ clock frequency.

    The signal gets better down around 5.428 kHz but still not a super clean square wave. I guess this is because I’m running with the internal oscillator. At 5.428 kHz, I’m seven harmonics away from my 38k target. I didn’t test the IRD communications as I’m pretty sure that is going to be a very week signal.
    But thanks, I liked the idea!

  • You're right, of course: max is ½ clock frequency. Try for the fifth harmonic of 7.6 kHz?

    -Phil
    “Perfection is achieved not when there is nothing more to add, but when there is nothing left to take away. -Antoine de Saint-Exupery
  • You're right, of course: max is ½ clock frequency. Try for the fifth harmonic of 7.6 kHz?

    -Phil

    okay I will give the 5th harmonic a try. I may have to boost up the current to my IR LED to get the distance I want. I will give it a try and see.
  • One possible problem with going to the fifth harmonic is fine control of the modulation, since every pulse the Prop generates has to equal five that the sensor sees. It all depends upon how many pulses equals one bit: the more the better.

    -Phil
    “Perfection is achieved not when there is nothing more to add, but when there is nothing left to take away. -Antoine de Saint-Exupery
  • Okay I can get 7.6 kHz out but not clean. The square wave jumps around in frequency. I have never looked at the output of a NCO counter running with the slow internal clock. It looks ugly. So, I don’t think I’m getting a good base frequency. But anyway the 5th harmonic wasn’t strong enough to trigger my 38 kHz IR detector. I would need to drive the LED with more current probably up to an amp. That kills my battery life.
    I’m now thinking I can get away with this being a receive only device. I will give it some more thought over the weekend. The main reason I wanted the TX ability is to allow the device to wake up and request data. This week I got my new IR Receiver the TSOP38238 and was pleasantly surprised how little current it requires when waiting for data. With the prop in pin sleep I can sleep and wake on data from the IR Receiver and all this takes about 200 uA. So, if I’m always listening for data why would I need to ask for it.
    I’m really trying to keep this one simple!
    Thanks again Phil for the suggestion!
  • Tracy AllenTracy Allen Posts: 6,082
    edited August 25 Vote Up0Vote Down
    The Prop's XTAL1 option may be too hard for a 76.8kHz tuning fork xtal. I've tried with a 32.768kHz crystal, and the oscillator just sits there at 1/2 supply drawing excess current, no oscillation.

    Here are experimental results, all pins configured for lowest current, running a counter in NCO mode at clkfreq/2.

    RCslow: 8.6µA without NCO, or 9.8µA with NCO, period measured 97.18µs (clkfreq=20580Hz)
    RCfast: 0.752mA without NCO, or 1.52mA with NCO, period measured 146.52ns . (clkfreq=13.680MHz)
    XTAL1, 5MHz: 0.537mA without NCO, or 0.88mA with NCO, period 399.98ns (clkfreq=5MHz)
    XTAL1 with 32kHz rock: 6mA to 7.2mA, no oscillation.

    It seems to me that a 4 or 5MHz crystal on the Prop remains a one-part solution for those occasional transmissions.

  • jmgjmg Posts: 10,345
    ChrisGadd wrote: »
    How's that compare to the trusty triple-nickel? Even the antique 555s in my parts bin only draw ~3.6mA and I see Digikey advertising some at 30uA!
    a HEF4093 should draw far less than 3.6mA, and has quite low part-error in 3 pin mode. (2 pin mode uses only the Hyst Band, so Fo has 100% Hyst variations )
    The CMOS 555's are quite a bit more expensive than a HEF4093
  • jmgjmg Posts: 10,345
    edited August 25 Vote Up0Vote Down
    The Prop's XTAL1 option may be too hard for a 76.8kHz tuning fork xtal. I've tried with a 32.768kHz crystal, and the oscillator just sits there at 1/2 supply drawing excess current, no oscillation.
    Yes, those higher-freq modes can be a pain to coax/force down to 32kHz and even if you can, the current drain is still high..
    Ideally, your MCU has a specific uA amplifier for 32kHz operation.

    An added series R on XTALOUT can help tune Icc values to a min, on Xtal oscillators.
    Here are experimental results, all pins configured for lowest current, running a counter in NCO mode at clkfreq/2.

    RCslow: 8.6µA without NCO, or 9.8µA with NCO, period measured 97.18µs (clkfreq=20580Hz)
    RCfast: 0.752mA without NCO, or 1.52mA with NCO, period measured 146.52ns . (clkfreq=13.680MHz)
    XTAL1, 5MHz: 0.537mA without NCO, or 0.88mA with NCO, period 399.98ns (clkfreq=5MHz)
    XTAL1 with 32kHz rock: 6mA to 7.2mA, no oscillation.

    It seems to me that a 4 or 5MHz crystal on the Prop remains a one-part solution for those occasional transmissions.

    On those numbers, Crystal (or ceramic resonator, for faster start times) seems a very good idea. Also solves RCosc variation issues.

    As this is not using the PLL, a 3.58MHz resonator should be slightly lower Icc again from the data curves, and if that is still to high, it may be possible to push down further, to some 'Min-power' MHz (Osc effects included) 2MHz is another common resonator value

    I notice 455kHz /12 = 37.916kHz, & 800/21 = 38.095 but not sure if the operating Icc of 455kHz,800kHz area is the minimum-power point ?
  • jmgjmg Posts: 10,345
    Here are experimental results, all pins configured for lowest current, running a counter in NCO mode at clkfreq/2.

    RCslow: 8.6µA without NCO, or 9.8µA with NCO, period measured 97.18µs (clkfreq=20580Hz)
    RCfast: 0.752mA without NCO, or 1.52mA with NCO, period measured 146.52ns . (clkfreq=13.680MHz)
    XTAL1, 5MHz: 0.537mA without NCO, or 0.88mA with NCO, period 399.98ns (clkfreq=5MHz)
    Nice numbers...
    Are those taken with 1 COG, in permanent WAIT ?

    Is it easy to repeat those for a NCO out of ~38kHz, where 38kHz is possible ? Curious how much of that NCO adder is the pin-toggle effect.
    ( 13.680M/360 = 38000, 5M/round(5M/38k) = 37878 )

  • Tracy AllenTracy Allen Posts: 6,082
    edited August 26 Vote Up0Vote Down
    Yes one cog. Simple program with variations:
    CON
      _clkmode = xtal1  ' or RCSLOW or RCFAST
      _xinfreq = 5_000_000   
                        '
    PUB main
      dira := $ffff  ' all pins are outputs
      outa := $3000  ' all pins except 28,29 (scl,sda) are low
      ctra := %00100<<26  ' NCO to p0
      'frqa := negx or zero or 32641751 
      frqa := 32641751   ' 26.315us -> 38.000.85  kHz (from 'scope)
      repeat
        waitcnt(0)
    

    This was on a Parallax protoboard with its standard 5MHz rock and modified to allow monitoring the CPU current.
    0.53mA ctra=0, that is, cog counter disabled
    0.54mA when frqa=0 but cog counter enabled, flatline output
    0.88mA when frqa=negx, so 4MHz output to p0
    0.9mA same as above but into 'scope probe LeCroy PP011 10M 10pF.
    0.59ma frqa=32641751 f=38kHz, the LED target frequency.

  • jmgjmg Posts: 10,345
    This was on a Parallax protoboard with its standard 5MHz rock and modified to allow monitoring the CPU current.
    0.53mA ctra=0, that is, cog counter disabled
    0.54mA when frqa=0 but cog counter enabled, flatline output
    0.88mA when frqa=negx, so 4MHz output to p0
    0.9mA same as above but into 'scope probe LeCroy PP011 10M 10pF.
    0.59ma frqa=32641751 f=38kHz, the LED target frequency.
    Thanks - I think you mean 400ns / 2.5MHz on p0 ?
    Shows quite significant +350uA adder for the 2.5MHz pin drive, and a much more tolerable +50uA for 38kHz
    Indicates ~ 13pF equivalent Prop Pin power capacitance, driving P0 @ 2.5MHz



  • Oh! right, 0.4µs period, 2.5MHz frequency. And driving p0 at 38kHz adds 50µA current, compared to leaving it static.

    The relevant clkset commands are,

    clkset(%0_00_00_001, 20_000) . ' drop to RCSLOW at ~20 KHz

    clkset(%0_01_01_001, 20_000) . ' xtal oscillator on, no PLL, still operating on RCslow

    clkset(%0_01_01_011, 5_000_000) ' switch to operate on 5MHz xtal, no PLL

    I've found that 4 milliseconds is enough time for the 5MHz to stabilize with an HC48 style crystal, although the Prop manual recommends 10ms. I wonder how it would be with a 5MHz resonator.


  • jmgjmg Posts: 10,345
    edited August 28 Vote Up0Vote Down
    I've found that 4 milliseconds is enough time for the 5MHz to stabilize with an HC48 style crystal, although the Prop manual recommends 10ms.
    I wonder how it would be with a 5MHz resonator.
    [/quote]
    Resonators are usually better than 10x faster, thanks to their lower Q. You can even use inductors, but their tolerance is not great.

    This ST app note suggests 100us~500us

    I also find this better picture
    0003_img0002.ashx?la=en-us

  • Makes one wonder if the combination of a resonator and a quartz crystal could somehow be combined to produce fast startup and accurate ultimate frequency? Ie the quartz crystal might somehow lock the resonator onto its frequency. Just a thought.
  • I found a 2.4576 MHz xtal sitting in a drawer. The Prop Iq driving the output pin at 38kHz was 340 µA (frqa:=66409813). Weirdness though, sometimes no output. The crystal was a big old HC48.

    No ceramic resonators here to try.

    About lower frequency crystals, <100kHz, the startup time in a Pierce circuit can be quite long, tenths of a second rather than a millisecond or so for higher MHz AT cut crystals. It shouldn't be hard to make a 38kHz xtal oscillator that draws less than 50µA at 3.3V, but the startup time has to be taking into consideration in the keying scheme. More parts?!
  • jmgjmg Posts: 10,345
    .. It shouldn't be hard to make a 38kHz xtal oscillator that draws less than 50µA at 3.3V, but the startup time has to be taking into consideration in the keying scheme. More parts?!
    38kHz crystals are not easy to find... or cheap.
    The Prop Xtal amplifier would not get down to 50uA at 3.3V, but you certainly can get external Oscillators with square wave outputs.
    eg RTC's start at 31c/1k
    or, you could make a uA region Xtal oscillator, plus a gated-burst buffer for IR, using a So14 4001UB or 4011UB non-buffered gate.


Sign In or Register to comment.