View previous topic :: View next topic |
Author |
Message |
diode_blade
Joined: 18 Aug 2014 Posts: 55 Location: Sheffield, South Yorkshire
|
DS33PIC QEI Module Interrupt (Solved) |
Posted: Wed May 17, 2023 5:39 am |
|
|
Compiler version PCWHD 5.105 and 5.107 (used both for testing)
IDE both PCWHD and MPLABX 6.05
Hardware used: DSPIC33ep512mu810 (mikroe Clicker2 board)
ICD-U80 & PICKIT 4
4 X 20 Char LCD 4 bit mode
1024 Quadrature endoer type Yumo E6B2-CWZ3E 1024 PPR
Problem: Interrupt is not firing.
I have read the Appropriate sections in the data sheet and the erata sheet and am still refering to them.
It is actually working I can see the count on the LCD going up and down, now I might be missing something totally Stupid, but i just can not get the interrupt to fire.
I am not using the INDX O/P of the encoder just the A & B O/P's into the clicker 2 board.
Test code below
Code: |
#include "33EP512MU810.h"
#device PASS_STRINGS=IN_RAM
#device ADC=10
#device *=16
#device PASS_STRINGS=IN_RAM
#FUSES HS,NOWDT,NOCKSNOFSM,NOJTAG,NOWRT,NOPROTECT,DEBUG
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#pin_select QEA1 = PIN_D1
#pin_select QEB1 = PIN_D2
#use delay(crystal=8Mhz,clock=32Mhz)
#include <Flex_LCD420.c>
#byte QEI1CON = getenv("SFR:QEI1CON")
#byte QEI1IOC = getenv("SFR:QEI1IOC")
#define debug_led PIN_A0
void init_pic(void)
{
#use FIXED_IO( A_outputs=PIN_A0 ) //clicker 2 led2
#use FIXED_IO( G_outputs=PIN_G9 ) // " led1
#use FIXED_IO(B_outputs=PIN_B9,PIN_B10,PIN_B11,PIN_B12,PIN_B13,PIN_B14,PIN_B15)
set_tris_d(0x0006);
setup_adc_ports(no_analogs);
}
int8 k; //debug for interupt
#INT_QEI
void QEI_TARGET(void)
{
k=1; //breakpoint
}
void main(void)
{
//int8 k;
static int32 setcount;
static unsigned int32 actcount;
static unsigned int32 pulscnt,qei_Stat;
delay_ms(500);
init_pic();
lcd_init();
setcount=4096;
k=0;
setup_qei(QEI_MODE_X4|QEI_FILTER_DIV_1|QEI_POS_GE_INT_ENABLED|QEI_MODULO_COUNT_MODE |QEI_OUTPUT_DISABLED|QEI_IDX_DOES_NOT_AFFECT_POSITION );
enable_interrupts(INT_QEI);
//enable_interrupts(GLOBAL);
enable_interrupts(GLOBAL);
clear_interrupt(INT_QEI);
qei_set_count(setcount);
while(1){
lcd_gotoxy(1,1);
printf(lcd_putc,"cnt is %08ld %u",pulscnt,k); //display live encoder count
actcount=qei_get_count();
pulscnt=actcount;//-setcount;
qei_stat=qei_status();
lcd_gotoxy(1,2);
printf(lcd_putc,"cnt is %08lx ",qei_stat); //display qei status
// output_high(debug_led);
// delay_ms(100);
// output_low(debug_led);
// delay_ms(100);
// k++;
}
}
|
Regards
Dave
Last edited by diode_blade on Thu May 25, 2023 7:52 am; edited 2 times in total |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9221 Location: Greensville,Ontario
|
|
Posted: Wed May 17, 2023 7:07 am |
|
|
I've never used that PIC or QE perhipheral ...
but....
do you have to 'setup' the peripheral ? Some 'register' (SFR) for 'counts', maybe direction ? and possibly enabling the peripheral to 'talk' to the PIC ??
since the encoder IS working, I suspect something 'simple'...
Jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19496
|
|
Posted: Wed May 17, 2023 7:18 am |
|
|
You are enabling the 'greater than or equal' interrupt, but I can't see you
putting a value into the QEI1GEC register.
I seem to remember that the compare does not work if the compare value
is zero (which is the default).
I think you should also disable HOME. You can PPS this to the Vss to
stop this being used.
Clear the interrupt before you enable it.
Second PASS_STRINGS not wanted
*=16 does nothing on a DSPic.
What does status tell you is happening?. Is bit 13 set (to say the comparison
has returned TRUE)?. Does it say the interrupt is enabled (bit 12)?. |
|
|
diode_blade
Joined: 18 Aug 2014 Posts: 55 Location: Sheffield, South Yorkshire
|
|
Posted: Wed May 17, 2023 7:58 am |
|
|
Ahhh, Thanks Temtronic and Ttlemah, will try that tomorrow and come back.
Will do some more reading this afternoon as well.
Regards.
Dave |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9221 Location: Greensville,Ontario
|
|
Posted: Thu May 18, 2023 5:20 am |
|
|
ok, real curious....
this option..
QEI_OUTPUT_DISABLED
NO info that I can see in the 2019 or 2121 CCS manual
actually very little info about all the 'options', sigh
Kinda wondering if it disables the bit that signals the QEI is creating an interrupt signal ? I know it doesn't disable reading the position data, OP can print that....so WHAT does it disable ?? |
|
|
diode_blade
Joined: 18 Aug 2014 Posts: 55 Location: Sheffield, South Yorkshire
|
|
Posted: Thu May 18, 2023 5:40 am |
|
|
temtronic wrote: | ok, real curious....
this option..
QEI_OUTPUT_DISABLED
NO info that I can see in the 2019 or 2121 CCS manual
actually very little info about all the 'options', sigh
Kinda wondering if it disables the bit that signals the QEI is creating an interrupt signal ? I know it doesn't disable reading the position data, OP can print that....so WHAT does it disable ?? |
You can assign an output pin through the PPS for CNTCMPx, I think I have a slight notion what might be going on now thanks to Ttelmah and yourself Temtronic, am about to investigate now.
When the set_qei_count(4096) in my code is carried out and I run the program, the 4096 count appears on the lcd display as the actual count even before I move the encoder.
I am just about to check the asm listing, I would have thought that in should place it in the QEIxGEC Reg's.
Onwards and upwards.
Cheers |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19496
|
|
Posted: Thu May 18, 2023 8:11 am |
|
|
No.
That sets the current encoder count to 4096, not the comparison value.
That is why you see it as the count.
I don't think there is a built in CCS function to set the comparison value
(or there wasn't when I was playing with this a few years ago). You just
have to make a #word pointing at the low byte, and write to this.
One thing I have to say, the QEI on this has a lot of 'oddities'. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9221 Location: Greensville,Ontario
|
|
Posted: Thu May 18, 2023 3:53 pm |
|
|
re: One thing I have to say, the QEI on this has a lot of 'oddities'.
and that's being NICE !!
I had a quik look at the QEI chapter....Yeesh the first PICs were far less complicated !
The only interrupt I could see was on the 'count compare'. If so, I'd set for a low number not 4096, for test purposes. Also be sure to reset 'k' in main.....otherwise it'll always be 1 forever..... |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19496
|
|
Posted: Fri May 19, 2023 12:36 am |
|
|
The module itself is not bad. Have used several others without problems,
though just like the MSSP, it is complex, because is does support so many
things. The oddities I was referring to are specific to the one on this chip.
It has a couple of quite major erratas, but also several other features that
don't work quite as implied/documented. There have been threads about it
here in the past.
There is an issue with the ADC configuration changing when you disable
debug:
[url]
https://www.ccsinfo.com/forum/viewtopic.php?t=55308&highlight=qei
[/url]
He doesn't post how his ADC is configured, so might be important to
look into this.
The rollover behaviour is rather odd:
[url]
https://www.ccsinfo.com/forum/viewtopic.php?t=50150&highlight=qei
[/url]
as well as the documented errata. |
|
|
diode_blade
Joined: 18 Aug 2014 Posts: 55 Location: Sheffield, South Yorkshire
|
|
Posted: Fri May 19, 2023 3:42 am |
|
|
Well I have the interrupt working thanks to the links posted, but I think I am going to look at a different chip, I think I have some of the 18fx431 series that have the simpler QEI unit that I have used before. Going to mess around with it over the weekend.
Thanks for the help everyone. Much appreciated. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19496
|
|
Posted: Fri May 19, 2023 4:10 am |
|
|
The funny thing is, that this was exactly my decision a couple of years ago!...
I switched to another PIC, which seemed to have a unit that worked
correctly. I switched to the much simpler 30F4012 and these worked
fine. Doesn't involve half the registers, and works well.
I did find some notes I made. I think you may find that what was happening
is that the compiler is clearing the interrupt flag, but not the event flag.
This has to be 'cleared by software'. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9221 Location: Greensville,Ontario
|
|
Posted: Fri May 19, 2023 4:59 am |
|
|
sigh, 2 decades ago I was using LSI/CSI ( USDIGITAL) QE chips to interface to 16F877s.While it added another chip to the PCB, they never ever failed to perform flawlessly. USD had some great, easy to use encoders, similar to the HP shaft style but a LOT simpler to install.
Have no idea what the cost is now, bet they're SMT nowadays...but might be an option ? |
|
|
diode_blade
Joined: 18 Aug 2014 Posts: 55 Location: Sheffield, South Yorkshire
|
Solved |
Posted: Thu May 25, 2023 7:51 am |
|
|
Right first thanks for help everyone.
Have gone back to using 18f4431, been testing on Mikroe Easypic V7 board.
Haa haaa laughs, at first the count was just going to 1 then back to zero when turning the encoder, spent two days going through setup code and previous code I used for this device years ago, still the same.
Then when I had looked at the V7 board links it had a link for Pin A4 that can be either in the VCAP position or as an input into the A4 pin on the PIC.
A few curses later.
Now doing what I want it to.
Thanks for the help. |
|
|
|