All About Circuits Forum  

Go Back   All About Circuits Forum > Software, Microcomputing, and Communications Forums > Embedded Systems and Microcontrollers

Notices

Embedded Systems and Microcontrollers Discussion forum for projects and working with embedded systems and microcontrollers (FPGAs, PICs, AVRs). Get help with hardware issues and embedded programming.

Reply   Post New Thread
 
Thread Tools Display Modes
  #1  
Old 10-28-2009, 06:56 PM
mantsali mantsali is offline
New Member
 
Join Date: Oct 2009
Posts: 7
Default how to calculate the frequency of a pulse train in 8051

how does one generate a 40khz pulse on the two pins of a 12mhz 8051 microcontroller in code. im using c but asm is welcome. even when using time delays, i wouldn't know how long a delay have to be to generate a desired frequency.
Reply With Quote
  #2  
Old 10-28-2009, 08:54 PM
Papabravo's Avatar
Papabravo Papabravo is offline
Senior Member
 
Join Date: Feb 2006
Location: Michigan, USA (GMT-5)
Posts: 5,521
Default

Quote:
Originally Posted by mantsali View Post
how does one generate a 40khz pulse on the two pins of a 12mhz 8051 microcontroller in code. im using c but asm is welcome. even when using time delays, i wouldn't know how long a delay have to be to generate a desired frequency.
If I tell you that the period of a waveform is the reciprocal of the frequency, would that be helpful to you. In this case:
Code:
1 / f (the frequency) = T(the period)
1 / 40,000 = 25 x 10^-6 or 25 microseconds
Select All
On an 8051 you could set a port pin to one, insert a few NOP instructions, set the port pin to 0, insert a few NOP instructions, and branch back to the beginning. The duty cycle would not be 50% since that would require a delay of 12.5 microseconds. So it might be high for 13 and low for 12, or high for 12 and low for 13, or any other combination you little heart desires.
__________________
We never have time to do it right,
But we always have time to do it over.
Reply With Quote
  #3  
Old 10-30-2009, 04:53 AM
Arm_n_Legs Arm_n_Legs is offline
Senior Member
 
Join Date: Mar 2007
Posts: 170
Default

Use the 8051 timer to perform the timing.

For 40KHz waveform means the signal alternate every 12.5 usec. Use the timer to time for 12.5 us. Oop... if running on 12 MHz, you can't get a resolution of 0.5 us.


TMOD = 0x01;
TR0 = 1;
TF0=0;
for(;{
TH1 = 0xff;
TL1 = 0xf3;
while(TF0==0);
P0 = ~P0;
TF0=0;
}
Reply With Quote
Reply   Post New Thread

Tags
, , , ,


Similar Threads
Thread Thread Starter Forum Replies Last Post
Implementing a frequency meter in the pulse generator nenadilic84 The Projects Forum 4 09-05-2009 08:39 PM
Detection of tone pulse train in noise znauzer The Projects Forum 7 08-24-2009 07:41 AM
sound card pulse generator with 2500 Hz carrier frequency alexv The Projects Forum 12 07-15-2009 06:17 PM
LED Pulse Frequency - Help Please! Rebecca Homework Help 6 02-08-2009 11:57 AM
Servo Motors Mazaag The Projects Forum 2 11-10-2006 07:18 AM

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 03:57 AM.


User-posted content, unless source quoted, is licensed under a Creative Commons Public Domain License.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.