scottc
Joined: 16 Aug 2010 Posts: 95
|
Pic 18f2431 QEI and writing to the poscntl register |
Posted: Sat Mar 05, 2011 4:14 pm |
|
|
Hi, I am using the QEI module of the 18F2431 and have run into a
slight issue, Perhaps some of you can help.
Here is the problem. I write a value to the Poscntl register say 8
and then rotate my encoder wheel to update the value. All this works
fine. I then press my switch which increments a count. This in turn
takes me to another "Menu" but the previous value of 8 that is contained
in the poscntl register is still there but I don't want it to be I basically
need to write a different value to the poscntl register each time I press
a switch and then update this value by turning the encoder wheel.
My main loop calls the various functions based on pressing a switch
Code: |
Void Frequency_Config(void)
{
if (count==2){ //Press Switch
encoder_mhz(mhz); Local_Mhz =(mhz);
}
if (changed==true){
changed=false;
write_display(Mhz,khz);
}
//--------------------------------------------------------------------
if (count==3){ //Press Switch
encoder_Khz(khz); Local_khz =(khz);
}
if (changed==true){
changed=false;
write_display(Mhz,khz);
}
} |
Here are the functions.
Code: |
int encoder_mhz(int Local_Mhz)
{
changed=true; mhz=poscntl;
if (Mhz>10){
Mhz=10;
poscntl=10;
}
else
If (Mhz<1){
Mhz=1;
poscntl=1;
}
return(Local_Mhz);
}
/*---------------------------------------------------------------------------*/
int encoder_Khz(int Local_Khz)
{
changed=true;
Khz=poscntl;
if (khz>99){
Khz=0;
poscntl=0;
}
else
If (Khz>99){
Khz=99;
poscntl=99;
}
Return (local_Khz);
}
|
In the main loop I have tried various methods to try make the poscntl
value equal to the int of Mhz or khz I use as a starting value, but the
result is as I turn the encoder well nothing happens got to love that
eh.
The results of the above code look like this on a LCD.
Press the switch which allows me to update the Mhz value by turning
the rotary encoder. Rotate the encoder so the value displayed is say
5.
Press the switch again, this takes me to the Khz option. kHZ displays
5 which is expected since that is the last value contained within the
poscntl register and thats the crux of the problem. Each time I press
the switch I want to be able to set the poscntl register value to be equal
to the last value that was contained in either Mhz or Khz and then update
the respective values by turning the encoder wheel.
Its kind of like changing the frequency on your car radio.
Hope someone can help clear the fog
Thanks Scott |
|