digital output frequency

Hello everyone!

Is there any command in C language equivalent to freqout in Pbasic language, or a way to do a digital output oscillate in a 38500 frequency?

Thanks in advance


Take a look at Kevin’s last year’s beacon code (here), you can modify the EDU-RC code to do what you want. The code has lots of comments and should help you. Any questions, ask! :wink:

“freqout” is not a PBASIC command as far as I know…

You can use the CCP module on the PICs to get a signal on pwms 13-16 there is an example of that in the code I believe. If not its in one of the programming .pdf’s somwhere. Not 100% sure all what you need to do, but check out some of the programming guides and datasheets on about programming it too.

As a matter of fact, it is, we just didn’t use it to program the robots in the PBasic era (2000-2003). This, and many other commands that weren’t used can be found in the Basic Stamp Manual, from Parallax. Oliver probably used freqout with the BOEBots, some really nifty mini-robots that we also use at our school to teach robotics.

Oliver, I was kind of in a hurry (watching two webcasts at the same time :smiley: ), so here’s a bit of clarification from my previous post:
If you don’t need to send those pulses at a precise rate, as the beacon code did last year, you can probably just use Kevin’s LED Dimmer code to generate PWM signals. Using that file and the PIC18F8520 data sheet (pages 143-144 and 156-157) you can select the frequency you want.
As a matter of fact, I believe the following code (copy’n’paste inside the User_Initialization function in your user_routines.c file) will generate you a nice 38.46 KHz PWM with a 50% duty cycle. I don’t have an RC or EDU in front of me right now to test it; if your application involves human safety, wait till someone more knowledgeable (yes, Kevin Watson :wink: ) approves this code, otherwise, just test it! :stuck_out_tongue:
(be aware that using IFI’s PWM will 'cause you trouble if using interrupt intensive code, especially Kevin’s gyro code - both use Timer2)

         PR2 = 0x40;                 // sets 38461 Hz freq.
         CCPR2L = 0x20;             // sets 50% duty cicle
         T2CONbits.T2CKPS0 = 1;    // sets 1:4 prescale
	 T2CONbits.T2CKPS1 = 0;   // same as above
         T2CONbits.TMR2ON = 1;   // starts timer 2


Also, don’t forget calling Generate_Pwms(pwm13,pwm14,pwm15,pwm16); to generate the above signal in the PWM 13 output. [EDITED - This step is unnecessary, wrong and will probably give you an error. Disregard it!]

[EDIT] Why not just use last year’s IR receivers (am I wrong assuming you want that particular 38500 Hz frequency for that? :)), rated at 40 KHz, and use the code that’s already available from a much much more reliable source? :]

actually it is. and if you use the “boe-bot” from Radio shack it uses the freqout command.


EDIT: ok, i didn’t read ahead, it was already said, but the boe bots were a neat little device.

Thanks Manoel and Jonathan, I looked the codes with attention and I belive that using signal on pwms 13-16 it will works. Only a question, What does CCP mean?

Yes Manoel, you are right, I want do the same that we do with BOEBots, use IR sensor to detect objects. Don’t worry my applications don’t involves human safety. :smiley:

I will try to do it monday and later I tell the results!

CCP stands for Capture/Compare/PWM. Again, the data sheet for the PIC is a very useful resource for more advanced programming. Download it here

Unfortunately for us though, the PWM outputs are outputs only so we cant use the capture or compare functions :-/ Might be handy for encoders, but oh well, we’ll work with what we have.