Content originally posted in LPCWare by YES_IKEDA on Tue Feb 04 20:44:28 MST 2014
Thank you.
Yes, I've read of course.
I ran in the source code below.
1. Variables are global variables.
2. Analog pin is fixed to GND.
3. ADCRead (x); such as is polling the original method.
(There is no external trigger.It is not a burst mode.)
4. Value indicated by this should indicate a zero value around almost.
5. However, I will show a large value sometimes more than 100.
6. CLKDIV of AD0CR is the same even if it is set to 1MHz, and even if it is set to 4MHz.
7. The SystemCoreClock has set to 100MHz.
I was able to see the big value 100 or more than zero.
I think whether Well Well that's the value of from 0 to less than 50.
Why not?
I have the same problem the question advertisers.
Thank you.
Is the source code....
/*
===============================================================================
Name : main.c
Author : $(author)
Version :
Copyright : $(copyright)
Description : main definition
===============================================================================
*/
#ifdef __USE_CMSIS
#include "LPC17xx.h"
#endif
#include <cr_section_macros.h>
#include <stdio.h>
#include "stdlib.h"
#include "string.h"
#include "ctype.h"
#include "type.h"
#include "math.h"
#include "adc.h"
#include "i2c.h"
#include "rtc.h"
#include "ssp.h"
#include "timer.h"
#include "uart.h"
#include "main.h"
#include "ExtValue.h"
//-----------------------------------------//
// main loop
// Variables are global variables.
// uiToString(xx),Device_Init(),InitValue()
// is Function of self-made
//-----------------------------------------//
int main(void)
{
SystemCoreClockUpdate();
Device_Init();
// Variable initialization
InitValue();
while(1){
switch(iMainTaskSwitch){
case0:
// Average value
iAD_0 = ADCRead(0);
iAD_1 = ADCRead(1);
iAD_2 = ADCRead(2);
iAD_3 = ADCRead(3);
iAD_4 = ADCRead(4);
iAD_5 = ADCRead(5);
iAD_Total = iAD_0 + iAD_1 + iAD_2 + iAD_3 + iAD_4 + iAD_5;
iAD_Avrage = iAD_Total / 6;
iMainTaskSwitch = 10;
break;
case10:
iAD_0 = ADCRead(0);
iAD_1 = ADCRead(1);
iAD_2 = ADCRead(2);
iAD_3 = ADCRead(3);
iAD_4 = ADCRead(4);
iAD_5 = ADCRead(5);
iMainTaskSwitch = 10;
iDiff = abs(iAD_Avrage - iAD_0);
if(iDiff > 100){
iMainTaskSwitch = 20;
}
iDiff = abs(iAD_Avrage - iAD_1);
if(iDiff > 100){
iMainTaskSwitch = 20;
}
iDiff = abs(iAD_Avrage - iAD_2);
if(iDiff > 100){
iMainTaskSwitch = 20;
}
iDiff = abs(iAD_Avrage - iAD_3);
if(iDiff > 100){
iMainTaskSwitch = 20;
}
iDiff = abs(iAD_Avrage - iAD_4);
if(iDiff > 100){
iMainTaskSwitch = 20;
}
iDiff = abs(iAD_Avrage - iAD_5);
if(iDiff > 100){
iMainTaskSwitch = 20;
}
break;
case20:
// Ready to Send
LPC_GPIO2->FIOSET = 1 << 6;// LED ON
iSendIndex = 0;
for(iSendIndex = 0; iSendIndex < 64; iSendIndex++){
chSendBuffer[iSendIndex] = ' ';
}
chSendBuffer[4] = ',';
chSendBuffer[9] = ',';
chSendBuffer[14] = ',';
chSendBuffer[19] = ',';
chSendBuffer[24] = ',';
chSendBuffer[29] = ',';
chSendBuffer[34] = 0x0d;
chSendBuffer[35] = 0x0a;
//Average value (places case 0:)
uiToString(4,iAD_Avrage,&chSendBuffer[0],1);
// CH0 <-> CH5
uiToString(4,iAD_0,&chSendBuffer[5],1);
uiToString(4,iAD_1,&chSendBuffer[10],1);
uiToString(4,iAD_2,&chSendBuffer[15],1);
uiToString(4,iAD_3,&chSendBuffer[20],1);
uiToString(4,iAD_4,&chSendBuffer[25],1);
uiToString(4,iAD_5,&chSendBuffer[30],1);
iSendIndex = 0;
iMainTaskSwitch = 25;
break;
case25:
// Transmission
LSRValue = LPC_UART0->LSR;
if (LSRValue & LSR_TEMT){
// both UnTHR and UnTSR are empty
chSend_Data = chSendBuffer[iSendIndex];
LPC_UART0->THR = chSend_Data;
iSendIndex++;
if(chSend_Data == 0x0a){
// Transmission completion
iMainTaskSwitch = 10;
LPC_GPIO2->FIOCLR = 1 << 6;// LED OFF
}
}
break;
default:
break;
}
}
return 0 ;
}