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

PIC12F675 ADC issues

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



Joined: 18 Jul 2006
Posts: 103

View user's profile Send private message

PIC12F675 ADC issues
PostPosted: Tue Feb 12, 2013 4:59 pm     Reply with quote

Hello I posted yesterday about a problem I am having with the ADC on the PIC2F675.

I downloaded the latest version of PCM (V4.140) today and simplified my code in order to start with a clean slate but I am still not having any luck getting this to work.

Here is the project:

I have a simple board that will cycle through 3 outputs. I want to be able to adjust the cycle rate using a switch that comes in on an analog input that will supply 1,2,3 or 4 volts for the 4 different cycle rates.

I tested the output flashing sequence with a fixed FlashRate of 250ms but when I add the simple ADC routing before the while(1==1) loop to get the flashrate as set by the analog input the system will not work.

Does anyone see the error of my ways on the ADC part of the program?

Thanks for any and all help.
Code:

/* This program is for the the "C" choir light control
PORTA.0 = Analog Input  - 1V, 2V, 3V, 4V (Used to select Chase rate)
PORTA.1 = Digital Output - Output2
PORTA.2 = Digital Output - Output1
PORTA.3 = MCLR
PORTA.5 = Digital Output - Output3
*/

#include <12f675.h>
#device adc=10

#fuses NOWDT,PROTECT,MCLR,PUT,NOBROWNOUT,INTRC_IO
#use delay(clock = 4000000)

#define Output3 PIN_A5
#define Output2 PIN_A1
#define Output1 PIN_A2

int8   FlashRate;
int16   temp_adc;

void main()
{
   
   output_low(Output1);
   output_low(Output2);
   output_low(Output3);
   setup_adc(ADC_CLOCK_DIV_8);
   setup_adc_ports(sAN0);
   set_adc_channel(sAN0);
   delay_ms(100);
   temp_adc = read_adc();
   FlashRate = temp_adc/5;   
   
   while (1==1)
   {
      output_low(Output3);
      output_high(Output1);
      delay_ms(FlashRate);
      output_low(Output1);
      output_high(Output2);
      delay_ms(FlashRate);
      output_low(Output2);
      output_high(Output3);
      delay_ms(FlashRate);
   }
}   
Ttelmah



Joined: 11 Mar 2010
Posts: 19499

View user's profile Send private message

PostPosted: Wed Feb 13, 2013 1:37 am     Reply with quote

One error - probably all that is wrong:
Code:

set_adc_channel(sAN0);

//should be

set_adc_channel(0);


The set_adc_channel function accepts a channel number, not the #defined constants....

Best Wishes
edbfmi1



Joined: 18 Jul 2006
Posts: 103

View user's profile Send private message

PostPosted: Wed Feb 13, 2013 11:00 am     Reply with quote

Thank you so much Ttelmah. I can't believe I did that. Maybe retirement isn't such a bad idea after all.
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