Continue to Site

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.

An interview question

Status
Not open for further replies.
Hii guys! Can you please help me in writing code in any programming language for generating square waveform at 4 different frequencies at 4 ports in any MC.
 
If it's for an interview you best do it yourself. This is even worse than asking someone to do your homework for you.
 
Dear! Actually my friend got rejected in Technical round due to this question. If interviewer would have been asked me the same question I can manage, but my friend explained the situation and asked me to do so. I can't say "do ur homework yourself" to my friend right! That's why I asked our group help as I'm bit weak in MC coding. So pls consider this.
 
"If interviewer would have been asked me the same question I can manage" leads me to believe that you should be the perfect person to TEACH your friend on how to do it.
 
boatload of suggestions are for individual generation/particular frequency. I`m struck at generating more than 2 waveforms at a tme.

You rather seem to be missing the point - the interview questions are to sort out unsuitable candidates, you're obviously not suitable for the position you're been interviewed for and your inability to answer the question shows that.
 
You rather seem to be missing the point - the interview questions are to sort out unsuitable candidates, you're obviously not suitable for the position you're been interviewed for and your inability to answer the question shows that.

What? You don't get to "phone a friend" for help during an interview?
 
boatload of suggestions are for individual generation/particular frequency. I`m struck at generating more than 2 waveforms at a tme.
This more specific type of question is the kind of thing that we are more willing to answer. If you cannot generate more than 2 waveforms at a time, it likely means that your approach is likely to be the wrong one (not useful in practice) One likely reason is because your approach is running in sequence with everything else in the processor which means this approach will not work in a real application where the processor has to be doing other things. But if you are getting these examples off the net, they cannot all be wrong so the other possibility is you don't understand their approach well enough to expand on it (which will be the case if you are just copying and pasting their code).

Using a hardware peripheral like a timer interrupt to generate the PWM is the most straightforward method. One for each PWM is best, but if you don't have enough, a single timer interrupt can be made to handle multiple signals shuffling in the appropriate interrupt value every time the interrupt fires. To know which interrupt value needs to trigger next, you need to examine all your signals. The interrupt routine also has to know the value that triggered it since it must behave differently for each value since each value is for a different signal.
 
Last edited:
This more specific type of question is the kind of thing that we are more willing to answer. If you cannot generate more than 2 waveforms at a time, it likely means that your approach is likely to be the wrong one (not useful in practice) One likely reason is because your approach is running in sequence with everything else in the processor which means this approach will not work in a real application where the processor has to be doing other things. But if you are getting these examples off the net, they cannot all be wrong so the other possibility is you don't understand their approach well enough to expand on it (which will be the case if you are just copying and pasting their code).

Using a hardware peripheral like a timer interrupt to generate the PWM is the most straightforward method. One for each PWM is best, but if you don't have enough, a single timer interrupt can be made to handle multiple signals shuffling in the appropriate interrupt value every time the interrupt fires. To know which interrupt value needs to trigger next, you need to examine all your signals. The interrupt routine also has to know the value that triggered it since it must behave differently for each value since each value is for a different signal.
Tq sir.!
 
You rather seem to be missing the point - the interview questions are to sort out unsuitable candidates, you're obviously not suitable for the position you're been interviewed for and your inability to answer the question shows that.
Dear! It's not d question for me. It's a question to my friend who failed to do that. He asked me and I too don't know. That's why I'm asking you all. That doesn't mean that I'm depending on you rather I would like to share knowledge. Mind!
 
Oooh nice! You also don't know. But difference is I'm trying to know what I don't know. But u r still managing

Since you said that if the interviewer asked you the same question, you could mange. Now you're trying to know. You also claim that I also don't know.

Here's how I would do it.

Most micros have a port that can be written to all at once. For this example, we'll call it PORTA and we'll assume it's at least 4-bits wide.

The program in a simple form.

Code:
for x=0 to 15
   PORTA = x
next x

The output of PORTA will be:

Code:
0000
0001
0010
0011
0100
0101
0110
0111
1000
1001
1010
1011
1100
1101
1110
1111

Output 0 changes every clock cycle
Output 1 changes every 2 clock cycles
Output 2 changes every 4 clock cycles
Output 3 changes every 8 clock cycles

4 pins. 4 different frequencies

.
ee18.GIF
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top