GLCD Scope does not have display....HELP!!!!!!!!!!!!!!!!!!!!

Post your requests and ideas on the future development of mikroC.
Post Reply
Author
Message
ldhong
Posts: 3
Joined: 11 May 2008 07:52

GLCD Scope does not have display....HELP!!!!!!!!!!!!!!!!!!!!

#1 Post by ldhong » 16 May 2008 09:20

void displayFloat(int x, int y, float oldValue, float theValue) {
char toPrintOld[4];
char toPrint[4];
sprintf(toPrintOld, "%f", oldValue);
sprintf(toPrint, "%f", theValue);
toPrintOld[3] = '\0';
toPrint[3] = '\0'; // Limit shown digits to 3
Glcd_Write_Text(toPrintOld, x, y, 1);
Glcd_Write_Text(toPrint, x, y, 1);
}

void displayInt8(int x, int y, int oldValue, int theValue) {
char toPrintOld[4];
char toPrint[4];
sprintf(toPrintOld, "%u", oldValue);
sprintf(toPrint, "%u", theValue);
toPrintOld[3] = '\0';
toPrint[3] = '\0'; // Limit shown digits to 3
Glcd_Write_Text(toPrintOld, x, y, 1);
Glcd_Write_Text(toPrint, x, y, 1);
}

void displayInt16(int x, int y, int oldValue, int theValue) {
char toPrintOld[6];
char toPrint[6];
sprintf(toPrintOld, "%lu", oldValue);
sprintf(toPrint, "%lu", theValue);
toPrintOld[5] = '\0';
toPrint[5] = '\0'; // Limit shown digits to 5
Glcd_Write_Text(toPrintOld, x, y, 1);
Glcd_Write_Text(toPrint, x, y, 1);
}

int useThreshold = 0; // 0 = Off, 1 = Rising, 2 = Falling
int theThreshold = 127;
int timeType = 1; // 1 = us, 2 = ms
int timePeriod = 4; // us or ms per measurement (* 25 for each div)
int voltageRange = 1; // 1 = 0 - 5V, 2 = 0 - 2.5V, 3 = 0 - 1.25V
float voltageConst = 0.079365; // For displaying the scaled voltage
char strAverageV[] = "Av";
char strVMaximum[] = "Mx";
char strVMinimum[] = "Mn";
char strVPtoP[] = "PP";
char strThreshold[] ="Th";
char strOff[] = "Off";
char strRising[] = "Rise";
char strFalling[] = "Fall";
char strTime[] = "Tm";
char strMs[] = "ms/div";
char strHz[] = "Hz";
char strRange[] = "R";
char strR0to5[] = "0-5";
char strR0to25[] = "0-2.5";
char strR0to12[] = "0-1.2";

void changeThreshold(int theUsage, int theValue) {
float tempFloat = 0.0;

tempFloat = (theThreshold>>2) * voltageConst;

if (theUsage == 0)
Glcd_Write_Text(strOff, 12, 24, 1);
else if (theUsage == 1) {
Glcd_Write_Text(strRising, 12, 24, 1);
displayFloat(12, 30, tempFloat, (theValue>>2) * voltageConst);
}
else if (theUsage == 2) {
Glcd_Write_Text(strFalling, 12, 24, 1);
displayFloat(12, 30, tempFloat, (theValue>>2) * voltageConst);
}

useThreshold = theUsage;
theThreshold = theValue;

Glcd_Write_Text(strThreshold, 0, 24, 1);
if (useThreshold == 0) Glcd_Write_Text(strOff, 12, 24, 1);
else if (useThreshold == 1) Glcd_Write_Text(strRising, 12, 24, 1);
else if (useThreshold == 2) Glcd_Write_Text(strFalling, 12, 24, 1);
}

