A A A

Electronicfr.com

Home arrow Microcontroleurs et USB arrow Part 2 : How to build a USB thermometer with PIC 18F4550 or 18F2550 20.08.2008

Menu principal

Home
Robotique
Microcontroleurs et Ethernet
Microcontroleurs et USB
Systèmes embarqués
Proposer un circuit

Search

Google
Web
electronicfr


Part 2 : How to build a USB thermometer with PIC 18F4550 or 18F2550

Ecrit par Administrator, le 27-10-2007 12:48
Pages vues 15464    
FRONTPAGE_NO_TRANSLATION_AVAILABLE

On this second part, we are adding a temperature sensor to the circuit described in the first part of this tutorial.


Sensor and schematic

 You can use the very usual LM35 circuit (Datasheet), or many others circuits like MCP9701, TC1047...

The following schematic show how to plug the sensor on our USB experimentation board:

The firmware

We will add some code for analog to digital convertion and temperature calculation in the file user.c
//Lets add includes for ADC and strings manipulations
#include <stdlib.h>
#include <adc.h>
//[...]
// We will write output data in this string
char input_buffer[64];
// [...]
void Exercise_Example(void)
{
int temp;
// [...]  
else if(start_up_state == 3)
{
if(mUSBUSARTIsTxTrfReady())
{
//A0 set in input
TRISAbits.TRISA0 = 1;
memset(output_buffer, '\0', 64);
output_buffer[(6*5)] = '\r';
output_buffer[(6*5)+1] = '\n';
OpenADC(ADC_FOSC_8 & ADC_RIGHT_JUST & ADC_0_TAD,
ADC_CH0 & ADC_INT_OFF & ADC_VREFPLUS_VDD & ADC_VREFMINUS_VSS,
0b1011);
SetChanADC(ADC_CH0);
Delay10TCYx( 50 );
ConvertADC(); // Start conversion
while( BusyADC() ); // Wait for ADC conversion
temp = ReadADC(); // Read result and put in temp
CloseADC(); // Disable A/D converter
temp=temp/7; //Convert in centigrad degrees
itoa(temp, output_buffer);	// Convert to a string        
mUSBUSARTTxRam((byte*)output_buffer,(6*5)+2); 
start_up_state=0;
}
}
}//end Exercise_Example

The value in Celsius degree will be sent threw the USB bus when the button on RB4 will be pressed.
Under windows, you can use the hyperterminal utility (19200bd with a 20MHz cristal) to see the value. Under linux you can use cat /dev/ttyACM0 .

 

[Note] How to use a 18F2550
You can use the source code for 4550 with very few modifications. Just select the appropriate device in the MPLAB configure menu. Change the linker script, and set the configuration bits (like in this picture). Remove any references to port D in io_cfg.h.
Here is a picture of a small prototype using PIC 18F2550:

Next part -> Application: A temperature and pressure monitoring system with PIC 18F4550

Quote this article in website Print Related articles Save this to del.icio.us

Commentaires utilisateurs (1) Fil RSS des commentaires
Commentaires en langue: English (0), French (1)
Posté le karim, le 24-03-2008 13:22, IP 41.226.254.199
1. usb
je cherche un exemple de pic 18f 2550 qui travail sur l'USB de class CDC . si vous avez quelque documentation aidez moi. 
intellah@yahoo.fr 
merci d'avance.
 
» Signaler ce commentaire à l'administrateur
» Répondre à ce commentaire
» Voir les 1 réponse(s)

Ajouter votre commentaire



mXcomment 1.0.5 © 2007-2008 - visualclinic.fr
License Creative Commons - Some rights reserved
 
< Précédent   Suivant >
 
TOP