Ram Prasadh
Member level 2
- Joined
- Feb 16, 2011
- Messages
- 51
- Helped
- 2
- Reputation
- 4
- Reaction score
- 2
- Trophy points
- 1,288
- Activity points
- 1,725
Your code should be something like this.
Code:ADCON0bits.GO = 1; while(ADCON0bits.GO); ADCON0bits.ADON = 0;
Can you post yout hex and cof files? Check my last post it is updated.
Waseem is right. What is the duration of each interrupt caused due to timer?
//Timer0
//Prescaler 1:1; TMR0 Preload = 15535; Actual Interrupt Time : 10 ms
//Place/Copy this part in declaration section
void InitTimer0(){
T0CON = 0x88;
TMR0H = 0x3C;
TMR0L = 0xAF;
GIE_bit = 1;
TMR0IE_bit = 1;
}
void Interrupt(){
if (TMR0IF_bit){
TMR0IF_bit = 0;
TMR0H = 0x3C;
TMR0L = 0xAF;
//Enter your code here
}
}
Compile the code I am sending and send me the hex and cof files.
See the attached image. I am getting this value for your code and ADC I/P 2.5V
See my last post. It's updated.I have used your code in the simulation. I will simulate it with my code and see and reply soon.
I checked with both the codes, yours and mine. I am getting 0x1FF or 511 for 2.5v and 0x3FF or 1023 for 5v which is right.
For 2.5v your ADRESH = 01111111 and ADRESL = 11000000
For 5v your ADRESH = 11111111 and ADRESL = 11000000
SO your readings will be 0111111111 and 1111111111 {because you have chosen left justified)
So it is 0x1FF and 0x3FF
#include<htc.h>
void interrupt isr(void);
void interrupt isr(void)
{
if(TMR0IF) {
TMR1IF = 0;
ADCON0bits.GO = 1;
while(ADCON0bits.GO);
ADCON0bits.ADON = 0;
PORTD = ADRESH;
PORTC = ADRESL;
TMR1H=0X3C;
TMR1L=0XAF;
}
}
void main()
{
unsigned int result =0;
TRISA = 0XFF;
TRISC = 0x00;
TRISD = 0X00;
PORTD = 0X00;
PORTA = 0X00;
PORTC = 0x00;
ADCON0 = 0x01;
ADCON1 = 0x0E; // Channel AN0 selected
ADCON2 = 0X3E; //Fosc/64 with time delay of 20*Tad
T0CON = 0X00;
PEIE = 0x01;
TMR0IE = 0x01;
GIE = 0x01;
TMR0H = 0X3C;
TMR0L = 0XAF;
TMR0IF = 0x00;
TMR0ON = 0x01;
while(1);
}
#include<htc.h>
void interrupt isr(void);
void interrupt isr(void)
{
ADON = 1;
ADRESH = 0X00;
ADRESL = 0X00;
ADFM = 1;
TMR1ON = 0;
if(TMR1IF) {
TMR1IF = 0;
ADCON0bits.GO = 1;
while(ADIF == 0);
ADCON0bits.ADON = 0;ADIF = 0;
PORTD = ADRESH;
PORTC = ADRESL;
TMR1ON = 1;
TMR1H=0XEF;
TMR1L=0XFA;
}
}
void main()
{
unsigned int result =0;
TRISA = 0XFF;
TRISC = 0x00;
TRISD = 0X00;
PORTD = 0X00;
PORTA = 0X00;
PORTC = 0x00;
ADCON0 = 0x00;
ADCON1 = 0x0E; // Channel AN0 selected
ADCON2 = 0X3E; //Fosc/64 with time delay of 20*Tad
T1CON = 0X00;
PEIE = 0x01;
TMR1IE = 0x01;
GIE = 0x01;
TMR1H = 0XFF;
TMR1L = 0XFA;
TMR1IF = 0x00;
TMR1ON = 0x01;
while(1);
}
Zip and post your proteus .dsn file. What value of Pot are you using?
I have the code three threads back... I have made the settings.... Have a look please...(I am using a pic18f4550)The problem is in your code. Post your code and hex file Have you done the ADCON1 settings? Have you made the TRISC and TRISD as 0X00?
Can you send the hex file of your code? I used your .dsn file and my code. I am getting 0x1FF for 2.5v.
Maybe you compiled the code for 8MHz. Change the clock for mcu and set it to 8 MHz in Proteus. You will get the right value.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?