View previous topic :: View next topic |
Author |
Message |
edbfmi1
Joined: 18 Jul 2006 Posts: 103
|
PIC12F675 ADC issues |
Posted: Tue Feb 12, 2013 4:59 pm |
|
|
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: 19518
|
|
Posted: Wed Feb 13, 2013 1:37 am |
|
|
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
|
|
Posted: Wed Feb 13, 2013 11:00 am |
|
|
Thank you so much Ttelmah. I can't believe I did that. Maybe retirement isn't such a bad idea after all. |
|
|
|