3
CCS :: View topic - #int_RDA and disable_interrupts() http://ccsinfo.com/forum/viewtopic.php?t=29437&highlight=inte ... 1 от 3 01.3.2007 г. 09:26 FAQ Forum Help Official CCS Support Search Register Profile Log in to check your private messages Log in #int_RDA and disable_interrupts() CCS Forum Index -> General CCS C Discussion View previous topic :: View next topic Author Message GIO Guest #int_RDA and disable_interrupts() Posted: Thu Jan 11, 2007 4:36 am I am playing with my first completed PIC project from some week and I am happy but ....now I would to add rs232 comunication with PC I have already read many post and think that better system is to use #int_RDA for get character from rs232 but I have a function with a disable_interrupts(GLOBAL), this can to be a risk to garbage characters from PC? Code: //-------------------------------- // RS232 receive interrupt #int_RDA void RDA_isr() //-------------------------------- { rcv[len++] = fgetc(PC); } Code: /------------------------ int16 ADC_CONV(int8 chan) //------------------------ { #bit ADGO=0x1f.2 // ADC Status bit #bit ADON=0x1f.0 // ADC module on/off #bit ADIF=0xC.6 // ADC Interrupt Flag bit #bit PEIE=0xB.6 // Peripheral Interrupt Enable #byte ADRESL=0x9E #byte ADRESH=0x1E int8 Tmp; int16 Raw = 0; int16 min = 1023; int16 max = 0; int16 Value; set_adc_channel(CHAN);

CCS _ View topic - #int_RDA and disable_interrupts()

Embed Size (px)

Citation preview

Page 1: CCS _ View topic - #int_RDA and disable_interrupts()

CCS :: View topic - #int_RDA and disable_interrupts() http://ccsinfo.com/forum/viewtopic.php?t=29437&highlight=inte...

1 от 3 01.3.2007 г. 09:26

FAQ Forum Help Official CCS Support Search Register

Profile Log in to check your private messages Log in

#int_RDA and disable_interrupts()

CCS Forum Index -> General CCS C Discussion

View previous topic :: View next topic

Author Message

GIOGuest

#int_RDA and disable_interrupts()Posted: Thu Jan 11, 2007 4:36 am

I am playing with my first completed PIC project from some week and I am happy but ....now I

would to add rs232 comunication with PC

I have already read many post and think that better system is to use

#int_RDA for get character from rs232 but I have a function with a disable_interrupts(GLOBAL),this can to be a risk to garbage characters from PC?

Code:

//-------------------------------- // RS232 receive interrupt #int_RDA void RDA_isr() //-------------------------------- {

rcv[len++] = fgetc(PC);

}

Code:

/------------------------ int16 ADC_CONV(int8 chan) //------------------------ { #bit ADGO=0x1f.2 // ADC Status bit #bit ADON=0x1f.0 // ADC module on/off #bit ADIF=0xC.6 // ADC Interrupt Flag bit #bit PEIE=0xB.6 // Peripheral Interrupt Enable

#byte ADRESL=0x9E #byte ADRESH=0x1E

int8 Tmp; int16 Raw = 0; int16 min = 1023; int16 max = 0; int16 Value;

set_adc_channel(CHAN);

Page 2: CCS _ View topic - #int_RDA and disable_interrupts()

CCS :: View topic - #int_RDA and disable_interrupts() http://ccsinfo.com/forum/viewtopic.php?t=29437&highlight=inte...

2 от 3 01.3.2007 г. 09:26

ADON=1; // 1=ADC module is powered up, 0=ADC module is shut-off and consumes nooperating current delay_us(20); // Add a slight delay here the input capacitor will not be fully charged

