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 CCS Technical Support

rotary encoder on glcd

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



Joined: 12 Jul 2015
Posts: 6

View user's profile Send private message

rotary encoder on glcd
PostPosted: Sun Jul 12, 2015 3:51 am     Reply with quote

Hi, I have done research on the web, but have not found anything concrete to speak of encoder connected to a display 128x64. can someone help me?

I have to count from 0 to 50 incrementally and 50 to 0 so decrease.
With LCD 16x2 or 16x4 everything works but with GLCD 128x64 I can not.

Thanks for any help

Gill
temtronic



Joined: 01 Jul 2010
Posts: 9241
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Jul 12, 2015 4:57 am     Reply with quote

Sounds like you need to break down your program as the encoder really has nothing to do with the GLCD.
Have you cut code to have the GLCD display a variable(say 'count') that you increment in a loop from 0 to 50 in a loop of say 1 Hz rate?
Show us that code, comment on what works or doesn't as well as mfr/make/model of the GLCD.
Also include compiler version.
Program will only be 20-30 lines of code(plus GLCD driver of course)

Jay
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Sun Jul 12, 2015 6:43 am     Reply with quote

Hi,

What is your CCS compiler version?

John
Ttelmah



Joined: 11 Mar 2010
Posts: 19536

View user's profile Send private message

PostPosted: Sun Jul 12, 2015 7:50 am     Reply with quote

You also need to tell us a lot more about your circuit?.

What GLCD driver are you using?. The CCS one?.
How is the encoder connected?.
Are you detecting this with interrupts?. B change?.
How many lines has the encoder?.
How fast can it turn?.
What processor?.
Processor speed?.

If you are using the CCS graphic driver, then this does not using interrupts for the graphic display, so provided you are using interrupts for the encoder, it should not make any difference. However I'd guess you are sending a lot more to the display than you did on the text screen, and this might introduce a particular fault, depending on your compiler version.

Generally, ou need to be aware that the problem with directly connected encoders, is that these _will_ generate quite high frequency interrupts. If you have anything else that needs to use interrupts, all the interrupt handlers _need_ (repeat _need_), to be written to be able to complete in less than the time between edges on the encoder, or the encoder needs to use high priority interrupts (on a chip which has hardware priority - so a PIC18 or better). If you are using interrupts then something you are doing is not meeting this requirement.

Honestly it is always far easier to use either a PIC that directly supports an encoder, or an external chip to decode this. _Guaranteeing_ that the PIC will not miss an edge, gets increasingly hard the more the chip is doing.

One possibility (which relates directly to the compiler version), is that you have one of the compiler versions that incorrectly disables interrupts in printf. This was a fault in some early V5 compilers (and some earlier V4 compilers).
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Sun Jul 12, 2015 8:45 am     Reply with quote

Hi,

This request has a distinct 'non-CCS' odor to it, hence my question Rolling Eyes I suspect they just parachuted in from Google. If they were really CCS users they would have already found the 'GLCD' and 'rotary encoder' threads here, as well as in the examples....

We'll see......

John
Ttelmah



Joined: 11 Mar 2010
Posts: 19536

View user's profile Send private message

PostPosted: Sun Jul 12, 2015 8:55 am     Reply with quote

Agreed. Temtronic had already asked what compiler version, but as you say, 'we will see'....
Gill



Joined: 12 Jul 2015
Posts: 6

View user's profile Send private message

PostPosted: Tue Jul 14, 2015 3:48 am     Reply with quote

Thank you for having responded to me in so many.
I apologize for my English translated.

Beginner and are self-taught, and I enclose listing. Thanks again.

CCS_PCWHD_v4.084
Code:

#include <18f452.h>
#device adc=10
#use delay(clock=4000000)
#fuses HS,NOLVP,NOWDT
#include <HDM64GS12.c>
#include <GRAPHICS.c>

#byte portb = 0x06
#byte portc = 0x07       

char uno[5];   

int16   X1=0,Q=0;
int8  Aux1=0;
int8  Enc1=0;
   
 void main() 
 { 
   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_CLOCK_DIV_2);
   setup_spi(SPI_SS_DISABLED);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   
   set_tris_a(0b000000);         
   set_tris_b(0b11111111);       
   set_tris_c(0b11111111);       
   
   glcd_init(ON);
   glcd_fillScreen(0);

   sprintf(uno,"%4ld", X1);
   glcd_text57(10,23,uno,3,on);
   
   glcd_text57(10,23,uno,3,off);   

   While (true)
   {
      Aux1 = Enc1;                               
      Enc1 = portb &192;                         
      Q=X1;                                     
      If ((Aux1 == 128) && (Enc1 == 192))    { X1++;}
      If ((Aux1 == 192) && (Enc1 == 128))    { X1--;}
      If (X1 == 65535) { X1=9999;}               
      If (bit_test(portc, 4) == 0)       { X1=0;}
      If (Q!=X1)         

      {
         sprintf(uno,"%4ld", X1);
         glcd_text57(10,23,uno,3,on);
         glcd_text57(10,23,uno,3,off);
      }
     
   }     
}
Ttelmah



