View previous topic :: View next topic |
Author |
Message |
mickent
Joined: 18 Feb 2007 Posts: 22 Location: TN, USA
|
PIC24 MPLAB_X failure to write SFR registers |
Posted: Wed Jul 18, 2012 5:42 pm |
|
|
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
|
|
Posted: Sat Jul 21, 2012 9:10 pm |
|
|
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: 1354
|
|
Posted: Sun Jul 22, 2012 6:39 am |
|
|
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. |
|
|
|