Brian Shewan Wins the CC Code Challenge (Week 27)

We have a winner of last week’s CC Weekly Code Challenge, sponsored by IAR Systems! We posted a code snippet with an error and challenged the engineering community to find the mistake!

Congratulations to Brian Shewan of Nova Scotia, Canadafor winning the CC Weekly Code Challenge for Week 27! Brian will receive Circuit Cellar 2011 and 2012 Archive CD.

Brian’s correct answer was randomly selected from the pool of responses that correctly identified an error in the code. Brian answered:

Line 22: Shift register won’t shift. Change to “ShiftReg_ClkB <= {ShiftReg_ClkB[1:0], clkA_Change}”

2013_code_challenge_27_answer

You can see the complete list of weekly winners and code challenges here.

What is the CC Weekly Code Challenge?
Each week, Circuit Cellar’s technical editors purposely insert an error in a snippet of code. It could be a semantic error, a syntax error, a design error, a spelling error, or another bug the editors slip in. You are challenged to find the error.Once the submission deadline passes, Circuit Cellar will randomly select one winner from the group of respondents who submit the correct answer.

Inspired? Want to try this week’s challenge? Get started!

Submission Deadline: The deadline for each week’s challenge is Sunday, 12 PM EST. Refer to the Rules, Terms & Conditions for information about eligibility and prizes.

Kang Usman Wins the CC Code Challenge (Week 26)

We have a winner of last week’s CC Weekly Code Challenge, sponsored by IAR Systems! We posted a code snippet with an error and challenged the engineering community to find the mistake!

Congratulations to Kang Usman of Jakarta, Indonesia for winning the CC Weekly Code Challenge for Week 26! Kang will receive an IAR Kickstart: KSK-FM3-48PMC-USB.

Kang’s correct answer was randomly selected from the pool of responses that correctly identified an error in the code. Kang answered:

Line 46: need [ and ]. it should be translate([0,0,2*ThreadThick])

2013_code_challenge_26_answer

You can see the complete list of weekly winners and code challenges here.

What is the CC Weekly Code Challenge?
Each week, Circuit Cellar’s technical editors purposely insert an error in a snippet of code. It could be a semantic error, a syntax error, a design error, a spelling error, or another bug the editors slip in. You are challenged to find the error.Once the submission deadline passes, Circuit Cellar will randomly select one winner from the group of respondents who submit the correct answer.

Inspired? Want to try this week’s challenge? Get started!

Submission Deadline: The deadline for each week’s challenge is Sunday, 12 PM EST. Refer to the Rules, Terms & Conditions for information about eligibility and prizes.

Guido Cargnino Wins the CC Code Challenge (Week 25)

We have a winner of last week’s CC Weekly Code Challenge, sponsored by IAR Systems! We posted a code snippet with an error and challenged the engineering community to find the mistake!

Congratulations to Guido Cargnino of Grugliasco, Turin, Italy  for winning the CC Weekly Code Challenge for Week 25! Guido will receive an Elektor 2012 & 2011 Archive DVD.

Guido’s correct answer was randomly selected from the pool of responses that correctly identified an error in the code. Guido answered:

Line #14: *p and *q must be used.

2013_code_challenge_25_answer

You can see the complete list of weekly winners and code challenges here.

What is the CC Weekly Code Challenge?
Each week, Circuit Cellar’s technical editors purposely insert an error in a snippet of code. It could be a semantic error, a syntax error, a design error, a spelling error, or another bug the editors slip in. You are challenged to find the error.Once the submission deadline passes, Circuit Cellar will randomly select one winner from the group of respondents who submit the correct answer.

Inspired? Want to try this week’s challenge? Get started!

Submission Deadline: The deadline for each week’s challenge is Sunday, 12 PM EST. Refer to the Rules, Terms & Conditions for information about eligibility and prizes.

John Safrit Wins the CC Code Challenge (Week 24)

