Kenmore 158: Normalized Pedal Position

Adjusting the output voltage vs. position for the sewing machine’s food pedal quickly revealed that the code shouldn’t depend on the actual ADC values. That’s blindingly obvious in hindsight, of course.

The maximum with the pedal in its overtravel region doesn’t change by much, because the Hall effect sensor output voltage saturates in a high magnetic field. I used a hardcoded word PedalMax = 870; which comes from 4.25 V at the ADC input.

On the low end, the sensor output can change by a few counts depending on small position changes, so I sampled the (presumably released) pedal output during the power-on reset:

	PedalMin = ReadAI(PIN_PEDAL);				// set minimum pedal input value
	printf("Set PedalMin: %u\r\n",PedalMin);
	PedalMaxClamp = 100;						// set upper speed limit

Given the complete ADC range, this function normalizes a value to the range [0,100], conveniently converting the pedal position into a percent of full scale:

int PedalPercent(word RawPos) {
int Clamped;

	Clamped = constrain(RawPos,PedalMin,PedalMax);
	return map(Clamped,PedalMin,PedalMax,0,100);

Graphing the normalized values against pedal position would have the same shape as the ADC values. All I’m doing is rescaling the Y axis to match the actual input limits.

The top of the main loop captures the pedal position:

PedalPosition = PedalPercent(PedalADC);

Now, it’s easy to add a slight deadband that ensures the sewing machine doesn’t start when you give the pedal a harsh look; the deadband is now a percent of full travel, rather than a hard-coded ADC count or voltage.

For example, in needle-follows-pedal mode, you must press the pedal by more than 10% to start the stitch, slightly release it to finish the stitch, and then almost completely release it to proceed to the next stitch:

	case PD_FOLLOW:
		if (PedalPosition > 10) {
			printf("Pedal Follow\r\n");
			do {
				PedalPosition = PedalPercent(ReadAI(PIN_PEDAL));
			} while (PedalPosition > 10);
			do {
				PedalPosition = PedalPercent(ReadAI(PIN_PEDAL));
			} while (PedalPosition > 2);

Adjusting percentages turns out to be much easier than fiddling with ADC values.

Obvious, huh?


, ,