void changeTimeDivision(int theType, int theValue) {
float tempFloat = 0.0, tempFloat2 = 0.0;

Glcd_Write_Text(strTime, 0, 36, 1);
if (theType == 1) {
tempFloat = timePeriod * 25;
tempFloat2 = theValue * 25;
displayFloat(12, 36, tempFloat/1000, tempFloat2/1000);
}
else if (theType == 2)
displayFloat(12, 36, timePeriod * 25, theValue * 25);

timeType = theType;
timePeriod = theValue;

if ((theType == 1) && (timePeriod < 16)) timePeriod = 16;

Glcd_Write_Text(strMs, 4, 42, 1);
}

void changeVoltageRange(int theType) {
Glcd_Write_Text(strRange, 0, 54, 1);
if (voltageRange == 1) Glcd_Write_Text(strR0to5, 8, 54, 1);
else if (voltageRange == 2) Glcd_Write_Text(strR0to25, 8, 54, 1);
else if (voltageRange == 3) Glcd_Write_Text(strR0to12, 8, 54, 1);

voltageRange = theType;

if (voltageRange == 1) voltageConst = 0.079365;
else if (voltageRange == 2) voltageConst = 0.039683;
else if (voltageRange == 3) voltageConst = 0.019841;

if (voltageRange == 1) Glcd_Write_Text(strR0to5, 8, 54, 1);
else if (voltageRange == 2) Glcd_Write_Text(strR0to25, 8, 54, 1);
else if (voltageRange == 3) Glcd_Write_Text(strR0to12, 8, 54, 1);
}

