View previous topic :: View next topic |
Author |
Message |
ccsfred
Joined: 15 Jun 2016 Posts: 33
|
QEI module only working in debug |
Posted: Wed Jul 06, 2016 4:23 am |
|
|
Hi,
I have a simple program to read the encoder value and print out every 250mS on a dspic33fj256mc710a:
Code: |
void readPosition()
{
int16 Value;
Value = qei_get_count( ); //Read the count
printf("Encoder position = %d \n\r",Value);
} |
Which works fine when debugging with PICKIT3, even if I unplug the debugger, but if I try to swap to programmer (PICKIT3), make and program the printf is printing on the UART, but the encoder value doesn't change.
I've made the analogue pins all digital by:
Code: |
#WORD AD1PCFGH = 0x032A
#WORD AD1PCFGL = 0x032C
AD1PCFGH=0xFF; // All digital
AD1PCFGL=0xFF; |
I don't have a separate configuration for debug & build, any ideas what seems to be stopping the QEI from working please?
Thanks |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9229 Location: Greensville,Ontario
|
|
Posted: Wed Jul 06, 2016 5:23 am |
|
|
don't use that PIC but...
When you compile did you change MPLAB Build Configuration to 'release' from 'debug'?
Did you remove ICD=True from the program ?
Does a 1Hz LED program work properly ?
Jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19518
|
|
Posted: Wed Jul 06, 2016 9:01 am |
|
|
He is on the right track. The debugger automatically configures the ADC registers. It's a known difference when switching between debug and run on these. Critical thing from the data sheet though:
"In devices with two ADC modules, if the
corresponding PCFG bit in either
AD1PCFGH(L) and AD2PCFGH(L) is
cleared, the pin is configured as an analog
input."
Note 'either'.
Also these are 16bit registers, so:
Code: |
#WORD AD1PCFGH = 0x032A
#WORD AD1PCFGL = 0x032C
#WORD AD2PCFGL = 0x36C
AD1PCFGH=0xFFFF; // All digital
AD1PCFGL=0xFFFF;
AD2PCFGL=0xFFFF;
|
Just use the CCS setup_adc_ports instruction. |
|
|
ccsfred
Joined: 15 Jun 2016 Posts: 33
|
|
Posted: Mon Jul 11, 2016 1:23 am |
|
|
Thanks, sorry for late reply, been off for a long weekend..
Jay,
Thanks! Yes ICD=TRUE removed and timing is correct.
Ttelmah,
Thank you, well spotted, that's fixed it.
I did try: setup_adc_ports(NO_ANALOGS); again, but QEI doesn't work, so kept with setting the registers!
I've got PCD V4.078
Thanks |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19518
|
|
Posted: Mon Jul 11, 2016 6:17 am |
|
|
Yes, there were problems with some of the commands on older copies of PCD like this, so 'glad it is working', and 'not surprised about the built in command', on that version. |
|
|
|