Using incremental encoder to generate 0-359 Degrees Oshonsoft (NOTE: QEI SIM NOT SUPPORTED)

Thread Starter

camerart

Joined Feb 25, 2013
3,724
Hi,
I need a PIC input of 0 to 359Degrees from an optical encoder QEI.

I have programs that run in the Oshonsoft Simulator, but as the QEI of the PIC is not supported, they need an in program test count,
Here is a program, which includes it's own counting:
In the SIM use the Hardware UART and enter e,g, A359E359

I'm pretty sure it will work 'live' using the QEI of the PIC, but need those parts removing from the program, but as I can't simulate it, I'm a bit stuck.

Any help welcome.
Camerart
 

Attachments

Last edited:

Thread Starter

camerart

Joined Feb 25, 2013
3,724
hi C,
I don't follow, which section do you want to remove.?
E
Morning E,
The program in #1 works in the SIM.
I want to use part of it between an incremental encoder and a PIC to give 0-359 degrees for a compass. I don't think it is set up for that, or is it?
I'm just making the PCB for it.
C.
 

ericgibbs

Joined Jan 29, 2010
18,766
hi C,
Is the Compass output I2C or serial.?
If you want to emulate a Compass, write a program for a 18F2431 that outputs compass test data, on demand
The programmed 18F2431 produces a compass test msg, you can also add user controls to the program, that can be used to call up different msgs.

E
 

Thread Starter

camerart

Joined Feb 25, 2013
3,724
hi C,
Is the Compass output I2C or serial.?
If you want to emulate a Compass, write a program for a 18F2431 that outputs compass test data, on demand
The programmed 18F2431 produces a compass test msg, you can also add user controls to the program, that can be used to call up different msgs.

E
Hi E,
I use SPI.
This is a channel on a Transmitter where an incremental rotary optical encode QEI will send 0-359 to the REMOTE.
I assumed that the program I posted in #1 could be modified. Is this correct?
C.
 

ericgibbs

Joined Jan 29, 2010
18,766
hi,
In the past, I had to emulate many different types of Surveying equipment in order to test my data acquisition and chart plotting programs, prior to in field testing.
If you know the format and rate of the data output of the unit want to emulate, write the program using the Oshonsoft IDE, debug and then program any type of PIC that has the data type output option.
Add the extra the user controls, so that you can manipulate the output data.

You could modify post #1 program to emulate a Compass or any of your hardware units, build a library of preprogrammed PIC's,
E
 

Thread Starter

camerart

Joined Feb 25, 2013
3,724
hi,
In the past, I had to emulate many different types of Surveying equipment in order to test my data acquisition and chart plotting programs, prior to in field testing.
If you know the format and rate of the data output of the unit want to emulate, write the program using the Oshonsoft IDE, debug and then program any type of PIC that has the data type output option.
Add the extra the user controls, so that you can manipulate the output data.

You could modify post #1 program to emulate a Compass or any of your hardware units, build a library of preprogrammed PIC's,
E
Hi E,
This isn't for emulation, it will be an actual channel on the transmitter.

EDIT: Using the #1 program, is it set up for QEI counting? If I remove the gosub COUNT and the READ AZIM sections, will it count using QEI?

C.
 
Last edited:

ericgibbs

Joined Jan 29, 2010
18,766
hi C,
This is clip from that program.
Are the Gosubs you have marked with '''''''''' the ones you want to delete.?
E

Update:
You posted: Oshonsoft Simulator, but as the QEI of the PIC is not supported,


If I recall correctly the QEI is supported by Oshonsoft, I posted you some programs back in 2015, using the QEI.

E

get_cnt:

If poscnt = azimval Then
PIR3.IC2QEIF = 1 'raise Intr
Goto clr_azim
Endif

If poscnt < azimval Then
If azimval - poscnt >= 1800 Then
''''''''''''''''Gosub dwncnt
Else
'''''''''''''''Gosub upcnt
Endif
Endif

If poscnt > azimval Then '270 > 90
If poscnt - azimval >= 1800 Then
''''''''''''''''Gosub upcnt
Else
''''''''''''''''Gosub dwncnt
Endif
Endif

Goto get_cnt
 
Last edited:

Thread Starter

camerart

Joined Feb 25, 2013
3,724
hi C,
This is clip from that program.
Are the Gosubs you have marked with '''''''''' the ones you want to delete.?
E

Update:
You posted: Oshonsoft Simulator, but as the QEI of the PIC is not supported,


If I recall correctly the QEI is supported by Oshonsoft, I posted you some programs back in 2015, using the QEI.

E

get_cnt:

If poscnt = azimval Then
PIR3.IC2QEIF = 1 'raise Intr
Goto clr_azim
Endif

If poscnt < azimval Then
If azimval - poscnt >= 1800 Then
''''''''''''''''Gosub dwncnt
Else
'''''''''''''''Gosub upcnt
Endif
Endif

