# An interview question

Status
Not open for further replies.

#### Eswara manikanta

##### New Member
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.

#### dknguyen

##### Well-Known Member
If it's for an interview you best do it yourself. This is even worse than asking someone to do your homework for you.

#### Eswara manikanta

##### New Member
If you KNOW please share your knowledge. Anyway thats a good suggestion

#### dknguyen

##### Well-Known Member
If you KNOW please share your knowledge. Anyway thats a good suggestion
No. This is for an interview. They expect you to do it yourself. They want to know what you know, not what we know.

#### Cicero

##### Active Member
If it's for an interview you best do it yourself. This is even worse than asking someone to do your homework for you.
This....

#### Eswara manikanta

##### New Member
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.

#### Spudboy488

##### Member
"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.

#### cowboybob

##### Well-Known Member
E, welcome to ETO!
... code in any programming language for generating square waveform...

...

#### Eswara manikanta

##### New Member
Managing is different from Teaching!

#### Eswara manikanta

##### New Member
boatload of suggestions are for individual generation/particular frequency. Im struck at generating more than 2 waveforms at a tme.

#### Nigel Goodwin

##### Super Moderator
boatload of suggestions are for individual generation/particular frequency. Im 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.

#### JonSea

##### Well-Known Member
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?

#### Spudboy488

##### Member
Managing is different from Teaching!
Well, I "managed" to answer the question so I won't bother teaching you how to do it.

#### dknguyen

##### Well-Known Member
boatload of suggestions are for individual generation/particular frequency. Im 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:

#### Eswara manikanta

##### New Member
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.!

#### Eswara manikanta

##### New Member
What? You don't get to "phone a friend" for help during an interview?
After few days of his interview he explained the whole situation. Didn't u seen d previous conversation?

#### Eswara manikanta

##### New Member
Well, I "managed" to answer the question so I won't bother teaching you how to do it.
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

#### Eswara manikanta

##### New Member
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!

#### Spudboy488

##### Member
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

.

Last edited:
Status
Not open for further replies.