void main() {


int const numOfSamples = 100;
int HQadcReadings[numOfSamples];
int adcReadings[numOfSamples], adcReadingsOld[numOfSamples];
int i = 0;
int thres2 = 1;
int tempThres = 0, k = 0;
float avgV = 0.0, avgVOld = 0.0;
float maxV = 0.0, maxVOld = 0.0;
float minV = 0.0, minVOld = 0.0;
float ptopV = 0.0, ptopVOld = 0.0;
int theFreq = 0.0, theFreqOld = 0.0;

INTCON = 0; // disable all interrupts
ADCON1 = 0x82; // configure VDD as Vref, and analog channels
TRISA = 0xFF; // designate porta as input

Glcd_Init(&PORTC, 4,5,0,1,6,2, &PORTB);
Glcd_Fill(0x00); // Must initialize the LCD
Glcd_Line((128-numOfSamples),0,(128-numOfSamples),63,1);

// Draw static text
Glcd_Write_Text(strAverageV, 0, 0, 1);
Glcd_Write_Text(strVMaximum, 0, 6, 1);
Glcd_Write_Text(strVMinimum, 0, 12, 1);
Glcd_Write_Text(strVPtoP, 0, 18, 1);
Glcd_Write_Text(strHz, 20, 48, 1);
// Setup variable ranges
changeVoltageRange(1); // Set voltage range
changeTimeDivision(1, 200); // Set time divisions
changeThreshold(1, 127); // Set threshold level

delay_ms(10);

delay_ms(100);
while (1) {
// If using threshold, wait until it has been reached
if (voltageRange == 1) tempThres = (int) theThreshold << 2;
else if (voltageRange == 2) tempThres = (int) theThreshold << 1;
else if (voltageRange == 3) tempThres = (int) theThreshold;
if (useThreshold == 1) {
k = 0;
while ((ADC_read(2)>tempThres) && (k<65535)) (k++);
k = 0;
while ((ADC_read(2)<tempThres) && (k<65535)) (k++);
}
else if (useThreshold == 2) {
k = 0;
while ((ADC_read(2)<tempThres) && (k<65535)) (k++);
k = 0;
while ((ADC_read(2)>tempThres) && (k<65535)) (k++);
}

// Collect ADC readings
if (timeType == 1)
for (i=0; i<numOfSamples; i++) {
HQadcReadings = ADC_read(2);
//Delay_us(timePeriod - 16);
Delay_us(100);
}
else if (timeType == 2)
for (i=0; i<numOfSamples; i++) {
HQadcReadings = ADC_read(2);
//Delay_ms(timePeriod);
Delay_ms(100);
}
for (i=0; i<numOfSamples; i++) {
if (voltageRange == 1) adcReadings = 63-(HQadcReadings>>4);
else if (voltageRange == 2) adcReadings = 63-(HQadcReadings>>3);
else if (voltageRange == 3) adcReadings = 63-(HQadcReadings>>2);
}

// Draw ADC readings
for (i=1; i<numOfSamples; i++)
Glcd_Dot(i+(128-numOfSamples),adcReadingsOld,1);
for (i=1; i<numOfSamples; i++)
Glcd_Dot(i+(128-numOfSamples),adcReadings,1);
for (i=0; i<numOfSamples; i++)
adcReadingsOld[i] = adcReadings[i];

// Calculate and display frequency of signal using zero crossing
// displayint8(0, 54, thres2, 0);
if (useThreshold != 0) {
for (i=0; i<63; i+=3)
Glcd_Dot(thres2+(128-numOfSamples),i,0);
if (useThreshold == 1) {
thres2 = 1;
while ((adcReadings[thres2]<(63-(theThreshold>>2))) && (thres2<numOfSamples-1)) (thres2++);
thres2++;
while ((adcReadings[thres2]>(63-(theThreshold>>2))) && (thres2<numOfSamples-1)) (thres2++);
}
else if (useThreshold == 2) {
thres2 = 1;
while ((adcReadings[thres2]>(63-(theThreshold>>2))) && (thres2<numOfSamples-1)) (thres2++);
thres2++;
while ((adcReadings[thres2]<(63-(theThreshold>>2))) && (thres2<numOfSamples-1)) (thres2++);
}
// displayint8(0, 54, 0, thres2);
for (i=0; i<63; i+=3)
Glcd_Dot(thres2+(128-numOfSamples),i,1);

k = (int) thres2 * timePeriod;
if (timeType == 1) theFreq = (float) 1000/k * 1000;
if (timeType == 2) theFreq = (float) 1000/k;
displayInt16(0, 48, theFreqOld, theFreq);
theFreqOld = theFreq;
}

// Calculate and display Average V
avgV = 0;
for (i=0; i<numOfSamples; i++)
avgV = (float) avgV + adcReadings[i];
avgV = (float) (63-(avgV / numOfSamples)) * voltageConst;
displayFloat(12, 0, avgVOld, avgV);
avgVOld = avgV;

// Calculate and display Maximum V
maxV = 63;
for (i=0; i<numOfSamples; i++)
if (adcReadings[i]<maxV) maxV = adcReadings[i];
maxV = (float) (63-maxV) * voltageConst;
displayFloat(12, 6, maxVOld, maxV);
maxVOld = maxV;

// Calculate and display Minimum V
minV = 0;
for (i=0; i<numOfSamples; i++)
if (adcReadings[i]>minV) minV = adcReadings[i];
minV = (float) (63-minV) * voltageConst;
displayFloat(12, 12, minVOld, minV);
minVOld = minV;

// Calculate and display Peak-to-peak V
ptopV = maxV - minV;
displayFloat(12, 18, ptopVOld, ptopV);
ptopVOld = ptopV;

// Display graph lines
if (useThreshold != 0)
for (i=29; i<127; i+=3)
Glcd_Dot(i,63-(theThreshold>>2),1);
for (i=0; i<63; i+=5) {
Glcd_Dot(53,i,1);
Glcd_Dot(78,i,1);
Glcd_Dot(103,i,1);
Glcd_Dot(127,i,1);
}

Delay_ms(100); // Reduces flicker by allowing pixels to be on
// much longer than off
}
}




I am trying to built a GLCD oscilloscope using PIC 18F2550 and above is the mikroC program for my pic18F2550. It was successfully compiled and HEX file was generated....When input signal from the frequency generator was fed into portA of pic 18f2550 nothing was display on the GLCD. All i got on my GLCD was a full black rectangle..I have double-checked the circuit connection and so the last resort was the problem to my program...SO, can any experts please troubleshoot and check for me is there anything missout or syntax error...Thank you first......

Post Reply

Return to “mikroC Wish List”