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

PIC24 MPLAB_X failure to write SFR registers

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



Joined: 18 Feb 2007
Posts: 22
Location: TN, USA

View user's profile Send private message

PIC24 MPLAB_X failure to write SFR registers
PostPosted: Wed Jul 18, 2012 5:42 pm     Reply with quote

The 12 bit A/D did not work with PCD v4.135 so I tried to setup by writing directly to the registers.

MPLAB_X v1.3 shows all zeros in the SFR register window for the A/D registers that I tried to write to. The program compiles, loads and runs.

I snipped the code to just show how I am attempting to write to the A/D registers.

PIC24FV32KA302
PCD v 4.135
MPLAB_X v 1.3
Code:

#include "C:\Users\MicKent\MPLABXProjects\SB_Control_04.X\SB_ControlH_04.h"
#include <ctype.h>
#include <math.h>
#zero_ram

//Oscillator setup registers ................................................//

#word OSCCON = 0x0742         //Oscillator control register
#word CLKDIV = 0x0744         //Oscillator clock control

//A to D converter setup registers ..........................................//

#word AD1CON1 = 0x0340            //A D Control Register 1
#word AD1CON2 = 0x0342            //A D Control Register 2
#word AD1CON3 = 0x0344            //A D Control Register 3
#word AD1CHS  = 0x0348            //A D Sample Select Register
#word AD1CSSH = 0x034E            //A D Input Scan Select Register
#word AD1CSSL = 0x0350            //A D Input Scan Select Register
#word AD1CON5 = 0x0354            //A D Control Register 5
#word AD1CHITH = 0x0356           //A D Scan Compare Hit Register
#word AD1CHITL = 0x0358           //A D Scan Compare Hit Register
#word AD1CTMENH = 0x0360          //CTMU Enable Register
#word AD1CTMENL = 0x0362          //CTMU Enable Register

//Function Prototypes .......................................................//

//void TempSen94022(void);

//LCD Routines .......PCMprogrammer .........................................//

//  snip


void main()
{
   setup_spi( FALSE );
   setup_spi2( FALSE );

   setup_adc_ports(sAN0 | sAN1);
   //setup_adc(ADC_CLOCK_INTERNAL | ADC_TAD_MUL_16);

   AD1CON1=0x8470;
   AD1CON2=0xD000;
   AD1CON3=0x1004;
   AD1CON5=0x1008;

  // setup_timer1(TMR_DISABLED);



   lcd_init();
   delay_ms(1000);


 do
   {
    int8 count=0;
    int16 TempSenRaw=0, TempSenSum=0, MotorTemp=0;
    set_adc_channel(0);
    delay_us(20);
   for(count=0; count<16; count++)
      {
     
      TempSenRaw = read_adc(ADC_START_AND_READ);
      delay_us(20);
      TempSenSum += TempSenRaw;
      TempSenRaw = 0;
      }
   MotorTemp = (((35696-TempSenSum)/22144) + 30);
   lcd_send_byte(0,1);

   printf(lcd_putc, "\fMotorTemp=%2u", MotorTemp);
     delay_ms(5000);
   }   

   while(1);
}


Picture of the MPLAB_X SFR A/D registers



Did I do this wrong?
Thanks for your help.
_________________
Mick
mickent



Joined: 18 Feb 2007
Posts: 22
Location: TN, USA

View user's profile Send private message

PostPosted: Sat Jul 21, 2012 9:10 pm     Reply with quote

To complete this post for the records:

I reverted back to MPLAB 8.86 and it works.

I love the new stuff but it can bite you in the A**
_________________
Mick
jeremiah



Joined: 20 Jul 2010
Posts: 1348

View user's profile Send private message

PostPosted: Sun Jul 22, 2012 6:39 am     Reply with quote

The main thing is to report it to Microchip so it can be fixed. The simulator is still in Beta, despite what they may say on their website.
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