CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Pic 18f2431 QEI and writing to the poscntl register

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
scottc



Joined: 16 Aug 2010
Posts: 95

View user's profile Send private message

Pic 18f2431 QEI and writing to the poscntl register
PostPosted: Sat Mar 05, 2011 4:14 pm     Reply with quote

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 Smile 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 Smile 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 Smile

Thanks Scott
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group