Generating 38kHz to drive an IrD LED while clocking the prop at 20kHz
JohnR2010
Posts: 431
in Propeller 1
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?
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
-Phil
Aren't there chips to do this, probably with a shutdown pin too...
Thanks
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.
https://www.digikey.com/products/en/crystals-oscillators-resonators/crystals/171?k=crystal&k=&pkeyword=crystal&pv139=184&FV=ffe000ab&mnonly=0&ColumnSort=0&page=1&stock=1&nstock=1&quantity=0&ptm=0&fid=0&pageSize=25
-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!
Thanks for your input!! Off to reading some data sheets.
-Phil
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!
-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.
-Phil
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!
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.
The CMOS 555's are quite a bit more expensive than a HEF4093
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.
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 ?
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 )
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.
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
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.
[/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
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?!
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.