Freqout question
Hi Folks,
Below I have pasted the code from the sx-b examples for freqout
This doesn't seem to generate the right frequency for the IR receiver.
I dont think the freqout is being scaled properly by the compiler. It's probably something I'm doing...
I was able to get the 38khz by running from the sxkey at 38MHZ, instead of the 4mhz in the example, and using the value of 72400 in place of 38000,
So I know my electronics are functioning
Thanks!!!
Jeff B
' =========================================================================
'
' File...... FREQOUT.SXB
' Purpose... Object detection with IR
' Author.... (c) Parallax, Inc. -- All Rights Reserved
' E-mail.... support@parallax.com
' Started...
' Updated... 05 JUL 2006
'
' =========================================================================
'
' Program Description
'
'
' Uses FREQOUT to modulate an IR LED for object detection. When object
' is detected, a tone is generated from the pieze element.
'
' Device Settings
'
DEVICE SX28, OSCXT2, TURBO, STACKX, OPTIONX
FREQ 4_000_000
ID "FREQOUT"
'
' IO Pins
'
IrLED VAR RB.0 ' output to IR LED
Detect VAR RB.1 ' input from IR detector
Spkr VAR RB.2 ' output to piezo
'
' Constants
'
IrMod CON 38000 ' modulation freq = 38 kHz
Yes CON 0 ' for active-low output
No CON 1
' =========================================================================
PROGRAM Start
' =========================================================================
'
' Program Code
'
Start:
DO
FREQOUT IrLED, 1, IrMod ' modulate IR diode
IF Detect = Yes THEN ' check detector
SOUND Spkr, 100, 2 ' buzz if object detected
ENDIF
LOOP
Below I have pasted the code from the sx-b examples for freqout
This doesn't seem to generate the right frequency for the IR receiver.
I dont think the freqout is being scaled properly by the compiler. It's probably something I'm doing...
I was able to get the 38khz by running from the sxkey at 38MHZ, instead of the 4mhz in the example, and using the value of 72400 in place of 38000,
So I know my electronics are functioning
Thanks!!!
Jeff B
' =========================================================================
'
' File...... FREQOUT.SXB
' Purpose... Object detection with IR
' Author.... (c) Parallax, Inc. -- All Rights Reserved
' E-mail.... support@parallax.com
' Started...
' Updated... 05 JUL 2006
'
' =========================================================================
'
' Program Description
'
'
' Uses FREQOUT to modulate an IR LED for object detection. When object
' is detected, a tone is generated from the pieze element.
'
' Device Settings
'
DEVICE SX28, OSCXT2, TURBO, STACKX, OPTIONX
FREQ 4_000_000
ID "FREQOUT"
'
' IO Pins
'
IrLED VAR RB.0 ' output to IR LED
Detect VAR RB.1 ' input from IR detector
Spkr VAR RB.2 ' output to piezo
'
' Constants
'
IrMod CON 38000 ' modulation freq = 38 kHz
Yes CON 0 ' for active-low output
No CON 1
' =========================================================================
PROGRAM Start
' =========================================================================
'
' Program Code
'
Start:
DO
FREQOUT IrLED, 1, IrMod ' modulate IR diode
IF Detect = Yes THEN ' check detector
SOUND Spkr, 100, 2 ' buzz if object detected
ENDIF
LOOP

Comments
Try using "FREQOUT IrLED, 50, IrMod" and see if it works.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"A government big enough to give you everything you want, is big enough to take away everything you·have."·· Thomas Jefferson
"It is our choices, Harry, that show what we truly are, far more than our abilities."·Dumbledore from Harry Potter
www.iElectronicDesigns.com
·
So, What I'm really doing is a bit beyond the code example.
I actually did try stretching out the original time value, and it didnt cause the receiver to respond
The wacky part is that in order to get the 38khz at all I goosed the clock frequency way up to 38mhz, and use the value of 72400 ( by trial and error) to make the receiver wake up properly. I am using a freq meter as well...
I'm transmitting to a BS2 ( for now , I want to do that ultimately with an sx as well) and using the modified example code below, I'm able to receive pulsein's on the bs2, as well as nice solid logic probe readings.
The original example code wont wake up the receiver at all. My freq meter says the resulting frequency from the example code ( with a pulse time value of 200 ) is 174khz
I did use the freq meter and some trial and error to get the values that will give me the 38khz below
Could the compiler directives incorrect in some way? It seems the sx clock frequency isn't being scaled to the 38000 value in some way, which would affect the pulsin results I'll eventually be looking for on the sx I would guess.
hmmmm, Thanks!!!
JB
' =========================================================================
'
' File...... FREQOUT.SXB MODIFIED
' Purpose... Object detection with IR
' Author.... (c) Parallax, Inc. -- All Rights Reserved
' E-mail.... support@parallax.com
' Started...
' Updated... 05 JUL 2006
'
' =========================================================================
'
' Program Description
'
'
' Uses FREQOUT to modulate an IR LED for object detection. When object
' is detected, a tone is generated from the pieze element.
'
' Device Settings
'
DEVICE SX28, OSCXT2, TURBO, STACKX, OPTIONX
FREQ 38_000_000
ID "IRTRANS"
'
' IO Pins
'
'IrLED VAR RB.0 ' output to IR LED
'Detect VAR RB.1 ' input from IR detector
'Spkr VAR RB.2 ' output to piezo
'irfreq var word
'
' Constants
'
IrMod CON 72400
' 38000000, 72400 modulation freq = 38 kHz
'69725 = 36.74
'108090 = 56.7k
' 63250 = 33.3k
'73200 = 38.42
' =========================================================================
PROGRAM Start
' =========================================================================
'
' Program Code
'
Start:
DO
FREQOUT RB.0, 4, IrMod ' frame pulse @ 4ms
pause 200
LOOP
· Are you using the USB version of the SX-Key ?
· If so, after running the original program (at 4 mhz) do Run->Clock and make SURE it is set to 4.000MHz.
· I have found that sometimes the USB version doesn't set the clock properly.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"A government big enough to give you everything you want, is big enough to take away everything you·have."·· Thomas Jefferson
"It is our choices, Harry, that show what we truly are, far more than our abilities."·Dumbledore from Harry Potter
www.iElectronicDesigns.com
·
Yeah, it is the USB version. So, it appears that modifying the clock via the run/clock window proved fruitful. Somehow it was defaulting to the 400khz setting, even though the code instructs it otherwise. When set to the proper 4mhz, I indeed get the 38khz. Oddly enough, my other program, after perhaps 50 program/run cycles at the 38mhz, didn't seem to do that. BTW the 4mhz coming right out of the sxkey was beyond the range of the frequency counter function on my multimeter [noparse]:)[/noparse]
I was hoping to use the 4mhz clock speed for power consumption reasons. Thanks so much, this will get me much closer!
Jeff B
If you aren't using SERIN or SEROUT and don't need real acurate timing you could use OSC4MHZ to use the internal 4MHZ clock.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"A government big enough to give you everything you want, is big enough to take away everything you·have."·· Thomas Jefferson
"It is our choices, Harry, that show what we truly are, far more than our abilities."·Dumbledore from Harry Potter
www.iElectronicDesigns.com
·