CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

QEI module only working in debug

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
ccsfred



Joined: 15 Jun 2016
Posts: 33

View user's profile Send private message

QEI module only working in debug
PostPosted: Wed Jul 06, 2016 4:23 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Jul 06, 2016 5:23 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Jul 06, 2016 9:01 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Jul 11, 2016 1:23 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Jul 11, 2016 6:17 am     Reply with quote

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. Smile
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group