View Full Version : 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
Oliver,
Take a look at Kevin's last year's beacon code (here (http://www.kevin.org/frc/2004/index.html)), 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! ;)
Mike Betts
05-03-2005, 20:42
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"freqout" is not a PBASIC command as far as I know...
ConKbot of Doom
06-03-2005, 00:18
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 microchip.com about programming it too.
"freqout" is not a PBASIC command as far as I know...
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 (http://www.parallax.com/dl/docs/prod/stamps/BasicStampMan.pdf), 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 :D ), 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 (http://www.kevin.org/frc/edu_led_pwm.zip) 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 ;) ) approves this code, otherwise, just test it! :p
(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
Setup_PWM_Output_Type(USER_CCP,IFI_PWM,IFI_PWM,IFI _PWM);
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? :]
"freqout" is not a PBASIC command as far as I know...
actually it is. and if you use the "boe-bot" from Radio shack it uses the freqout command.
-Mike
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. :D
I will try to do it monday and later I tell the results!
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. :D
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 (http://www.kevin.org/frc/pic18f8520_ds.pdf)
ConKbot of Doom
06-03-2005, 21:58
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 (http://www.kevin.org/frc/pic18f8520_ds.pdf)
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.
vBulletin® v3.6.4, Copyright ©2000-2017, Jelsoft Enterprises Ltd.