|
|
View previous topic :: View next topic |
Author |
Message |
Guest
|
problems with the current setup_adc_ports() |
Posted: Mon Aug 20, 2007 8:00 am |
|
|
CCS complier is not using the setup_adc_ports () function correctly. In order for it to work i need to download version 3.249. Does anyone have an idea how to fix the code so that I can use the below code with my current version.
#include <12f683>
#device ICD=TRUE
#fuses intrc_io,nomclr,nowdt,noprotect
#use delay(clock=2000000)
#use rs232(debugger)
#define AD_CHANNEL_POT 0
#define GREEN PIN_A2
#define YELLOW PIN_A5
#define RED PIN_A4
#define LED_ON(x) output_low(x)
#define LED_OFF(x) output_high(x)
void main(void)
{
int32 _fixed(2) volt;
int8 adc;
setup_adc(ADC_CLOCK_INTERNAL);
setup_adc_ports(AN0_ANALOG);
set_adc_channel(0);
while(TRUE)
{
//use read_adc() to read the pot value, store to the variable 'adc'
adc = read_adc();
//Here we convert the adc value into a fixed point decimal representing
//the voltage in a range from 0.00 to 5.00
volt = (int16)adc; //0-255 becomes 0-25500
volt *= 5;
volt /= 2.55;
//Display the voltage on the debug monitor. We use printf() and the
//escape character for fixed point decimal (%w)
printf("Volt: %w (%x)\r\n", volt, adc);
LED_OFF(GREEN);
LED_OFF(YELLOW);
LED_OFF(RED);
//turn on green LED if voltage is over 1.25
if (volt <= 1.25)
LED_ON(RED);
//turn on yellow LED if voltage is over 2.5
if (volt <3> 1.25)
LED_ON(Yellow);
//turn on red LED if voltage is over 3.75
if (volt >= 3.75)
LED_ON(Green);
delay_ms(250);
}
} |
|
|
Ttelmah Guest
|
|
Posted: Mon Aug 20, 2007 8:28 am |
|
|
What 'current version'.....
We are not telepathic.
What doesn't work about it?.
Best Wishes |
|
|
Roland Guest
|
setup_adc_ports does not write ADSEL |
Posted: Mon Aug 20, 2007 9:37 am |
|
|
We had problems using setup_adc_ports() too.
Compiler 4042 to 4051.
Compiling for 16f886
Sample:
setup_adc_ports(sAN0|sAN1|sAN3);
.. makes (this is from 4050)::
04F2: BSF 03.5
04F3: BSF 03.6
04F4: MOVF 09,W
04F5: ANDLW C0
04F6: MOVWF 09
04F7: BCF 03.6
04F8: BCF 1F.4
04F9: BCF 1F.5
04FA: MOVLW 0B
04FB: MOVWF 00
but should (this is from 4038):
04F2: BSF 03.5
04F3: BSF 03.6
04F4: MOVF 09,W
04F5: ANDLW C0
04F6: MOVWF 09
04F7: BCF 03.6
04F8: BCF 1F.4
04F9: BCF 1F.5
04FA: MOVLW 00
04FB: IORLW 0B
04FC: BSF 03.6
04FD: MOVWF 08
So ADSEL are not written.
Regards,
Roland |
|
|
Ttelmah Guest
|
|
Posted: Mon Aug 20, 2007 10:30 am |
|
|
He is on a 12F683, and the current version, correctly accesses port 9F, and sets the specified bits on it. Hence my question 'what compiler version'...
The alternative 'setup_port_a' function, also does the same, as does the manual version:
Code: |
#byte ANSEL=0x9F
#define setup_adc_myself(x) ANSEL=(ANSEL&0x70)|(x)
|
Best Wishes |
|
|
|
|
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
|