CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Problem with pic12f - Software or hardware?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
matheusmestres28



Joined: 30 Apr 2013
Posts: 20

View user's profile Send private message

Problem with pic12f - Software or hardware?
PostPosted: Mon May 13, 2013 1:43 pm     Reply with quote

Hello guys, I'm using pic12f1822 and an accelerometer in one of my applications and having some problems. Pic12f1822 isn't an available device in proteus, so I'm using pic12f683 to simulate my circuit and check if there is something wrong with my code or hardware. I had already built the circuit on the breadboard with 1822 and didn't worked, and I guess it's a software problem, maybe something with the serial communication settings. Can anyone help me??

Proteus points this error: "ADC conversion started before wait time has expired following previous conversion or channel change".

Code:
#include <12f683.h>
#device   adc=10

#FUSES NOWDT, INTRC, NOMCLR                   

#use delay(clock=4000000)
#use rs232(baud=9600,xmit=PIN_A3)

float vx,ax,vy,ay,vz,az;

void printaccel(char ca,float a)
{
  printf("A aceleracao no eixo %c e': %f \n\r",ca,a);
}

void main() {
   set_tris_a(0b00011000);
   setup_adc_ports(ALL_ANALOG);
   setup_adc(ADC_CLOCK_INTERNAL);

   while(TRUE){
            set_adc_channel(0);
            delay_us(10);       
            vx = read_adc();
            vx = vx*0.0048875855327468;
            ax = (vx-1.65)*12.25;   
            printaccel('x',ax);
            delay_ms(1000);
       
            set_adc_channel(1);
            delay_us(10);       
            vy=read_adc();
            vy = vy*0.0048875855327468;
            ay = (vy-1.65)*12.25;
            printaccel('y',ay);
            delay_ms(1000);
         
            set_adc_channel(2);
            delay_us(10);       
            vz=read_adc();
            vz = (vz*0.0048875855327468);
            az = (vz-1.65)*12.25;
            printaccel('z',az);
            delay_ms(1000);
   }

}


Proteus circuit is in the link below:

http://img600.imageshack.us/img600/7231/simulationp.png[/url]
gpsmikey



Joined: 16 Nov 2010
Posts: 588
Location: Kirkland, WA

View user's profile Send private message

PostPosted: Mon May 13, 2013 2:18 pm     Reply with quote

Probably the best thing to do is get your hands on some real parts and test your circuit out. For many cases, Proteus seems to create more problems than it solves - see this link for more info:
http://www.ccsinfo.com/forum/viewtopic.php?t=47549

Especially in the area of fuses and timing, Proteus seems to miss (or ignore) the correct settings. I would double check the delay settings and A/D converter clock settings in the spec sheet - those can sometimes take a bit to make sure you have the right ones and if you don't have the A/D converter clock selected correctly, things don't work as expected (as I discovered myself some time ago Embarassed )

mikey
_________________
mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3
temtronic



Joined: 01 Jul 2010
Posts: 9243
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon May 13, 2013 2:44 pm     Reply with quote

With respect to real hardware...
You're using a 5 volt PIC...is the accelerometer rated for 5 volts?
Which mfr/make/model ? Having 3 analog outputs is 'rare', most are digital...

Use 3 pots instead of accel unit...makes it easy to debug code/hardware issues.


hth
jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19538

View user's profile Send private message

PostPosted: Mon May 13, 2013 2:57 pm     Reply with quote

Screaming problem is the serial pin....

A3, is _input only_.

Best Wishes
matheusmestres28



Joined: 30 Apr 2013
Posts: 20

View user's profile Send private message

PostPosted: Wed May 15, 2013 2:27 pm     Reply with quote

temtronic wrote:
With respect to real hardware...
You're using a 5 volt PIC...is the accelerometer rated for 5 volts?
Which mfr/make/model ? Having 3 analog outputs is 'rare', most are digital...

Use 3 pots instead of accel unit...makes it easy to debug code/hardware issues.


hth
jay