We have a winner of last week’s CC Weekly Code Challenge, sponsored by IAR Systems! We posted a code snippet with an error and challenged the engineering community to find the mistake!

Congratulations to John Safrit of Mebane, North Carolina, United States  for winning the CC Weekly Code Challenge for Week 24! John will receive a CC T-shirt and a one-year subscription to Circuit Cellar.

John’s correct answer was randomly selected from the pool of responses that correctly identified an error in the code. John answered:

Line#22: need to terminate space string, add: space[d]=’';

2013_code_challenge_24_answer

You can see the complete list of weekly winners and code challenges here.

What is the CC Weekly Code Challenge?
Each week, Circuit Cellar’s technical editors purposely insert an error in a snippet of code. It could be a semantic error, a syntax error, a design error, a spelling error, or another bug the editors slip in. You are challenged to find the error.Once the submission deadline passes, Circuit Cellar will randomly select one winner from the group of respondents who submit the correct answer.

Inspired? Want to try this week’s challenge? Get started!

Submission Deadline: The deadline for each week’s challenge is Sunday, 12 PM EST. Refer to the Rules, Terms & Conditions for information about eligibility and prizes.

Issue 280: EQ Answers

PROBLEM 1
What is the key difference between the following two C functions?

#define VOLTS_FULL_SCALE 5.000
#define KPA_PER_VOLT 100.0
#define KPA_THRESHOLD 200.0

/* adc_reading is a value between 0 and 1
 */
bool test_pressure (float adc_reading)
{
  float voltage = adc_reading * VOLTS_FULL_SCALE;
  float pressure = voltage * KPA_PER_VOLT;

  return pressure > KPA_THRESHOLD;
}

bool test_pressure2 (float adc_reading)
{
  float voltage_threshold = KPA_THRESHOLD / KPA_PER_VOLT;
  float adc_threshold = voltage_threshold / VOLTS_FULL_SCALE;

  return adc_reading > adc_threshold;
}

ANSWER 1
The first function, test_pressure(), converts the ADC reading to engineering units before making the threshold comparison. This is a direct, obvious way to implement such a function.

The second function, test_pressure2(), converts the threshold value to an equivalent ADC reading, so that the two can be compared directly.

The key difference is in performance. The first function requires that arithmetic be done on each reading before making the comparison. However, the calculations in the second function can all be performed at compile time, which means that the only run-time operation is the comparison itself.

PROBLEM 2
How many NAND gates would it take to implement the following translation table? There are five inputs and eight outputs. You may consider an inverter to be a one-input NAND gate.

Inputs Outputs
A B C D E   F G H I J K L M
1 1 1 1 1 0 0 0 0 1 1 1 1
0 1 1 1 1 0 0 0 0 0 0 1 1
0 0 1 1 1 0 0 0 0 0 0 0 0
0 0 0 1 1 1 0 0 0 0 0 1 1
0 0 0 0 1 1 0 0 0 1 1 1 1

 

ANSWER 2
First of all, note that there are really only four inputs and three unique outputs for this function, since input E is always 1 and outputs GHI are always 0. The only real outputs are F, plus the groups JK and LM.

Since the other 27 input combinations haven’t been specified, we can take the output values associated with all of them as “don’t care.”

The output F is simply the inversion of input C.

The output JK is high only when A is high or D is low.

The output LM is high except when B is low and C is high.

Therefore, the entire function can be realized with a total of five gates:

eq0641_fig1

PROBLEM 3
Quick history quiz: Who were the three companies who collaborated to create the initial standard for the Ethernet LAN?

ANSWER 3
The original 10-Mbps Ethernet standard was jointly developed by Digital Equipment Corp. (DEC), Intel, and Xerox. It was released in November 1980, and was commonly referred to as “DIX Ethernet.”

PROBLEM 4
What was the name of the wireless network protocol on which Ethernet was based? Where was it developed?

ANSWER 4
The multiple access with collision detection protocol that Ethernet uses was based on a radio protocol developed at the University of Hawaii. It was known as the “ALOHA protocol.”