All About Circuits Forum how to calculate the frequency of a pulse train in 8051
 Register Blogs FAQ Members List Today's Posts Search Today's Posts Mark Forums Read

 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.

#1
10-28-2009, 06:56 PM
 mantsali New Member Join Date: Oct 2009 Posts: 7
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.
#2
10-28-2009, 08:54 PM
 Papabravo Senior Member Join Date: Feb 2006 Location: Michigan, USA (GMT-5) Posts: 5,843

Quote:
 Originally Posted by mantsali 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.
#3
10-30-2009, 04:53 AM
 Arm_n_Legs Senior Member Join Date: Mar 2007 Location: Singapore Posts: 181

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;
}

 Tags 8051, calculate, frequency, pulse, train

 Similar Threads Thread Thread Starter Forum Replies Last Post nenadilic84 The Projects Forum 4 09-05-2009 08:39 PM znauzer The Projects Forum 7 08-24-2009 07:41 AM alexv The Projects Forum 12 07-15-2009 06:17 PM Rebecca Homework Help 6 02-08-2009 11:57 AM Mazaag The Projects Forum 2 11-10-2006 07:18 AM

 Thread Tools Display Modes Linear Mode

 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 Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home Electronics Forums     General Electronics Chat     The Projects Forum     Homework Help     Electronics Resources Software, Microcomputing, and Communications Forums     Programmer's Corner     Embedded Systems and Microcontrollers     Computing and Networks     Radio and Communications Circuits and Projects     The Completed Projects Collection Abstract Forums     Math     Physics     General Science All About Circuits Commmunity Forums     Off-Topic     The Flea Market     Feedback and Suggestions

All times are GMT. The time now is 08:00 PM.