Actually, the accelerometer is in a small board, which contains a Vin pin (3.3V to 16V). The circuit has an internal voltage regulator to 3.3V
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed May 15, 2013 2:36 pm     Reply with quote

Quote:

Proteus points this error: "ADC conversion started before wait time has
expired following previous conversion or channel change".

If you would simply download the 12F683 data sheet, and go to the
chapter on ADC and read the section on Acquisition requirements, and
look at their sample calculation and the result, then you would instantly
see the problem with your code and find the answer.
matheusmestres28



Joined: 30 Apr 2013
Posts: 20

View user's profile Send private message

PostPosted: Wed May 15, 2013 2:43 pm     Reply with quote

Ttelmah wrote:
Screaming problem is the serial pin....

A3, is _input only_.

Best Wishes


I have a doubt here.. PIN_A3 = GP3 or AN3??

One of my friends in lab told me PIN_A3 = AN3.

In pic 12f683 datasheet, AN3 = GP4 = I/O port, but GP3 = MCLR = input only.

Which of these is the correct one??

tyty
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Wed May 15, 2013 2:43 pm     Reply with quote

yes the adc problem is very clear,
as is the RS232 issue.

the amount of floating point, repeated code , is an awfully full load
for such a small memory model pic.

if you MUST use floating point (which i deeply DOUBT)
ccs does a very good job with function calls and could save much
memory for you.
matheusmestres28



Joined: 30 Apr 2013
Posts: 20

View user's profile Send private message

PostPosted: Wed May 15, 2013 2:49 pm     Reply with quote

PCM programmer wrote:
Quote:

Proteus points this error: "ADC conversion started before wait time has
expired following previous conversion or channel change".

If you would simply download the 12F683 data sheet, and go to the
chapter on ADC and read the section on Acquisition requirements, and
look at their sample calculation and the result, then you would instantly
see the problem with your code and find the answer.


ok, I've already read it, but I'm going to read it again. My english isn't that good, so I must have misread something
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed May 15, 2013 2:58 pm     Reply with quote

I think I discovered the problem. There are two versions of the 12F683
data sheet that pop up on Google. (Assuming Google is used to find them).

In the "b" version of the data sheet, in 9.2 A/D Acquisition Requirements,
it shows Tacq = 19.72 μs.

In the "d" version, Microchip has changed it. Now Tacq = 4.67 us.

So your code would meet the spec for the "d" version, but it appears
that the Proteus model was likely made based on the "b" version value.
You can test this by changing your delay_us() statements after the A/D
channel change to be 20 us.

This likely explains the Proteus issue, but here I've violated our
belief on this forum that we should not be solving Proteus problems.
matheusmestres28



Joined: 30 Apr 2013
Posts: 20

View user's profile Send private message

PostPosted: Mon May 20, 2013 12:55 pm     Reply with quote

PCM programmer wrote:
I think I discovered the problem. There are two versions of the 12F683
data sheet that pop up on Google. (Assuming Google is used to find them).

In the "b" version of the data sheet, in 9.2 A/D Acquisition Requirements,
it shows Tacq = 19.72 μs.

In the "d" version, Microchip has changed it. Now Tacq = 4.67 us.

So your code would meet the spec for the "d" version, but it appears
that the Proteus model was likely made based on the "b" version value.
You can test this by changing your delay_us() statements after the A/D
channel change to be 20 us.

This likely explains the Proteus issue, but here I've violated our
belief on this forum that we should not be solving Proteus problems.


Thank you very much man, I'm sorry for the off topic question, but it was a problem related to ccs and I thought here was the best place to ask for it.

Really, thank you very much!!
matheusmestres28



Joined: 30 Apr 2013
Posts: 20

View user's profile Send private message

PostPosted: Mon May 20, 2013 1:13 pm     Reply with quote

ohh, btw, it worked fine when I did what PCM says, changed xmit to PIN_A4 and redefined my fuses to intrc_io instead of intrc only.

Now I'm going to try it on 12f1822.

Thank you very much guys
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group