Quadrature Encoder 18F2331

For Formula Flowcode Micromouse users to discuss projects, flowcharts, and any other issues related to the Formula Flowcode Micromouse.

Moderator: Benj

Post Reply
KrisJeff
Flowcode v5 User
Posts: 25
Joined: Sun Feb 01, 2009 5:32 pm
Location: Albox, Almeria, Spain.
Has thanked: 4 times
Contact:

Quadrature Encoder 18F2331

Post by KrisJeff »

I have Flowcode 4, Development board 3 with up to date PPP. I cant run a sample program Encoder2 posted by sean on the 26th Feb 2008.
Sean surgested that the program was OK but configuration could be wrong. Despite hours of trying I still can't get it to run using flowcode.

However to veryfy the PIC18F2331 I still can't get the simplest program to run? Tried alternative 2331 no joy. No problem programming PIC16 devices?
I've never used 18F devices until now.

Anybody any ideas?

Kris Jeffery.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Quadrature Encoder 18F2331

Post by Benj »

Hello Kris

I would start out with a simple program that cannot go wrong. Eg a one second LED flasher. Then you can confirm if your configuration settings are all correct before you start on the bigger programs.

Here is an example of a config that is compatible with a 19.6608MHz crystal.
config1.JPG
config1.JPG (85.69 KiB) Viewed 12444 times
config2.JPG
config2.JPG (85.2 KiB) Viewed 12444 times

KrisJeff
Flowcode v5 User
Posts: 25
Joined: Sun Feb 01, 2009 5:32 pm
Location: Albox, Almeria, Spain.
Has thanked: 4 times
Contact:

Re: Quadrature Encoder 18F2331

Post by KrisJeff »

Dear Ben,

Thanks but no different. Simple program as stated. Programming fine until the end then "programming failed <1> <2> <3> <6>
Return code 0


This is pretty much where I was but I could manage just programming failed <1>, return code 0.

Kris.

User avatar
Steve
Matrix Staff
Posts: 3424
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times
Contact:

Re: Quadrature Encoder 18F2331

Post by Steve »

My copy of PPP seems to have 2 entries for the 2331 which appear to be the same on the face of it, but are different in the actual configuration files. If you have 2 entries, you could try running PPP stand-alone and manually selecting each of the 2331 entries in turn and sending the HEX file to the device. You may find that one works whereas the other one doesn't.

Please let me know how you get on.

KrisJeff
Flowcode v5 User
Posts: 25
Joined: Sun Feb 01, 2009 5:32 pm
Location: Albox, Almeria, Spain.
Has thanked: 4 times
Contact:

Re: Quadrature Encoder 18F2331

Post by KrisJeff »

Dear Steve,
Up dated this week end to Flowecode 4.2.3.58 with PPP 3.11.15.30. Everything the exact same?
I thought I would try the code to a 4331 as this was the basis of Seans original quaderature encoder.
Now it will compile to the chip but does not run properly. Even the LCD display does not work properly. This is what I get after downloading:

File name: C:\Users\Kris\Documents\Flowcode Project\Encoder Posisioning\PIC18F4331\Original Encoder2.c
Generated by: Flowcode v4.2.3.58
Date: Sunday, November 08, 2009 18:01:42
Licence: Professional
Registered to: Kris Jeffery


http://www.matrixmultimedia.com


Launching the compiler...
C:\Program Files\Matrix Multimedia\Flowcode V4\BoostC\boostc.pic18.flowcode.exe -v -t PIC18F4331 "Original Encoder2.c"
BoostC Optimizing C Compiler Version 6.95 (for PIC18 architecture)
http://www.sourceboost.com
Copyright(C) 2004-2009 Pavel Baranov
Copyright(C) 2004-2009 David Hobday

Licensed to FlowCode User under Single user Pro License for 1 node(s)
Limitations: PIC18 max code size:Unlimited, max RAM banks:Unlimited


Original Encoder2.c
Starting preprocessor: "C:\PROGRA~1\MATRIX~1\Flowcode V4\BoostC\pp.exe" "C:\Users\Kris\Documents\Flowcode Project\Encoder Posisioning\PIC18F4331\Original Encoder2.c" -i "C:\PROGRA~1\MATRIX~1\Flowcode V4\BoostC\include" -d _PIC18F4331 -la -c2 -o "C:\Users\Kris\Documents\Flowcode Project\Encoder Posisioning\PIC18F4331\Original Encoder2.pp" -v -d _BOOSTC -d _PIC18


..............

Original Encoder2.c success

success

Return code = 0

Launching the linker/assembler...
C:\Program Files\Matrix Multimedia\Flowcode V4\BoostC\boostlink.pic.exe -ld "C:\Program Files\Matrix Multimedia\Flowcode V4\BoostC\lib" libc.pic18.lib flowcode.pic18.lib rand.pic18.lib float.pic18.lib "Original Encoder2.obj" -t PIC18F4331 -d "C:\Users\Kris\Documents\Flowcode Project\Encoder Posisioning\PIC18F4331" -p "Original Encoder2"
BoostLink Optimizing Linker Version 6.95
http://www.sourceboost.com
Copyright(C) 2004-2009 Pavel Baranov
Copyright(C) 2004-2009 David Hobday


