# Programming for SAMPLING two 12 BITS CHANNELS AT 500 Hz in Dynamic C using RCM 3700

**URL:** <https://forums.digi.com/t/programming-for-sampling-two-12-bits-channels-at-500-hz-in-dynamic-c-using-rcm-3700/15580>\
**Category:** Rabbit Software\
**Tags:** c, programmable, dynamic, xbee\
**Created:** [October 14, 2015, 8:03am UTC](https://forums.digi.com/t/programming-for-sampling-two-12-bits-channels-at-500-hz-in-dynamic-c-using-rcm-3700/15580 "2015-10-14T08:03:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![manishpatil](https://avatars.discourse-cdn.com/v4/letter/m/4bbf92/32.png) [@manishpatil](https://forums.digi.com/u/manishpatil)\
**Post date:** [October 14, 2015, 8:03am UTC](https://forums.digi.com/t/programming-for-sampling-two-12-bits-channels-at-500-hz-in-dynamic-c-using-rcm-3700/15580/1 "2015-10-14T08:03:02Z")

</div>

Hi Eveeryone  
I am looking for Programming for SAMPLING two 12 BITS CHANNELS AT 500 Hz in Dynamic C using RCM 3700.

---

<div class="post-metadata">

**Author:** ![TomCollins](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.digi.com/tomcollins/32/37_2.png) [@TomCollins](https://forums.digi.com/u/TomCollins)\
**Post date:** [October 14, 2015, 2:49pm UTC](https://forums.digi.com/t/programming-for-sampling-two-12-bits-channels-at-500-hz-in-dynamic-c-using-rcm-3700/15580/2 "2015-10-14T14:49:29Z")

</div>

Dynamic C includes a bunch of samples in the RCM3700/ADC folder for sampling analog channels. What have you been able to get working, and what are you currently stuck on? Can you read a single 12-bit channel? Is it the sampling frequency that’s an issue? Storage of samples?

---

<div class="post-metadata">

**Author:** ![manishpatil](https://avatars.discourse-cdn.com/v4/letter/m/4bbf92/32.png) [@manishpatil](https://forums.digi.com/u/manishpatil)\
**Post date:** [October 15, 2015, 9:27am UTC](https://forums.digi.com/t/programming-for-sampling-two-12-bits-channels-at-500-hz-in-dynamic-c-using-rcm-3700/15580/3 "2015-10-15T09:27:13Z")

</div>

Thanks for reply. Let recheck one more time. within two days I will get back to u. Below program I wrote.  
#class auto

#define DS1 0x40 //led, port F bit 6 bitmask  
#define DS2 0x80 //led, port F bit 7 bitmask

/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

- Configuration Section \*
- --------------------- \*
- All fields in this section must \*
- be altered to match your local \*
- network settings. \*  
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*_/  
/_
- Pick the predefined TCP/IP configuration for this sample. See
- LIB\TCPIP\TCP\_CONFIG.LIB for instructions on how to set the
- configuration.  
_/  
 #define TCPCONFIG 1  
 #define \_PRIMARY\_STATIC\_IP “192.168.0.40”  
 #define \_PRIMARY\_NETMASK “255.255.255.0”  
 #ifndef MY\_NAMESERVER  
 #define MY\_NAMESERVER “10.10.6.1”  
 #endif  
 #ifndef MY\_GATEWAY  
 #define MY\_GATEWAY “192.168.0.1”  
 #endif  
/_
- TCP/IP modification - reduce TCP socket buffer
- size, to allow more connections. This can be increased,
- with increased performance, if the number of sockets
- are reduced. Note that this buffer size is split in
- two for TCP sockets–1024 bytes for send and 1024 bytes
- for receive.  
\*/  
#define TCP\_BUF\_SIZE 2048

/\*

- Web server configuration  
\*/

/\*

- Define the number of HTTP servers and socket buffers.
- With tcp\_reserveport(), fewer HTTP servers are needed.  
\*/  
#define HTTP\_MAXSERVERS 2  
#define MAX\_TCP\_SOCKET\_BUFFERS 2

/\*

- Our web server as seen from the clients.
- This should be the address that the clients (netscape/IE)
- use to access your server. Usually, this is your IP address.
- If you are behind a firewall, though, it might be a port on
- the proxy, that will be forwarded to the Rabbit board. The
- commented out line is an example of such a situation.  
\*/  
#define REDIRECTHOST \_PRIMARY\_STATIC\_IP  
// #define REDIRECTHOST “[my.host.com:8080](http://my.host.com:8080)”

/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

- End of configuration section \*  
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/

/\*

- REDIRECTTO is used by each ledxtoggle cgi’s to tell the
- browser which page to hit next. The default REDIRECTTO
- assumes that you are serving a page that does not have
- any address translation applied to it.
- 

\*/

#define REDIRECTTO “http://” REDIRECTHOST “/index.shtml”

#memmap xmem  
#use “dcrtcp.lib”  
#use “http.lib”

/\*

- Notice that we have ximported in the source code for
- this program. This allows us to
- in the pages/showsrc.shtml.
- 

\*/

#ximport “samples/rcm3700/tcpip/pages/browseled.shtml” index\_html  
#ximport “samples/rcm3700/tcpip/pages/rabbit1.gif” rabbit1\_gif  
#ximport “samples/rcm3700/tcpip/pages/led1on.gif” led1on\_gif  
#ximport “samples/rcm3700/tcpip/pages/led1off.gif” led1off\_gif  
#ximport “samples/rcm3700/tcpip/pages/led2on.gif” led2on\_gif  
#ximport “samples/rcm3700/tcpip/pages/led2off.gif” led2off\_gif  
#ximport “samples/rcm3700/tcpip/pages/button.gif” button\_gif  
#ximport “samples/rcm3700/tcpip/pages/showsrc.shtml” showsrc\_shtml  
#ximport “samples/rcm3700/tcpip/browseled.c” browseled\_c

/\*

- In this case the .html is not the first type in the
- type table. This causes the default (no extension)
- to assume the shtml\_handler.
- 

\*/

/\* the default for / must be first \*/  
SSPEC\_MIMETABLE\_START  
SSPEC\_MIME\_FUNC(“.shtml”, “text/html”, shtml\_handler),  
SSPEC\_MIME(“.html”, “text/html”),  
SSPEC\_MIME(“.gif”, “image/gif”),  
SSPEC\_MIME(“.cgi”, “”)  
SSPEC\_MIMETABLE\_END

/\*

- Each ledx contains a text string that is either
- “ledon.gif” or “ledoff.gif” This string is toggled
- each time the ledxtoggle.cgi is requested from the
- browser.
- 

\*/

char led1[15];  
char led2[15];

int led1toggle(HttpState\* state)  
{  
if (strcmp(led1,“led1on.gif”)==0)  
strcpy(led1,“led1off.gif”);  
else  
strcpy(led1,“led1on.gif”);

cgi\_redirectto(state,REDIRECTTO);  
return 0;  
}

int led2toggle(HttpState\* state)  
{  
if (strcmp(led2,“led2on.gif”)==0)  
strcpy(led2,“led2off.gif”);  
else  
strcpy(led2,“led2on.gif”);

cgi\_redirectto(state,REDIRECTTO);  
return 0;  
}

SSPEC\_RESOURCETABLE\_START  
SSPEC\_RESOURCE\_XMEMFILE(“/”, index\_html),  
SSPEC\_RESOURCE\_XMEMFILE(“/index.shtml”, index\_html),  
SSPEC\_RESOURCE\_XMEMFILE(“/showsrc.shtml”, showsrc\_shtml),  
SSPEC\_RESOURCE\_XMEMFILE(“/rabbit1.gif”, rabbit1\_gif),  
SSPEC\_RESOURCE\_XMEMFILE(“/led1on.gif”, led1on\_gif),  
SSPEC\_RESOURCE\_XMEMFILE(“/led1off.gif”, led1off\_gif),  
SSPEC\_RESOURCE\_XMEMFILE(“/led2on.gif”, led2on\_gif),  
SSPEC\_RESOURCE\_XMEMFILE(“/led2off.gif”, led2off\_gif),  
SSPEC\_RESOURCE\_XMEMFILE(“/button.gif”, button\_gif),  
SSPEC\_RESOURCE\_XMEMFILE(“browseled.c”, browseled\_c),  
SSPEC\_RESOURCE\_ROOTVAR(“led1”, led1, PTR16, “%s”),  
SSPEC\_RESOURCE\_ROOTVAR(“led2”, led2, PTR16, “%s”),  
SSPEC\_RESOURCE\_FUNCTION(“/led1tog.cgi”, led1toggle),  
SSPEC\_RESOURCE\_FUNCTION(“/led2tog.cgi”, led2toggle),  
SSPEC\_RESOURCETABLE\_END

void update\_outputs()  
{  
auto int value;

```
value=PFDRShadow&amp;0x3F; //on state for leds

/* update O0 */

```

costate  
{  
BitWrPortI(PBDR, &PBDRShadow, 0, 5); // chip select low  
sent [1]=160; // channel 0  
for(j = 0;j \< 10;j++);  
SPIWrRd(sent,received, 3);  
for(j = 0;j \< 10;j++);  
BitWrPortI(PBDR, &PBDRShadow, 1, 5); // chip select high  
i=(received[1]%16)\*256+received [2];  
printf("ADC 0value: %d ", i);  
serDputc(received[1]%16);  
serDputc(received[2]);  
BitWrPortI(PBDR, &PBDRShadow, 0, 5); // chip select low  
sent [1]=224; //channnel 1  
for(j = 0;j \< 10;j++);  
SPIWrRd(sent,received, 3);  
for(j = 0;j \< 10;j++);  
BitWrPortI(PBDR, &PBDRShadow, 1, 5); // chip select high  
i=(received[1]%16)\*256+received [2];  
printf("ADC 0value: %d ", i);  
serDputc(received[1]%16);  
serDputc(received[2]);  
waitfor(DelayMs(2));

```
/* update O1 */

```

}  
costate  
{ if (strcmp(led2,“led2on.gif”))  
// value|=DS2;  
BitWrPortI(PADR, &PADRShadow,1, 4); //PA6=0  
else BitWrPortI(PADR, &PADRShadow,0, 4); //PA6=0  
WrPortI(PFDR, &PFDRShadow, value);  
}  
}

main()  
{

```
//brdInit(); //initialize board for this demo

```

WrPortI(SPCR,&SPCRShadow,0x84); //PortA outputs

```
BitWrPortI(PBDR, &amp;PBDRShadow,0, 6);	//PA6=0

```

BitWrPortI(PBDR, &PADRShadow,0, 4); //PA6=0

strcpy(led1,“led1on.gif”);  
strcpy(led2,“led2off.gif”);

sock\_init();  
http\_init();  
tcp\_reserveport(80);

while (1)  
{  
update\_outputs();  
http\_handler();

```
}

```

}

#nodebug
