How would you use the ADCIN command to read the value of a pot while simultaneously doing something else?
How would you use the ADCIN command to read the value of a pot while simultaneously doing something else?
Setup a hardware peripheral like capture, hardware PWM, counter, UART, etc and enable
it. They will all run simultaneously in the background while you're sampling the A/D input.
Hello. I am using the instant interrupt routine. I also posess a servo motor like ted,
so I wand to start a pulsout every 20ms. I did this in the tmr0-interrupt routine(tmr0
initialized by OPTION_REG = 1) I am using a 20Mhz quarz.
I think: 20 / 4 = 5Mhz. OPTION_REG means prescaler = 1:1. Means 1/(5,000,000) equals 0.2us.
TMR0 = 8Bit => 256 * 0.2us = 51.2us.
So every 51.2us there will be an interrupt. So
20,000 / 51.2 = 390.625 = 391. So as soon as the interrupt will have occurred 391 times 20ms
should have been passed. I wrote
But the servo is choppy. What is wrong?Code:main: '...do xyz counter = 0 END IRRoutine: IF counter = 391 THEN pulsout servo, duration ENDIF IF counter > 391 THEN counter = 0 ENDIF IF counter < 391 THEN counter = counter + 1 ENDIF @ INT_RETURN
Last edited by Security; - 2nd September 2008 at 05:29.
How does this work?
Code:main: '...do xyz counter = 0 END IRRoutine: IF counter => 391 THEN pulsout servo, duration counter = 0 ELSE counter = counter + 1 ENDIF @ INT_RETURN
Well.
But the servo is still choppy.
I found the reason: Option_reg was wrong. I had a prescaler of 2:1.
Last edited by Security; - 2nd September 2008 at 07:00.
Bookmarks