本文整理汇总了C++中ReadADC函数的典型用法代码示例。如果您正苦于以下问题:C++ ReadADC函数的具体用法?C++ ReadADC怎么用?C++ ReadADC使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ReadADC函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testPNP
u16 testPNP() {
u8 i, C[2], B[2], E[2];
u16 Vc[2], Vb[2];
u32 hFE[2];
B[0] = B[1] = tList[0][1];
C[0] = E[1] = tList[1][0];
C[1] = E[0] = tList[0][0];
R_470K(B[0], LOW);
for (i = 0; i < 2; i++) {
R_680(C[i], LOW);
R_0(E[i], HIGH);
Delay_MS(10);
Vc[i] = ReadADC(C[i]);
Vb[i] = ReadADC(B[i]);
hFE[i] = (u32) Vc[i]*691;
hFE[i] = hFE[i] / Vb[i];
}
HiZ3(B[0], C[0], E[0]);
if (hFE[0] > hFE[1])i = 0;
else i = 1;
pins[C[i]] = 'C';
pins[B[i]] = 'B';
pins[E[i]] = 'E';
return hFE[i];
}
示例2: main
/* Main function */
int main() {
char tempVal; // 8 bit value of the temperature.
char flowVal; // 8 bit value of the flow rate.
int stat = 0; // Status of device.
Init();
while(1) {
// Wait for command from base.
SwtichAlpha(RX);
while(!stat)
{
stat = (ID & ReceiveAlpha());
}
SwtichAlpha(ID);
// Gather sensor values.
tempVal = ReadADC(TEMP);
flowVal = ReadADC(FLOW);
// Transmit sensor values.
SwtichAlpha(TX);
SendAlpha(tempVal);
SendAlpha(flowVal);
}
}
示例3: testRES
u16 testRES() {
u8 R1, R2;
u32 v0, v680, v470K, rt680, rt470K, rr;
R1 = tList[0][0];
R2 = tList[0][1];
R_0(R2, LOW);
R_680(R1, HIGH);
Delay_MS(10);
v0 = ReadADC(R2);
v680 = ReadADC(R1);
R_470K(R1, HIGH);
Delay_MS(10);
v470K = ReadADC(R1);
HiZ(R1);
HiZ(R2);
//When Rx > sqrt(680*470000) the rt470K is more accurate
//we calculate if this threshold has been passed below
if (v680 > 512) rt680 = v680 - 512;
else rt680 = 512 - v680;
if (v470K > 512) rt470K = v470K - 512;
else rt470K = 512 - v470K;
if (rt470K > rt680){
//We will use the value calculated with the 680R resistor
if(v680==v0){ //Shortcircuit?
rr = 1; //0 is considered error
}
else{
//Use the common formula for a voltage divisor with some correction
//The output is not 5V and 0V for HIGH and LOW, the difference increasses with
//lower resistor values, empirically V_low=x, V_high=Vcc-2.80*V_low
//R = 680*(v680-v0)/(1023-2.8v0-v680)
rr = (5*R680_IDEAL*(v680-v0)) / (5*1023 - 14*v0 - 5*v680);
}
}
else{
//We will use the value calculated with the 470K resistor
//Use the common formula for a voltage divisor
rr = (R470K_IDEAL*v470K) / (1023 - v470K);
}
pins[R1] = 'R';
pins[R2] = 'R';
part_unit = 'R';
if (rr > 0x03E7FC18) { //Values that overflow 16bits when divided by 1000
rr /= 1000000;
part_unit = 'M';
}
else if(rr > 0xFFFF){ //Values that overflow 16bits
rr /= 1000;
part_unit = 'K';
}
return (u16) rr;
}
示例4: TaskSensores
void TaskSensores(void *pdata)
{
#if OS_CRITICAL_METHOD == 3
OS_CPU_SR cpu_sr;
#endif
struct AdcMsg *m;
INT16U value = 0;
INT16U ValorTeclado = 0;
INT8U err;
for(;;)
{
m = (struct AdcMsg *) OSMemGet(dMemory,&err);
if(err == OS_NO_ERR){
OSSemPend(STeclado,0,&err);
ValorTeclado = NumeroSensores;
OSSemPost(STeclado);
m->adc0 = 0;
m->adc1 = 0;
m->adc2 = 0;
switch(ValorTeclado){
case 3:
Delay10TCYx(100);
SetChanADC(ADC_CH2);
ConvertADC();
while( BusyADC() );
value = ReadADC();
m->adc2 = Temp(value);
case 2:
Delay10TCYx(100);
SetChanADC(ADC_CH1);
ConvertADC();
while( BusyADC() );
value = ReadADC();
m->adc1 = Temp(value);
case 1:
Delay10TCYx(100);
SetChanADC(ADC_CH0);
ConvertADC();
while( BusyADC() );
value = ReadADC();
m->adc0 = Temp(value);
default:
break;
}
err = OSQPost(QueueADC0,m);
if(err == OS_Q_FULL){
OSMemPut(dMemory,m);
OSSemPost(STaskTxSerial);
}
}else{
OSSemPost(STaskTxSerial);
}
//OSSemPost(STask2);
OSTimeDly(1);
}
}
示例5: ReadZ
// Read Pressure on board 2
static void ReadZ(int* z1, int* z2)
{
DDRB = 0x10; // XP = 0
PORTB = 0x00;
DDRD = 0x80; // YM = 1
PORTD = 0x80;
*z1 = ReadADC(12); // Measure z1 (Read YP ADC)
*z2 = ReadADC(9); // Measure z2 (Read XM ADC)
}
示例6: PublishMotorPowerData
/*
* Read and publish voltage and current for power calculations
*/
void PublishMotorPowerData()
{
//Generate the msg
hardware_interface::RawMotorPowerData power_data;
//Read the data
power_data.current = ReadADC(ADC_CURRENT_SENSE, ADC_CH0);
power_data.voltage = ReadADC(ADC_CURRENT_SENSE, ADC_CH1);
//Publish the msg
motor_power_pub.publish(power_data);
}
示例7: ShortedProbes
uint8_t ShortedProbes(uint8_t Probe1, uint8_t Probe2)
{
uint8_t Flag1 = 0; /* return value */
unsigned int U1; /* voltage at probe #1 in mV */
unsigned int U2; /* voltage at probe #2 in mV */
unsigned int URH; /* half of reference voltage */
const uint8_t *addr;
uint8_t pp;
/*
* Set up a voltage divider between the two probes:
* - Probe1: Rl pull-up
* - Probe2: Rl pull-down
*/
ADC_DDR = TXD_MSK; // all-Pins to Input
ADC_PORT = TXD_VAL; // all ADC-Ports to GND
addr = &PinRLRHADCtab[Probe1];
pp = pgm_read_byte(addr);
R_PORT = pp;
addr += (int8_t)(Probe2-Probe1);
R_DDR = pp | pgm_read_byte(addr); // pgm_read_byte(PinRHtab[Probe1]) | pgm_read_byte(PinRLtab[Probe2]);
/* read voltages */
U1 = ReadADC(Probe1);
U2 = ReadADC(Probe2);
/*
* We expect both probe voltages to be about the same and
* to be half of Vcc (allowed difference +/- 20mV).
*/
#ifndef MAX_UH_DIFF
#define MAX_UH_DIFF 30
#endif
URH = ADCconfig.U_AVCC / 2;
URH -= ((long)U_VCC * (long)(PIN_RP-PIN_RM)) / (4*(unsigned long)(R_L_VAL+PIN_RM)); // differenz of Pin resistance high (22) and low (20)
if (((U1 + MAX_UH_DIFF) > URH ) && (U1 < (URH + MAX_UH_DIFF)))
{
if (((U2 + MAX_UH_DIFF) > URH) && (U2 < (URH + MAX_UH_DIFF)))
{
Flag1 = 1;
}
}
/* reset port */
R_DDR = 0;
return Flag1;
}
示例8: SEC_InitializeADC
/*
* Setup ADC module to read in accelerometer and potentiometer values
*/
void SEC_InitializeADC(void) {
_mqx_int i;
char dev_name[10];
fd_adc = fopen(MY_ADC, (const char*)&adc_init);
if (NULL == fd_adc) {
printf("ADC device open failed\n");
_task_block();
}
for (i = 0; i < ADC_CH_COUNT; i++) {
sprintf(dev_name, "%s%d", MY_ADC, i);
fd_ch[i] = fopen(dev_name, (const char*)&adc_ch_param[i]);
if (NULL == fd_ch[i]) {
printf("adc:%d channel open failed\n", i);
_task_block();
}
}
_time_delay (100);
#if ADC_CH_COUNT > 1
for (i = 0; i < 3; i++) {
SEC_Params.last[i] = ReadADC(ADC_ACCX + i);
}
SEC_Params.flat=SEC_Params.last[ACCY];
#endif
_time_delay (200);
}
示例9: adc_int_handler
void adc_int_handler()
{
unsigned int result;
result = ReadADC();
result = result /4;
Handle_i2c_data_save(1,&result);
}
示例10: Sleep
/*!
\brief
Tastsensor Abfrage im 'Polling-Betrieb'.
\return
Tastenwert bitorientiert, K1 = Bit5, K2 = Bit4, K3 = Bit3, K4 = Bit2,
K5 = Bit1, K6 = Bit0
\see
Die globale Variable autoencode wird temporaer auf FALSE gesetzt und am Ende\n
der Funktion mit dem alten Wert restauriert.
\par Hinweis:
In dieser Funktion sind 2 Sleep() Aufrufe vorhanden. Sie werden benoetigt\n
damit der Kondensator an der AD-Wandlereinheit genuegend Zeit hat geladen\n
zu werden.
\par Beispiel:
(Nur zur Demonstration der Parameter/Returnwerte)
\code
uint8_t t1, t2;
unsigned char text [16];
while (1)
{
t1 = PollSwitch ();
t2 = PollSwitch ();
// 2x PollSwitch aufrufen und beide Rueckgabewerte auf Gleichheit ueberpruefen
if (t1 && t2 && t1 == t2) // irgendeine Taste gedrueckt
{
itoa (t1, text, 10); // Tastenwert senden
SerPrint (text);
SerPrint ("\r\n"); // Zeilenvorschub
}
Msleep (500); // 0,5 sek warten
}
\endcode
*****************************************************************************/
unsigned char PollSwitch (void)
{
unsigned int i;
int ec_bak = autoencode; // Sichert aktuellen Zustand
/*
Autoencode-Betrieb vom ADC-Wandler unterbinden.
*/
autoencode = FALSE;
DDRD |= SWITCHES; // Port-Bit SWITCHES als Output
SWITCH_ON; // Port-Bit auf HIGH zur Messung
i = ReadADC(SWITCH, 10);
SWITCH_OFF; // Port-Bit auf LOW
Sleep (5);
/*
Autoencode-Betrieb vom ADC-Wandler wiederherstellen.
*/
autoencode = ec_bak;
/*
Die Original Umrechenfunktion von Jan Grewe - DLR wurder ersetzt durch
eine Rechnung ohne FLOAT-Berechnungen.
return ((unsigned char) ((( 1024.0/(float)i - 1.0)) * 61.0 + 0.5));
Wert 61L evtl. anpasssen, falls fuer K1 falsche Werte zurueckgegebn werden.
*/
return ((10240000L / (long)i - 10000L) * MY_SWITCH_VALUE + 5000L) / 10000;
}
示例11: main
void main(void)
{
int16_t moyenne;
BoardInit();
/* Configuration de l'ADC
* horloge: oscillateur RC interne
* résultat justifié à droite
* temps d'acquisition: 2*Tad (délai minimum entre 2 conversions)
* canal 4
* interruption desactivée
* tensions référence par défaut (Vref+ = AVdd / Vref- = AVss)
*/
OpenADC(ADC_FOSC_RC|ADC_RIGHT_JUST|ADC_2_TAD, ADC_CH4|ADC_INT_OFF, 0);
moyenne = 0;
for (uint8_t i = 0; i < 16; i++) {
ConvertADC(); /* démarrage conversion */
while (BusyADC()); /* attente fin conversion */
moyenne += ReadADC(); /* lecture résultat */
}
moyenne /= 16;
while (1);
}
示例12: main
int main(void)
{
uint16_t adc_result;
int i;
char value[10];
sbi(DDRB, 4);
sbi(DDRC, 5);
cbi(PORTB,4);
sbi(PORTC,5);
UART_init(250000);
InitADC();
sei();
while(1)
{
adc_result=ReadADC(2); // Read Analog value from channel-2
// Voltage = adc_result*5/1024
// Temperature = (V - 1035 mV)/(-5.5 (mV/oC))
itoa(adc_result,value,10);
for(i=0;i<=2;i++){
UART_TxChar(value[i]);}
UART_TxStr("\n\r\0");
PORTB ^= (1<<PB4);
_delay_ms(100);
}
}
示例13: main
void main(void) {
int count;
unsigned int adcValue = 0;
unsigned int adcValueOld = 0;
char buffer[16];
ConfigureOscillator();
InitApp();
lcd_init();
lcd_enable();
lcd_cursor_off();
lcd_test();
lcd_pos(2, 1);
while (1) {
ConvertADC();
while (BusyADC());
adcValue = ReadADC();
if (adcValue != adcValueOld) {
lcd_clear();
lcd_pos(1, 1);
memset(&buffer[0], 0, sizeof(buffer));
sprintf(&buffer[0], "Valor: %.4u %.3u%%", adcValue, (int)(((float)adcValue / 1024) * 100));
lcd_write_buffer(buffer, strlen(buffer));
adcValueOld = adcValue;
}
__delay_ms(20);
}
}
示例14: ProcessIO
void ProcessIO(void)
{
BYTE numBytesRead;
//Blink the LEDs according to the USB device status
BlinkUSBStatus();
// User Application USB tasks
if((USBDeviceState < CONFIGURED_STATE)||(USBSuspendControl==1)) return;
if(buttonPressed)
{
if(stringPrinted == FALSE)
{
if(mUSBUSARTIsTxTrfReady())
{
putrsUSBUSART("Button Pressed data-- \r\n");
stringPrinted = TRUE;
}
}
}
else
{
stringPrinted = FALSE;
}
if(USBUSARTIsTxTrfReady())
{
numBytesRead = getsUSBUSART(USB_Out_Buffer,64);
if(numBytesRead != 0)
{
BYTE i;
for(i=0;i<numBytesRead;i++)
{
switch(USB_Out_Buffer[i])
{
case 0x0A:
case 0x0D:
putUSBUSART(&USB_Out_Buffer[i],numBytesRead);
break;
case 0x53://letter S to start sampling
ReadADC();
putUSBUSART(ADC_sample,SAMPLE_SIZE);
break;
case 0x51: //letter Q to stop
break;
default:
putUSBUSART(&USB_Out_Buffer[i],numBytesRead);
break;
}
}
//putUSBUSART(USB_In_Buffer,numBytesRead);
}
}
CDCTxService();
} //end ProcessIO
示例15: getPartSS_PNP
//2conducts, 1 node. directon 2 (IN), muct be PNP/DD-CC
type getPartSS_PNP() {
u16 test;
if (tList[0][2]>(tList[1][2] + DARL_BJT)) {
node = 0;
return PNP_D;
}
if (tList[1][2]>(tList[0][2] + DARL_BJT)) {
node = 1;
return PNP_D;
}
R_680(tList[0][1], LOW); //B
R_0(tList[0][0], HIGH); //E
R_680(tList[1][0], LOW); //C
test = ReadADC(tList[1][0]);
HiZ3(tList[0][0], tList[1][0], tList[0][1]);
//if VCE>0V then PNP
if (test > CP_LOW) return PNP;
//else it's a double diode with CA
return CC;
}