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.

16F88 ADC, Simulation w/ SourceBoost IDE

Status
Not open for further replies.

adamthole

New Member
Hello,

I was just curious if I am doing something wrong with the code or simulator, or if the simulator just cannot simulate what I am trying to do? I am using SourceBoost IDE to program and simulate.

I am new to PIC and have been trying things out on the simulator to get better at it. One thing I am trying to learn right now is how to read ADC values. I downloaded evandude's adc code for the pic 16f88 and modified it slightly:

//////Begin Code///////
#include <system.h>
#pragma DATA 0x2007, 0x3F50//_INTRC_IO & _WDT_OFF & _LVP_OFF

//important bits in SFR's for ADC, UART, and interrupt.
volatile bit go @ ADCON0.GO;
volatile bit gie @ INTCON.GIE;
volatile bit rcie @ PIE1.RCIE;
volatile bit peie @ INTCON.PEIE;
volatile bit rcif @ PIR1.RCIF;
volatile bit trmt @ TXSTA.TRMT;


char data_in;
bit newdata;

//Function: Reads one value from the ADC
//Returns: most significant byte of result
inline char adc_read()
{
go = 1;
while (go);
return adresh;
}

void main()
{
//*********************//
// configure I/O ports //
//*********************//
portb = 00000000b;
trisb = 11111111b; //0 = Output, 1 = Input
porta = 00000000b;
trisa = 11111111b; //0 = Output, 1 = Input

//***************//
// configure ADC //
//***************//

osccon = 01110000b; //internal oscillator @ 8MHz
cmcon = 00000111b; //comparators off
ansel = 00000001b; //AN0 on (RA0)
adcon1 = 00000000b; //left justified, fosc/2 clock, Vdd & Vss ref voltages
adcon0 = 00000101b; //set to AN0, ADC operating

char adcval,temp;

while(1)
{
temp=adc_read();
delay_ms(5);
}
}
/////END CODE/////

I run the program, put XX voltage on pin RA0 with the Variable PSU and I watch temp. Temp is always 0. When I step through the program it hangs when it goes to function adc_read(). The simulator apparently is not clearing the go bit when it gets a value.

I have modified the adc_read() so it isn't in the infinite loop and temp still remains 0 all the time.

Am I doing something wrong or was the simulator just not made for what I am doing?

I couldn't get the original code to work correctly, available:

http://www.eegeek.net/electronics/tutorials/PIC/adctest.c


Thanks
 
I got my answer from the SourceBoost Forums. Just in case anyone cares, the ADC simulation only supports the 16F877, so all I had to do was change the chip type to 16F877 instead of 16F88, and it worked.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top