Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Produce 2 square wave at the same time

Status
Not open for further replies.

nanoha

New Member
Hello,
I had a 8051 micro C test last week and it ask us to produce 2 square wave of different freq at the same time. (make it appear at oscilloscope)

I stuck when I need to create both of the wave simultaneously. Actually, I don't even know that we can do something simultaneously using micro C.

Even if I use interrupt (for the second wave), isn't the controller leave the main program and read the interrupt program? So I don't see that I can produce both of them simultaneously.

Any idea??? (Or maybe there is something wrong with my understanding. Hope you guys can help.)
 

breadboardguy

New Member
You could be using assembler and modify a peripheral port register in one instruction ( minus other register). It would work for a pic tough.
 

3v0

Coop Build Coordinator
Forum Supporter
Iff the processor does not have other work to do you can easily generate as many square waves as you need without timers or interrupts. This is not finished code but it illustrates the idea.

Code:
#define TIME0   1000
#define TIME1   500

#define BIT0     ??   // a port bit
#define BIT1     ??   // a port bit
unsigned int t0, t1;

t0=TIME0;
t1=TIME1;
// make BIT0 and BIT1 outputs
...
void main(void)
{
  while(1)
  {
    if (!(t0--))
    {
       toggle(BIT0);
       t0 = TIME0;
    }
    else
    {
      // waste time equal to above
    }
    if (!(t1--))
    {
       toggle(BIT1);
       t1 = TIME1;
    }
    else
    {
      // waste time equal to above
    }  
    // put some delay here if you want to slow things down
  }
}
 
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top