We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
device:LPC2103 Keil MDK 3.11 I want to control the sample speed with MAT0.3 in simulator,but I can't reach the interrupt subroutine and the ADC do not work at all! Thanks everyone read the message!
the following is my code:
******************************************************* #include <lpc2103.h>
void InitADC(void); __irq void irq_adc (void) ;
void InitTimmer(void); __irq void irq_t0 (void) ;
int main(void) {
InitADC(); InitTimmer(); while(1); return(0) ; }
// T0.3 void InitADC(void) { // SEL CKDIV PDN START
int x=0x000000ff | 100<<8 | 1<<21 |5<<24 ;
ADCR = x;
ADINTEN=0X1FF;
PINSEL0 |= 3<<20 | 3<<22 | 3<<24;
PINSEL1 |=3<<12 | 3<<14 | 3<<16 | 3<<18 | 3<<20 ;
VICVectAddr1=(long)irq_adc ;
VICVectCntl1 |= 0x20 | 18; VICIntEnable |= 1<<18;
}
void InitTimmer(void) { T0MCR = 3<<9;//On match reset the counter and generate an interrupt
T0MR3 = 1500; //Set the cycle time
T0TCR = 0x00000001;//enable timer
VICVectAddr0=(long)irq_t0 ;
VICVectCntl0 = 0x20 |4; VICIntEnable|= 1<<4;
__irq void irq_adc (void) { int adc_channal;
adc_channal=ADSTAT & 0x00ff;
switch(adc_channal)
{ case 1:break; case 2 :break; case 4 :break; case 8 :break; case 0x10 :break; case 0x20 :break; case 0x40:break; case 0x80:break; } }
__irq void irq_t0 (void) { T0IR = 1; // Clear interrupt flag
VICVectAddr = 0; // Acknowledge Interrupt
switch(T0IR) { case 1:break; case 2 :break; case 4 :break; case 8 :break; case 0x10 :break; case 0x20 :break; case 0x40:break; case 0x80:break; }
No, I don't think too many will read your message unless you take the time to read the posting instructions.
Repost your code, but format it properly so it is readable! The instructions are available in the form when you write your post!
device:lpc2103 develop tool:keil mdk3.11 simulator
function: 1.Sample voltage from AD00.
2.Sampling speed is controlled by MAT0.3
problem: can't not reach the ADC interrupt subrountine
code list:
#include <lpc2103.h>
void InitADC(void);//initiate ADC __irq void irq_adc (void) ;//ADC interrupt subrountine
void InitTimmer(void);//initiate timmer __irq void irq_t0 (void) ;//timmer 0 interrupt subrountine
InitADC(); //initiate ADC
InitTimmer(); //initiate timmer
while(1);
return(0) ;
// T0.3 void InitADC(void)
{ // SEL=1 CKDIV=100 PDN=1 START=5(MAT0.3)
ADCR = 0x1 | 100<<8 | 1<<21 |5<<24 ;
ADINTEN=0X101;//enable interrupt of ADC
PINSEL0 |= 3<<20 | 3<<22 | 3<<24;// connect the pin
VICVectAddr1=(long)irq_adc ;//set the interrupt adress
VICVectCntl1 |= 0x20 | 18; //set the timmer0 interrupt
VICIntEnable |= 1<<18;//enable timmer0 interrupt
void InitTimmer(void)//Initiate the timmer0 { T0MCR = 3<<9;//On match reset the counter and generate an interrupt in MAT0.3
// the ADC interrupt subrountine
{ case 1:break;
case 2 :break;
case 4 :break;
case 8 :break;
case 0x10 :break;
case 0x20 :break;
case 0x40:break;
case 0x80:break;
} }
// THE timmer0 interrupt subrountine
__irq void irq_t0 (void) {
switch(T0IR) { case 1:break;
TOIR=0XFF;
Do you read your datasheets as carefully as you read the instructions how to post code?
do you mean that my code isn't writed followed the registers setting in the LPC2103 datasheet or my code pasted in the Forum don't match the form that a thread should be in?
If it is the previous one,I will answer "yes".If I set ADC sample immidiately,it can be reached the interrupt subroutine.But it does not affect in the case of starting by MAT0.3.
If it is the latter,I find it in the page,but I can't find it .
www.danlhenry.com/.../keil_code.png
device:lpc2103 develop
tool:keil mdk3.11 simulator
#include <lpc2103.h> void InitADC(void);//initiate ADC __irq void irq_adc (void) ;//ADC interrupt subroutine void InitTimmer(void);//initiate timmer __irq void irq_t0 (void) ;//timmer 0 interrupt subroutine int main(void) { InitADC(); //initiate ADC InitTimmer(); //initiate timmer while(1); return(0) ; } void InitADC(void)// Initate the ADC { // SEL=1 CKDIV=100 PDN=1 START=5(MAT0.3) ADCR = 0x1 | 100<<8 | 1<<21 |5<<24 ; ADINTEN=0X101;//enable interrupt of ADC PINSEL0 |= 3<<20 | 3<<22 | 3<<24;// connect the pin PINSEL1 |=3<<12 | 3<<14 | 3<<16 | 3<<18 | 3<<20 ; VICVectAddr1=(long)irq_adc ;//set the interrupt adress VICVectCntl1 |= 0x20 | 18; //set the timmer0 interrupt VICIntEnable |= 1<<18;//enable timmer0 interrupt } void InitTimmer(void)//Initiate the timmer0 { T0MCR = 3<<9;//On match reset the counter and generate an interrupt in MAT0.3 T0MR3 = 1500; //Set the cycle time T0TCR = 0x00000001;//enable timer VICVectAddr0=(long)irq_t0 ; VICVectCntl0 = 0x20 |4; VICIntEnable|= 1<<4; } // the ADC interrupt subrountine __irq void irq_adc (void) { int adc_channal; adc_channal=ADSTAT & 0x00ff; VICVectAddr = 0; // Acknowledge Interrupt switch(adc_channal) { case 1:break; case 2 :break; case 4 :break; case 8 :break; case 0x10 :break; case 0x20 :break; case 0x40:break; case 0x80:break; } } // THE timmer0 interrupt subrountine __irq void irq_t0 (void) { VICVectAddr = 0; // Acknowledge Interrupt switch(T0IR) { case 1:break; case 2 :break; case 4 :break; case 8 :break; case 0x10 :break; case 0x20 :break; case 0x40:break; case 0x80:break; } TOIR=0XFF; }
Is that how you actually write your code?
Do you find it clear and easy to read?
Most people find it helps to use indentation and whitespace to lay-out their code for easier reading; eg,
int main(void) { InitADC(); // initiate ADC InitTimmer(); // initiate timmer while(1); return(0) ; }
and:
void InitADC(void)// Initate the ADC { ADCR = 0x1 | 100<<8 | 1<<21 | 5<<24 ; ADINTEN = 0x101; // enable interrupt of ADC PINSEL0 |= 3<<20 | 3<<22 | 3<<24; // connect the pin PINSEL1 |= 3<<12 | 3<<14 | 3<<16 | 3<<18 | 3<<20 ; VICVectAddr1 = (long)irq_adc ;// set the interrupt adress VICVectCntl1 |= 0x20 | 18; // set the timmer0 interrupt VICIntEnable |= 1<<18; // enable timmer0 interrupt }
Thank you for looking at my threat so seriously!!
code list: The declaration
#include <lpc2103.h> void InitADC(void);//initiate ADC __irq void irq_adc (void) ;//ADC interrupt subroutine void InitTimer(void);//initiate timmer __irq void irq_t0 (void) ;//timmer 0 interrupt subroutine
The main function
int main(void) { InitADC(); //initiate ADC InitTimer(); //initiate timer while(1); return(1) ; }
ADC initiation part
void InitADC(void)// Initate the ADC { // SEL=1 CKDIV=100 PDN=1 START=5(MAT0.3) ADCR = 0x1 | 100<<8 | 1<<21 |5<<24 ; ADINTEN=0X101;//enable interrupt of ADC PINSEL0 |= 3<<20 | 3<<22 | 3<<24;// connect the pin PINSEL1 |=3<<12 | 3<<14 | 3<<16 | 3<<18 | 3<<20 ; VICVectAddr1=(long)irq_adc ;//set the interrupt adress VICVectCntl1 |= 0x20 | 18; //set the timmer0 interrupt VICIntEnable |= 1<<18;//enable timmer0 interrupt }
timer initiation part
void InitTimer(void)//Initiate the timer0 { T0MCR = 3<<9;//On match reset the counter and generate an interrupt in MAT0.3 T0MR3 = 1500; //Set the cycle time T0TCR = 0x00000001;//enable timer VICVectAddr0=(long)irq_t0 ; VICVectCntl0 = 0x20 |4; VICIntEnable|= 1<<4; }
the ADC interrupt subrountine
// the ADC interrupt subrountine __irq void irq_adc (void) { int adc_channal; adc_channal=ADSTAT & 0x00ff; VICVectAddr = 0; // Acknowledge Interrupt switch(adc_channal) { case 1:break; case 2 :break; case 4 :break; case 8 :break; case 0x10 :break; case 0x20 :break; case 0x40:break; case 0x80:break; } }
THE timmer0 interrupt subrountine
// THE timmer0 interrupt subrountine __irq void irq_t0 (void) { VICVectAddr = 0; // Acknowledge Interrupt switch(T0IR) { case 1:break; case 2 :break; case 4 :break; case 8 :break; case 0x10 :break; case 0x20 :break; case 0x40:break; case 0x80:break; } TOIR=0XFF; }
Now I have finished the thread edition . Is there anyone doing me a favor to answer my question?
You need to setup the External Match Control 0 to Toggle (T0EMR = 0x0C00) in order for External Match 0 (EM0 bit in T0EMR) to change and trigger the A/D.
Current version of the simulator will however work only with Match Outputs that are actually connected to pins (MAT0.3 is not connected to a pin on LPC2103). This is fixed in the next release of MDK. Please contact support.intl@keil.com for an update.
Next problem in your code is the A/D Converter IRQ routine which doesn't clear the A/D Interrupt flag which will lead to an endless IRQ. You need to clear the IRQ flag by reading the A/D Global Data register (ADGDR).
Thanks! Is it means that if I use hareware to execude my code ,it can be successful ? My circuit will be reach today,and I will test my code .
Your test program will fail on real HW without the two modifications I have pointed out earlier.