

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


#include "predef.h" #include <stdio.h> #include <ctype.h> #include <startnet.h> #include <autoupdate.h> #include <dhcpclient.h> #include <..\mod5282\system\sim5282.h> extern "C" { void UserMain(void * pd); } /* Set up A/D to continuously sample all 8 channels and store the results / void InitializeQADC() { sim.qadc.qadcmcr=0x8000; sim.qadc.portqa=0; sim.qadc.portqb=0; sim.qadc.ddrqa=0; sim.qadc.ddrqb=0; sim.qadc.qacr0=0x7F; / 64Mhz clock / sim.qadc.qacr1=0x1100; _/ probably not needed (repeated below) /_ sim.qadc.qacr2=11; sim.qadc.qasr0=0; sim.qadc.qadcmcr=0x0000; sim.qadc.ccw[0]=0xC0; sim.qadc.ccw[1]=0xC1; sim.qadc.ccw[2]=0xC2; sim.qadc.ccw[3]=0xC3; sim.qadc.ccw[4]=0xF4; sim.qadc.ccw[5]=0xF5; sim.qadc.ccw[6]=0xF7; sim.qadc.ccw[7]=0xF8; sim.qadc.ccw[8]=0xFC; sim.qadc.ccw[9]=0xFD; sim.qadc.ccw[10]=0xFF; _sim.qadc.qacr1=0x1100; / Continious software scans in queue 1 /_ } / Return the converted samples / WORD GetQADC(int ch) { return sim.qadc.rjurr[ch]; } void UserMain(void * pd) { InitializeStack(); if (EthernetIP==0)GetDHCPAddress(); OSChangePrio(MAIN_PRIO); EnableAutoUpdate(); / Start up the A/D system / InitializeQADC(); iprintf("Application started\n"); while (1) { OSTimeDly(20); iprintf("A/D values. Floating point voltage assumes a 5.0V reference\r\n"); for (int i=0; i<10; i++) { WORD v=GetQADC(i); float f=v; f=f5.0/1024.0; printf("AD[%d] = 0x%03X or %4d or %4.2fV \r\n",i,v,v,f); } } } Docsity.com