If poscnt > azimval Then '270 > 90
If poscnt - azimval >= 1800 Then
''''''''''''''''Gosub upcnt
Else
''''''''''''''''Gosub dwncnt
Endif
Endif

Goto get_cnt
Hi E,
I searched both here and ETO around 2015, the programs you posted, were similar to the one in #1 where you have added either a counter within the program, or click PINs in the SIM, for counting.

In: https://forum.allaboutcircuits.com/threads/gps-nmea-antenna-aiming-tracker.447/page-23#post-761073
#447 you made a comment about QEI and Vladimir, so I doubt the SIM will work with QEI.
Also in that thread, there are working TRACKER programs where the LIVE QEI is counting fine, but they are quite long and involved.

I'll see if I can strip one of the TRACKER programs, to only leave the QEI counting section (If I can??)
C.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,724
hi,
It runs for me, it expects you to enter the A123E123 at the UART.
Receives the serial data and drives the PWM and Indexing.
What do you expect the program to do.?
E
hi,
It runs for me, it expects you to enter the A123E123 at the UART.
Receives the serial data and drives the PWM and Indexing.
What do you expect the program to do.?
E
Hi E,
The A123E123 also runs for me, but you wrote ASM code for the motor drive section, and I'm sure the QEI INPUT is similar that the program won't run by switching the QEA and QEB PINs. ( I recall you contacted Vlad)
I now have a PCB that I can test LIVE tomorrow. I'll let you know what happens
Thanks,
C.
 

ericgibbs

Joined Jan 29, 2010
18,766
hi,
I agree, I guess you are wanting to switch the input QEA and QEB pins, by clicking on them on the PIC view image.??.?
As you recall that does not work in the IDE, Vlad never came back.
I am sure that we devised a work around for that bug.?? using CAP1,2,3
E
 

Attachments

Thread Starter

camerart

Joined Feb 25, 2013
3,724
hi,
I agree, I guess you are wanting to switch the input QEA and QEB pins, by clicking on them on the PIC view image.??.?
As you recall that does not work in the IDE, Vlad never came back.
I am sure that we devised a work around for that bug.?? using CAP1,2,3
E
Hi E,
CAP1,2,3 doesn't ring a bell with me, I think I just tried LIVE tests.
I'll let you know tomorrow.
C.
 

ericgibbs

Joined Jan 29, 2010
18,766
hi C,
To get the posxcnt 16bit counter to count up or down the QEA and QEB must follow this pattern in order for the PIC logic to decode the count direction.
AA1 16-Jan-19 19.12.gif
 

ericgibbs

Joined Jan 29, 2010
18,766
hi C,
Written you a short test program, uses 18F2431. Use the IDE PIC view to set/reset the input bits on PORTA

The pos2cnt 16 bit counter in the QEx section can be inc or dec around 000.0 degrees, PORTA.3 or PORTA.4
Test range is 3550 > 3559 and 10 > 0 about the Index value of 3559/0, The Index stop can be released with PORTA,2 click

Outputs the count on the serial port.

Test the program and copy/paste the routines into your main program.

E
 

Attachments

Last edited:

Thread Starter

camerart

Joined Feb 25, 2013
3,724
hi C,
Written you a short test program, uses 18F2431. Use the IDE PIC view to set/reset the input bits on PORTA

The pos2cnt 16 bit counter in the QEx section can be inc or dec around 000.0 degrees, PORTA.3 or PORTA.4
Test range is 3550 > 3559 and 10 > 0 about the Index value of 3559/0, The Index stop can be released with PORTA,2 click

Outputs the count on the serial port.

Test the program and copy/paste the routines into your main program.

E
Hi E,
Many thanks for the program.
Would it be a big problem for me to switch to 18F4431 PICs?
Reason: I've been playing with veroboard and 18F2431 all day, but can't get it working. (I use off board programming with it, and it's a pain) I ordered a load of 18F4431, and will eventually use them on my PCBs.
If it's a problem, I'll keep trying the 18F2431.
C.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,724
hi,
The 18F4431 will be OK.
E

BTW:
Do you recall this PIC based Quad signal generator.?
https://forum.allaboutcircuits.com/...-gen-2-phase-non-overlapping-clock.654/unread
Hi E,

Hi E,
Your signal generator rings a bell and I think I made one. Although I hope you realise, that I don't want to generate signals, but use an incremental encoder attached to the QEI INPUT PINs to generate the quadrature.

More success with the 18F4431:) I now have a test one, with QEA and QEB INPUT test buttons working, and it is connected to the MAIN 18LF4620 via SPI, also a TX, so I should be able to test any programs ok. (Both with 'in circuit' programming, much better tan today's earlier efforts)
I see you have an INDEX button, but I think we didn't use that method with the TRACKER, as if I recall correctly used QEA and QEB only which counted to 3599. If you want me to post a TRACKER program, let me know.

Thanks C.
 
Last edited:
Top