ADC16 - get value and set channel

Post your C and C++ discussions here
Post Reply
jonyb82
User
User
Posts: 3
Joined: Thu Sep 25, 2008 9:11 am

ADC16 - get value and set channel

Post by jonyb82 »

I have a Pico ADC16 which is currently being used for optical measurements. I have the task of updating the software that is currently being used.
I have attempted to write a program in c# and have got stuck, although i managed to open the port and report the driver version correctly.
The problem came when i attempted to set the channels and read values.
I suspected that it was due to problems with calling the adc1632.dll correctly from .NET, so i dumped that and went back to native c++.

However i have the exact same problem. When i set the channels it returns true, but never does when i ask for a value.

I have a serial monitor program which shows the comms and nothing goes to the ADC16 after the port has been opened. The pico recorder software works and is reading values.

So my questions are: should i expect, when calling set_channel , for information to be sent to the pico, or does this wait until get value is called? and why are no values being read?

Here is my C++ code (i'm a c# programmer so it might not be too good, but it compiles ok). I'm using VS2005 and the lastest SDK from pico website.

// PicoOldSchool.cpp : Defines the entry point for the console application.
#include "stdafx.h"

int _tmain(int argc, _TCHAR* argv[])
{
unsigned short port = 1;
unsigned short channel = 1;
unsigned short resolution = 16;
unsigned short single_ended = short(false);
unsigned short filter_factor = 10;

short ok;
short opened;

long value = 100;

//make sure it is closed and wait
adc16_close_unit(port);
Sleep(2000);

//open the pico port and report and wait
opened = adc16_open_unit(port);
printf("%ld", opened);
opened = 0;
Sleep(2000);

//set the channel -> returns true
opened = adc16_set_channel (port, channel, resolution, single_ended, filter_factor);
printf("%ld", opened);

for (int l = 0; l<5; l++)
{
Sleep(3000);
ok = adc16_get_value (&value, port, channel);

if(ok==1)
{
printf("%ld", value);
}
else
{
printf("no reading");
}
}

Sleep(2000);
//close the port
adc16_close_unit(port);

return 0;
}

// stdafx.h :
#pragma once
#define WIN32_LEAN_AND_MEAN
#include
#include
#include // for dodgy sleep function
#include
#include "adc16.h"

jonyb82
User
User
Posts: 3
Joined: Thu Sep 25, 2008 9:11 am

Post by jonyb82 »

I have answered my own question: no, there will be no communication to the adc16 when i call the set_channel function. This is only used to send to correct data to the adc16 when i call get_value.

I still cant receive any data using this program. Any ideas on what to try next?

jonyb82
User
User
Posts: 3
Joined: Thu Sep 25, 2008 9:11 am

Post by jonyb82 »

Another note:
I removed 'far' from the adc16.h file to make it compile, i assumed these were no longer required for 32bit arch.

Post Reply