| View previous topic :: View next topic |
| Author |
Message |
languer
Joined: 09 Jan 2004 Posts: 144 Location: USA
|
|
Posted: Tue Apr 02, 2013 10:00 pm |
|
|
| Quote: | | better option would be to use a quadrature encoder |
great idea ... like use the right tool for the job
| Code: | | use the 1024 counts from a 10 bit ADC to create 1000 different frequencies |
I'll beg to differ on this. I will argue that this is entirely possible. With proper signal processing (read: dithering, oversampling, and averaging/decimating) this is within the realm. This is done quite frequently on sigma-delta ADCs (lookup ADI for examples; a simplified note from AVR here). However, having the same potentiometer position give you the same ADC value (i.e. the same frequency), now that is very unlikely.
All that said, a quadrature encoder, now that sounds like the right answer. |
|
 |
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Wed Apr 03, 2013 2:42 am |
|
|
OK. I was stretching a point. I suggested either fewer frequencies or more resolution.
I am aware that he could increase resolution by dithering etc. with his current PIC's 10bit ADC.
That still leaves the problem of how to deal with being on the edge.
Here's one way you could achieve moving the ADC input around by ~1count or 0.1%.
Does it without the complication of OPAs etc.
| Code: | 5V
|
>
> 4R7
>
4k7 |
-----WWWWW---------|
| |
| >
PWM --| 4k7 > <----to ADC input
| pot >
| |
-----WWWWW---------|
4k7 |
>
> 4R7
>
|
0V |
When PWM is low it pulls the upper end of the pot down by ~1 part per 1000.
And leaves lower end more or less as is.
When PWM is high it pulls the lower end of the pot up by ~1 part per 1000
And leaves upper end more or less as is.
Having said all that, we still don't really know exactly what he's trying to do.
I have to agree, encoder looks like a good idea.
Maybe just two buttons would do the job, one each for sharp & flat.
Mike |
|
 |
Ttelmah
Joined: 11 Mar 2010 Posts: 20161
|
|
Posted: Wed Apr 03, 2013 3:13 am |
|
|
and (of course), if you look at how some mice 'shut down' when not moved, you have a change in behaviour, where is if the movement is less than some figure for a few seconds, it stops returning new readings, and switches to sampling at a much lower frequency. Then requires quite a large movement to trigger the restart, with two readings (say) 1/4 second apart, differing by more than perhaps 20 counts, to switch back to 'full' operation, and start returning movements to the computer. Behaviour like this would then give the 'stable reading' required.
Best Wishes |
|
 |
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Wed Apr 03, 2013 5:48 am |
|
|
Could you go to a different method of setting a value such as:
0 to 20% - scan down in frequency quickly
21 to 40% - scan down slowly
41 - 60% - stay on current frequency
61 - 80% - scan up slowly
81 - 100% - scan up quickly _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
 |
notbad
Joined: 10 Jan 2013 Posts: 68
|
|
Posted: Thu Apr 04, 2013 1:03 am |
|
|
Thanks guys
The problem is solved. Here is the code that I wrote:
| Code: | int16 val;
int16 temp;
int32 AdcSum;
int8 n=0;
int8 LSByte;
void main()
{
setup_adc_ports(sAN0);
setup_adc(ADC_CLOCK_DIV_32);
set_adc_channel(0);
while(1)
{
delay_ms(1);
AdcSum+=read_adc();
if(++n==0)
{
LSByte=AdcSum;
temp= AdcSum>>8;
AdcSum=0;
int16 diff=abs((signed int16)val-temp);
if (diff>1){
printf("%Lu-%u\n\r", temp,LSByte );
val=temp;}
else if (diff==1){
if ((temp>val && LSByte>150) || (temp<val && LSByte<100) ) {
printf("%Lu-%u\n\r", temp,LSByte );
val=temp;}}
}//avg
}//while
}//main |
The problem was that after oversampling I "threw out" the extra bits. Now I use them to implement a threshold. If the major value is more than one count away it’s accepted. If it is -+1 then we look at the less significant bits. If they are far enough then the value is updated.
Thanks again for your attention |
|
 |
|