lab 4

Ran through the PWM code examples - no problems. Got my little LED to do the apple sleep thing, and then I played around a bit with changing some of the code numbers to get it to brighten and dim faster/slower/at different intervals/etc. Overall, a nice relaxing lab.

I also went ahead the servo lab, which was quite thrilling. First I used to code example just to set it go to from one end to another, which was rather exciting in and of itself. BUT THEN, I changed the code to take analogue input from a potentiometer to control the servo, and that was really exciting. Unfortunately, I didn't have my camera, so there aren't any pictures.

Here's the pic code:

DEFINE OSC 4

DEFINE ADC_BITS 10 ' Set number of bits in result DEFINE ADC_CLOCK 3 ' Set clock source (3=rc) DEFINE ADC_SAMPLEUS 50 ' Set sampling time in uS

sensorValue VAR WORD ' Create variable to store result

TRISA = %11111111 ' Set PORTA to all input ADCON1? = %10000010 ' Set PORTA analog and right justify result

output portc.3

start:

	pulseWidth var byte
	' set up constants with the minimum and maximum pulsewidths
	minPulse CON 50
	maxPulse CON 250
	' set up a constant with the time between pulses:
	refreshPeriod CON 20

	' set an initial pulsewidth:
	pulseWidth = minPulse

pulseRange var word pulseRange = maxPulse - minPulse

main:

    adcin 0, sensorValue

    'take the output pin low so we can pulse it high
	Low PORTC.3
	' pulse the pin
	PulsOut? PORTC.3, pulseWidth
	' pause for as long as needed:
	Pause refreshPeriod

    pulseWidth = minPulse + (pulseRange * (sensorValue/10)) / 100

GoTo? main


Page last modified March 30, 2006, at 10:10 PM