for (tmp = 0; tmp < ADC_NUMSAMPLES; ++tmp) { disable_interrupts(GLOBAL); ///<<<<<<<<<<< enable_interrupts(INT_AD);

PEIE=1; // 1=Enables all unmasked peripheral interrupts, 0=Disables all peripheral interrupts

ADIF=0; // 1=ADC completed, 0=ADC is not complete

ADGO=1; // When ADON=1: 1=ADC in progress, 0=not in progress

sleep();

disable_interrupts(INT_AD); enable_interrupts(GLOBAL); //Note that these only need to be enabled at all //if you are intending to use another interrupt.

Value = make16(ADRESH,ADRESL); Raw += Value;

if (value <min> max) max = value;

}

Raw = Raw - (min + max); // tolgo i valori minimo e massimo Raw = Raw / (ADC_NUMSAMPLES - 2 ); // media delle letture

return (Raw); }

Thanks in advance, GIO

TtelmahGuest

Posted: Thu Jan 11, 2007 6:22 am

It'll depend on your chip, baud rate, and processor clock source. Calculate how long an ADC conversion takes. This will depend on the selected ADC divider, clock

rate etc.. On some chips, the master CPU clock can be left running, while the processor is

asleep. If not, serial receive, will not take place at all (it is not disabling the interrupt that will then be the problem, but the fact that the UART clock will be stopped). If the clock can be left

running, then provided the conversion time is less than a character time, there will not be a

problem. As an 'aside', you don't need all your fiddles with direct bit accesses.

read_adc(ADC_START_ONLY), triiggers the ADC to start. read_adc(ADC_READ_ONLY), reads the

return. setup_adc(ADC_ON), tunrs on the ADC, while the same with 'ADC_OFF', turns it off. 'clear_interrupts(INT_AD)', turns off ADIF.

Aso, beware, that sleeping for a short time, may take a lot more time than you think. Check the

oscillator startup times...

Best Wishes

ckielstra

Joined: 18 Mar 2004Posts: 1334Location: The Netherlands

Posted: Thu Jan 11, 2007 7:31 am

Just a thought, do you really need to disable the interrupts during the AD-conversion?

I guess you disable the AD-converter to minimize the noise induced by the processor? But, you are averaging the results, than assuming the induced processor noise is random the noise would

not be visible in the result.

Guest Posted: Thu Jan 11, 2007 10:02 am

Page 3: CCS _ View topic - #int_RDA and disable_interrupts()

CCS :: View topic - #int_RDA and disable_interrupts() http://ccsinfo.com/forum/viewtopic.php?t=29437&highlight=inte...

3 от 3 01.3.2007 г. 09:26

Reality, I have found this ADC_CONV() function on this (or another) forum and used after

adding averaging the results.

I am beginner and I do not know if routine work also if I delete two rows:

disable_interrupts(GLOBAL);

enable_interrupts(GLOBAL);

or better use the simple value = read_adc()

In all case, I add other info on my project:

Code:

#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=PC,errors)

#include <16F877a.h> #device *=16 #device adc=10 #fuses WDT,HS, PUT, NOPROTECT, NOLVP #use delay(clock=10000000)

void main() //-------------------------------- { int8 restart_reason;

restart_reason = restart_cause();

setup_wdt(WDT_2304MS); restart_wdt(); // !!

int_count = INTS_PER_SECOND;

setup_timer_1 ( T1_INTERNAL | T1_DIV_BY_8 ); set_timer1(3036); // = 65536-(0,1/(4*4/10.000.000)) for 100ms

setup_timer_2(T2_DISABLED,0,1);

setup_adc_ports(RA0_RA1_RA3_ANALOG); setup_adc(ADC_CLOCK_INTERNAL);

CLEAR_INTERRUPT(INT_RDA); enable_interrupts(INT_RDA); enable_interrupts(INT_TIMER1); // disable_interrupts(INT_TIMER2); enable_interrupts(global);

Thank to all,

GIO

Display posts from previous: All PostsAll Posts Oldest FirstOldest First Go

CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours

Page 1 of 1

Jump to: General CCS C DiscussionGeneral CCS C Discussion Go

You can post new topics in this forumYou can reply to topics in this forum

You cannot edit your posts in this forumYou cannot delete your posts in this forum

You cannot vote in polls in this forum

Powered by phpBB © 2001, 2005 phpBB Group