How to use the Counter in SPIN to create a carrier?
william chan
Posts: 1,326
Hi,
Let's say I need to create a carrier for an IR led at 38Khz.
I believe using a loop in SPIN is too slow for 38Khz. ( Assembly would use up another cog )
Can I use a cog's CTRA or CTRB in SPIN to do this?
Any example codes to set up the counters in SPIN or to start or pause the carrier would be most appreciated.
Thanks.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.fd.com.my
www.mercedes.com.my
Let's say I need to create a carrier for an IR led at 38Khz.
I believe using a loop in SPIN is too slow for 38Khz. ( Assembly would use up another cog )
Can I use a cog's CTRA or CTRB in SPIN to do this?
Any example codes to set up the counters in SPIN or to start or pause the carrier would be most appreciated.
Thanks.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.fd.com.my
www.mercedes.com.my
Comments
Once you've been able to get a steady 38KHz output, you can modulate it by alternating the same pin (via OUTA) between 0 and 1. When 0, you will see the 38KHz output; when 1, a straight high. This is because the output from the counter is ORed with OUTA. This also implies that you will want to use current-sinking to drive your IRED: i.e. tie the anode high through a current-limiting resistor, and connect the cathode to the pin. This way, when the output is high, the IRED is off.
-Phil
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
'Just a few PropSTICK Kit bare PCBs left!
You guys are genius!
Why can't I set
frqa := 0 and
outa[noparse][[/noparse]pin] := 0
to pause (modulate) the 38Khz carrier? Too slow?
My circuit is already connected to a bipolar NPN transistor which sinks the current from the IRED to ground, so I can't have the
output pin high when idle.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.fd.com.my
www.mercedes.com.my
Post Edited (william chan) : 12/9/2008 6:15:22 AM GMT
You'd do FRQA~ followed by PHSA~ to stop the 38KHz carrier. You'll have to set them both to the proper values to start the carrier again. This would certainly be fast enough, a fraction of a cycle of the carrier.
-Phil
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
'Just a few PropSTICK Kit bare PCBs left!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·"I have always wished that my computer would be as easy to use as my telephone.· My wish has come true.· I no longer know how to use my telephone."
- Bjarne Stroustrup
-Phil
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
'Just a few PropSTICK Kit bare PCBs left!
But using 3.3v to power the IRED would heavily load the 100mA 3.3v regulator.
If we use a NPN transistor, the power source can be tapped from 3.3v, 5v or 12v supplies. More choices.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.fd.com.my
www.mercedes.com.my
You could use a separate 3.3V regulator for the IRED and still drive it with a PNP. Its forward voltage is only about 1.2V, so there's no necessity to sink it from a 5V or greater supply — as there would be for, say, a blue LED with a much higher forward voltage.
-Phil
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
'Just a few PropSTICK Kit bare PCBs left!
this is assuming clkfreq is 80 MHz