Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Quadrature encoding sequence.

Status
Not open for further replies.

camerart

Well-Known Member
Hi,

Is there a sequence of quadrature encoding written in PIC BASIC please? I've been trying to get 18F2431 PICs to work with the QEI module inside the PIC, which coupled with the PWM module is causing a lot of frustration, as the Oshonsoft simulator does support them.

I'm considering starting again and leaving out the PWM module, and using a quadrature section instead.

Any help welcome.

Camerart.
 
I haven't really been following your project, I look in from time to time but Eric seems to have it covered...

Could you give a brief summary for me.... What are you trying to achieve???

Hi Ian,

I built a tracker and a circuit with 3x PICs. One for calculating and one each for Azimuth and Elevation that, at the moment, I want it to aim an antenna at a GPS NMEA signal. Indeed Eric, has been spending many hour helping, and has even set-up a similar rig at his establishment. He got good results, and at one time I did, but then I got intermittent results. Eric used quality encoders, but I sense that this isn't the problem as the problem starts before the motor has moved. I also think it isn't the circuit as I have separate test circuits.

The 18F2431 PIC has QUAD and PWM modules built in, but the Oshonsoft simulator doesn't support them, so I've been trying to find out where the problem is by testing, and it appears to be where the data (Calculated from another PIC) is received.

I think I can get by without the PWM part, and as a last resort would like to know if a PIC BASIC quadrature sequence within the existing program instead of the module could get round the problem.

Regards, Camerart.
 
I thought Oshonsoft did support PWM! Or is it a software implementation, like the rest of his modules...

You can achieve both by writing your own.... Writing a PWM hardware library is quite simple, I haven't read much about the QEI module... Probably because I use a small 8 pin pic to do all that bit for me...

I can give you a basic version of the quadrature encoder but it's a state machine and uses all the processor time!
 
I thought Oshonsoft did support PWM! Or is it a software implementation, like the rest of his modules...

You can achieve both by writing your own.... Writing a PWM hardware library is quite simple, I haven't read much about the QEI module... Probably because I use a small 8 pin pic to do all that bit for me...

I can give you a basic version of the quadrature encoder but it's a state machine and uses all the processor time!

Hi Ian,

Could I look at the QUAD basic code please. I'll leave the PWM till later.

Thanks, C.
 
My circuit
Code:
Define CONF_WORD = 0x31c4
Dim op As Byte  'current state
Dim lastop As Byte  'last state
TRISIO = 0x7  'one side inputs other outputs
CMCON = 7
ANSEL = 0  'no adc
WPU = 0x30
op = GPIO And 3  'for miscount on startup

main:
   lastop = ShiftLeft(op, 2)  'move state to last state position
   op = GPIO And 3  'read GPIO.0 and GPIO.1 only
   lastop = lastop + op  'add new  state
   Select Case lastop  'only 16 state combinations
     Case 1, 7, 8, 14  'seqence above
       Goto down
     Case 2, 4, 11, 13  'sequence above
       Goto up
     Case Else  'stopped or invalid
       Goto main  'do nothing
   EndSelect
down:  'set direction down
   GPIO.5 = 0
   WaitUs 100
   Goto clock
up:  'set direction up
   GPIO.5 = 1
   WaitUs 100
   Goto clock
clock:  'clock direction
   GPIO.4 = 1
   WaitUs 100
   GPIO.4 = 0
Goto main  'go again
End
My code
 

Attachments

  • upload_2015-11-29_19-40-58.png
    upload_2015-11-29_19-40-58.png
    4.7 KB · Views: 299
My circuit and code

Hi Ian,

Thanks for sending the program and circuit

I've tried it with 12F683 (I have some) in simulation and it's perfect for these little PICs. I'm going to try to add it into the larger 18F2431 PICs, I'm using.

Regarding Oshonsoft and 18F2431 PICs: Oshonsoft does support PWM, but these PICs are motor control PICs and have PWM and QUAD modules already inside them. Oshonsoft doesn't support these PIC modules.

C.
 
I've tried it with 12F683 (I have some) in simulation and it's perfect for these little PICs. I'm going to try to add it into the larger 18F2431 PICs, I'm using.
An Idea that was suggested on this forum, was to mount the pic12f675 on the encoder and just have the clock and direction into the larger chip..
 
An Idea that was suggested on this forum, was to mount the pic12f675 on the encoder and just have the clock and direction into the larger chip..

Hi Ian,

It does sound a good idea, and I will try it, if I can't get the program inside my PICs first.

Thanks, C.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top