Joined: 11 Mar 2010
Posts: 19536

View user's profile Send private message

PostPosted: Tue Jul 14, 2015 7:28 am     Reply with quote

The simple answer is you _need_ to be using interrupts to decode the encoder.

As it stands you encoder will not work if any part in the loop takes longer than one time between the edges. That it worked with the text LCD, was a fluke.
It looks as if this is a very low speed/edge count encoder, but still it must have priority over everything else. The easiest way to do this is to use interrupts.

As a comment, the setup_spi line is wrong. The _enables_ the SPI. The disable command is:

setup_spi(FALSE);
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Tue Jul 14, 2015 7:41 am     Reply with quote

Hi,

As Ttelmah has already mentioned, you really need to use interrupts if you have any hope of getting the rotary encoder to work in a reliable fashion.

But, more importantly, you need to learn proper code development, and troubleshooting! You are attempting to perform two rather 'advanced' tasks, the GLCD & the rotary encoder, simultaneously. That is a really poor strategy, as either, for a beginner, can be quite formidable....

My recommendations:

1. Attach a LED and a suitable current limiting resistor to an unused PIC I/O pin, and see if you can flash the LED at a predictable rate.

2. Reduce your code to only what is necessary to make the GLCD work. Write some simple text ('Hello World') to the GLCD to prove that it works!

3. Reduce your code to only what is necessary to make the rotary encoder work. Send data to the serial port of your PC to verify that the encoder is doing what you want it to do!

4. Combine the two programs into one working program that does both functions correctly.

If you want more specific help, you'll need to tell us the model of the GLCD, and of the rotary encoder. There are so many varieties of each that it's impossible to offer more than general comments without this information!

Also, do you *really* have hardware to test this on, or is this purely a simulation exercise?

Good Luck!

John
Gill



Joined: 12 Jul 2015
Posts: 6

View user's profile Send private message

PostPosted: Tue Jul 14, 2015 11:15 am     Reply with quote

Hi,
The display is used LGM12641BS1R
Encoder ADA377 of Adafruit
Pic 18F452.
Momentarily it simulates operation with PROTEUS, if everything were to work step to the realization of the hardware.

Thanks for your patience
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jul 14, 2015 12:54 pm     Reply with quote

Quote:
#include <18f452.h>
#device adc=10
#use delay(clock=4000000)
#fuses HS,NOLVP,NOWDT
#include <HDM64GS12.c>
#include <GRAPHICS.c>

#byte portb = 0x06
#byte portc = 0x07

While (true)
{
Aux1 = Enc1;
Enc1 = portb &192;
Q=X1;
If ((Aux1 == 128) && (Enc1 == 192)) { X1++;}
If ((Aux1 == 192) && (Enc1 == 128)) { X1--;}
If (X1 == 65535) { X1=9999;}
If (bit_test(portc, 4) == 0) { X1=0;}
If (Q!=X1)

The port addresses shown above in bold are not correct for the 18F452.
Read the PIC data sheet to see the correct addreses, or use the getenv()
function.
marcelomaggi



Joined: 14 Jul 2015
Posts: 3

View user's profile Send private message Visit poster's website

PostPosted: Tue Jul 14, 2015 3:11 pm     Reply with quote

Hi,
You may check a simple tutorial I created on using encoders with PIC and CCS C.
Please go to http://magusporta.com/tips/tips.html

I hope this may be of help.
_________________
Marcelo
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Tue Jul 14, 2015 3:44 pm     Reply with quote

Hello Marcelo,

That was a great first post here on the forums Very Happy !
_________________
John

If it's worth doing, it's worth doing in real hardware!
marcelomaggi



Joined: 14 Jul 2015
Posts: 3

View user's profile Send private message Visit poster's website

PostPosted: Wed Jul 15, 2015 3:04 pm     Reply with quote

Hi John,
I am glad you liked it. Very Happy
You are welcome to visit the site; I will keep updating it from time to time, mainly with ideas related to PIC and CCS C.
_________________
Marcelo
Gill



Joined: 12 Jul 2015
Posts: 6

View user's profile Send private message

PostPosted: Sat Jul 18, 2015 10:50 am     Reply with quote

hello
I apologize for being late to thank you, but only now after two days has begun to operate internet.

As cited "PCM programmer" I mistakenly set the port addresses in the wrong way, instead of the 18F452 I put sets of 16f877.

I thank everyone for their availability, see you soon

Gill
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