[En-Nut-Discussion] Newbie help ADC (possibly a fprintf problem) and HTML problem

Kathy Quinlan katinkad at kaqelectronics.dyndns.org
Sun Dec 11 08:02:33 CET 2005


Kathy Quinlan wrote:

> Hi all,
> 
> First off thanks to Harald and the rest of the crew for such a great 
> product.
> 
> My problems
> 
> I am adding some code into the webport utility to read the ADC, right 
> now it is just ADC0 (ie the first channel)
> 
> The HTML issue is just that I do not get a value in the box, I get the 
> word "Volts" above the table with an "f" in front of it.
> 
> The ADC problem is I think a problem with fprintf.
> 
> 
> Regards,
> 
> Kat.

OK all fixed, it was a HTML problem and a lack of RTFM on my part (well 
the FAQ), in reverse order ;) I did not realise that floating point was 
not complied in as default. easy fixed, read result in mV no problem.

The HTML problem was a lack of <td> and </td> in the fprintf statement, 
took a while to work out, but I got there.

When I get home tonight I will set up the vref and a pot to the input 
and make sure it works, with my kludged value for testing I get 100mV 
which is what I would expect (20 * 5).

Regards,

Kat.

(Changed code bellow in case someone else has a problem ;)


> Here is my code:
> 
> 
> 
> #include <dev/adc.h>    //at the top of the code with other includes
> 
> 
> /*!
>  * \brief CGI callback function to display the value of the ADC Channel.
>  *
>  * Creates HTML code to show the value of ADC Channel 0.
>  * The page will be automatically refreshed every 5 seconds.
>  *
>  *
>  *
>  *
>  *
>  * This function is called by the HTTP module when a browser requests
>  * a CGI function, for which this routine has been registered via
>  * NutRegisterCgi().
>  *
>  * \param stream Stream device of the HTTP connection.
>  * \param req    Pointer to the CGI REQUEST structure. Detailed information
>  *               is available in the Nut/OS API documentation.
>  *
>  * \return 0 on success or -1 in case of any failure.
>  */
> int ADCStatus(FILE * stream, REQUEST * req)
> {
>     u_short adc_value;
> 
>     static prog_char head[] =   /* */
>         "<html>"                /* */
>         "<head>"                /* */
>         "<meta http-equiv=\"refresh\" content=\"5; URL=" ADC_STATUS_CGI 
> "\">"  /* */
>         "<title>Ethernut CPU ADC Status</title>"       /* */
>         "</head>"               /* */
>         "<body bgcolor=\"#C7D0D9\"><a href=\"/\">"      /* */
>         "<img src=\"/enmini.gif\" border=\"0\" width=\"70\" 
> height=\"17\">"     /* */
>         "</a><div align=\"center\">"    /* */
>         "<table border=\"1\" cellspacing=\"0\">\r\n"    /* */
>         "<thead><tr><th rowspan=\"2\"> ADC Channel </th>"      /* */
>         "<th colspan=\"8\">Value</th></tr>"       /* */
>         "</thead><tfoot>\r\n";
> 
>     ADCInit();
>     ADCSetChannel(0);
>     ADCStartConversion();
>     while (ADCRead(&adc_value))
>         NutThreadYield();
> 
> 
>     NutHttpSendHeaderTop(stream, req, 200, "Ok");
>     NutHttpSendHeaderBot(stream, "text/html", -1);
> 
>     fputs_P(head, stream);
> 
>         adc_value =20;	//remove when ready with hardware
> 
>     fputs("<tr><th>0</th>", stream);
	/* NEW CODE
       fprintf(stream,"%i Volts",adc_value * 5.0);	
	
	END NEW CODE */
>

	/* OLD CODE
      fprintf(stream,"%4.1f Volts",adc_value /1023.0 * 5.0);

	END OLD CODE */
>     fputs("</tr>\r\n", stream);
> 
>    fflush(stream);
>     return 0;
> }
> 
> 
> 
> 



-- 
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.371 / Virus Database: 267.13.13/197 - Release Date: 9/12/2005




More information about the En-Nut-Discussion mailing list