Caution: argument of 'delay_us' calls must have a value of 1 or more
Caution: Delay inaccurrate: 'delay_us', Delay overhead:0ms, Unit delay:0.00101725ms, Delay resolution:1 units
Caution: Delay inaccurrate: 'delay_10us', Delay overhead:0ms, Unit delay:0.0101725ms, Delay resolution:1 units
Caution: Delay inaccurrate: 'delay_ms', Delay overhead:0ms, Unit delay:1.00016ms, Delay resolution:1 units
Warning unreferenced functions removed:
FCI_FLOAT_TO_STRING in: C:\Program Files\Matrix Multimedia\Flowcode V4\FCD\internals.h
FCI_NUMBER_TO_HEX in: C:\Program Files\Matrix Multimedia\Flowcode V4\FCD\internals.h
FCI_STRING_TO_INT in: C:\Program Files\Matrix Multimedia\Flowcode V4\FCD\internals.h
FCI_STRING_TO_FLOAT in: C:\Program Files\Matrix Multimedia\Flowcode V4\FCD\internals.h
Wdt_Delay_S in: C:\Program Files\Matrix Multimedia\Flowcode V4\FCD\internals.h
isinf in: C:\Program Files\Matrix Multimedia\Flowcode V4\FCD\internals.h
FCD_LCDDisplay0_PrintASCII in: C:\Users\Kris\Documents\Flowcode Project\Encoder Posisioning\PIC18F4331\Original Encoder2.c
FCD_LCDDisplay0_Command in: C:\Users\Kris\Documents\Flowcode Project\Encoder Posisioning\PIC18F4331\Original Encoder2.c
FCD_LCDDisplay0_Cursor in: C:\Users\Kris\Documents\Flowcode Project\Encoder Posisioning\PIC18F4331\Original Encoder2.c
FCD_LCDDisplay0_PrintString in: C:\Users\Kris\Documents\Flowcode Project\Encoder Posisioning\PIC18F4331\Original Encoder2.c
FCD_LCDDisplay0_ScrollDisplay in: C:\Users\Kris\Documents\Flowcode Project\Encoder Posisioning\PIC18F4331\Original Encoder2.c
FCD_LCDDisplay0_ClearLine in: C:\Users\Kris\Documents\Flowcode Project\Encoder Posisioning\PIC18F4331\Original Encoder2.c
FCD_LCDDisplay0_RAM_Write in: C:\Users\Kris\Documents\Flowcode Project\Encoder Posisioning\PIC18F4331\Original Encoder2.c

Building CASM file
Memory Usage Report
===================
RAM available:768 bytes, used:61 bytes (8.0%), free:707 bytes (92.0%),
Heap size:707 bytes, Heap max single alloc:127 bytes
ROM available:8192 bytes, used:1300 bytes (15.9%), free:6892 bytes (84.1%)



success

Return code = 0

Launching the programmer...
C:\Program Files\Matrix Multimedia\Flowcode V4\tools\PPP\PPPv3.exe -cs 2 -chip PIC18F4331 -nogui "Original Encoder2.hex"
Sending program...
Erasing the PICmicro
NOTE: EEPROM data will also be erased!
Writing program memory
Writing configuration memory
Writing id-locations
Reading program memory
Reading configuration memory
Finished reading PICmicro contents
Program sent and verified OK

652 out of 8192 program bytes used
0 out of 256 data bytes used
That took 4.609 seconds

Return code = 0

FINISHED

Any ideas?

Kris.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Quadrature Encoder 18F2331

Post by Benj »

Hello Kris

My guess is that the problem is based on your configuration settings. What settings are you using in the chip -> configure -> Expert settings menu?

Eg
HS+PLL is 4x your crystal speed for a maximum clock speed of 40MHz. Eg 4 x 10MHz crystal.
HS is your crystal speed eg 19.6608MHz crystal

The clock speed in the Project options menu of Flowcode must match this speed to allow delays and components such as the LCD to work correctly.

KrisJeff
Flowcode v5 User
Posts: 25
Joined: Sun Feb 01, 2009 5:32 pm
Location: Albox, Almeria, Spain.
Has thanked: 4 times
Contact:

Re: Quadrature Encoder 18F2331

Post by KrisJeff »

Ben,

All settings as per your earlier reply regarding PIC18F2331 with clock of 19.6608MHz ?

Kris

KrisJeff
Flowcode v5 User
Posts: 25
Joined: Sun Feb 01, 2009 5:32 pm
Location: Albox, Almeria, Spain.
Has thanked: 4 times
Contact:

Re: Quadrature Encoder 18F2331

Post by KrisJeff »

Changed 2331 to 18F4331 with better results. I have this running in my version 3 programmer/simulator. It will count up and down but well out of sync with the QEA and QEB inputs from the encoder. Also the INDEX input
has not effect on the count. The count I get is very slow and somewhat unstable as it will count up a couple of digits to count back one or two?
I am not farmiliar with C code at all (that's why I choose Flowcode as a means of programming) so I'm well in the dark regarding the C code blocks.
My first quad encoder had 200 pulses per rev. This gives me approx one pulse per mm with a 65mm dia pulley. This is exactly just what I require. I thought that this low count of 200 could be a problem (not configured for this), however,
I changed the encoder to 1000 pulses per rev with no difference at all? It's as though the actual count is diveded by thousands and as stated is quite unstable. I'm sure I'm pretty close and I've tried altering the (POSCNT <<8) + POSCNTL but to be
honest I'm not sure of what I'm doing plus whatever I change it to has little effect on the speed of the count?
I'm only using inputs INDX, QEA and QEB.
I'm trying to get position over say 30M for a lift position system @ + or - 1mm. The other thing is the Maxcount of 5000. I thought the counter was OK up to 32767, this would of course give me 32.767 metres in my lift shaft which is roghly some
10 floors or so.

I have an alternative using a 16F877A counting on the RBO/INT pin, however, I would prefer to use a purpose built chip if poss. I just need to undersand this a bit better?
Can anyone help?

Kris Jeffery.

Post Reply