Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

ADC does't work

Status
Not open for further replies.

Tymoty

New Member
Hi, I try convert voltage from MMA7260Q and show on lcd but it doesn't work. this is my code

g1=0;
g2=0;
ADCON0bits.ADON=1;
_asm NOP _endasm
_asm NOP _endasm
ADCON0bits.GO=1;
ADCON0bits.CHS0=0;

while(ADCON0bits.GO!=0);
osaX=(ADRESH*256) + ADRESL;

ADCON0bits.ADON=1;
_asm NOP _endasm
_asm NOP _endasm
ADCON0bits.GO=1;
ADCON0bits.CHS0=1;

while(ADCON0bits.GO!=0);
osaY=(ADRESH*256) + ADRESL;
PutMessage((rom char*)"\x16\x0\x8 X:");
PutMessage(osaX);
PutMessage((rom char*)"\x16\x0\x24 Y:");
PutMessage(osaY);
}

and before this in main.c

ADCON0=0x00;
ADCON1=0x0D;
ADCON2=0x95;

and on senzor is voltage about 1,65V(axes x,y) and when i connect mcu voltage is cca 0,2V. i don't know why
 
Assuming you are using my GLCD code, you have a few problems here. The PutMessage routine only works with strings that are stored in ROM, your 0azX is not a string and is not stored in ROM. The way to fix this is to write a new function that will print an integer.

A simple version would be,
Code:
void PutInt(unsigned int num){
    PutChar((num/1000)%10+0x30);
    PutChar((num/100)%10+0x30);
    PutChar((num/10)%10+0x30);
    PutChar((num)%10+0x30);
}

I have not checked your ADC code but it looks like you don't leave enough acquisition time.

Mike.
 
adc 10bit 1010110101
ADRESH*256 + ADRESL = ?
xxxxxx10 in adresh = 2 = 2*256 = 512
10110101 in adresl = 181 + adresh "512" = 693
so 10 bit adc result from 1010110101 = 693


Csaba
 
Thank you pommie, your code running great. I had mystake in configuration of trisa (i use ra0 and ra1 and i had ra6 and ra7).

and pommie I hope that I can use your glcd routine. I use this for my school project and of course I write you like author. but I need some info about you, I can't write to my project - routine from some forum from pommie :)
thank you
 
Feel free to use my code, it is in the public domain and so that should make it acceptable. If you have any problems with citation then I can give you additional information.

Mike.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top