![]() |
![]() |
![]() |
|
|
|||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
|
|
Thread Tools | Display Modes |
|
|
(permalink) |
|
I’m sampling two AD channels every 1 second inside the ISR. My Xtal is 4 MHz & my AD conversion clock is set for Int RC.
When doing multiple channels there are some timing parameters required. I want to check my codings timing to get best AD results. I want to know what I’m missing in my code or what I have to adjust. Code:
org 0x0004 Interrupt movwf W_Temp ;save W in a Temp swapf STATUS,W ; movwf S_Temp ;save status in a Temp bcf INTCON,T0IF ;reset T0IF int flag decfsz Count,F ;count 100 times to make 1 second goto Exit movlw .100 movwf Count Channel1 bcf ADCON0,3 ;turn on first AD channel (RA0) call Del_Hold ;make a 40 uS delay after changing the channel call Sample ;check the AD value & get a sample bcf STATUS,C rrf ADLResult,F ;make the value divide by 2 call BCD ;make the value into decimals call BCD_Split1 ;convert into segment digits 1 & 2 Channel2 bsf ADCON0,3 ;turn on second AD channel (RA1) call Del_Hold ;make a 40 uS delay after changing the channel call Sample bcf STATUS,C rrf ADLResult,F ;make the value divide by 2 call BCD ;make the value into decimals call BCD_Split2 ;convert into segment digits 3 & 4 Exit swapf S_Temp,W movwf STATUS swapf W_Temp,F ;swap to file swapf W_Temp,W ;swap to work retfie ;*************** ;AD subroutines ;*************** Sample clrf ADLResult ;clear the result bsf ADCON0,GO ;start convertion btfsc ADCON0,GO goto $-1 bsf STATUS,RP0 ;switch to bank1 movf ADRESL,W bcf STATUS,RP0 ;back to bank0 movwf ADLResult ;place the 8 bit AD result return Del_Hold movlw .12 ;40 uS holding delay movwf Hold decfsz Hold,F goto $-1 return |
|
|
|
|
|
|
(permalink) |
|
I would suggest that's a very poor method?, it's best to keep ISR's as short as possible - use the ISR to set a flag, and check for the flag in the main program.
|
|
|
|
|
|
|
(permalink) |
|
It's really not a good idea for calling any delay in the ISR. Use interrupt to count, but not to use interrupt to perform ADC and delay.
What PIC are you using? Why do you need 40 us holding time which is so long?
__________________
Superman returns..
|
|
|
|
|
|
|
(permalink) | |
|
Quote:
Mike. |
||
|
|
|
|
|
(permalink) |
|
How high can it be? According to the datasheet of 16F88, the acquisition time with the source impedance of 10 k
__________________
Superman returns..
|
|
|
|
|
|
|
(permalink) |
|
My point was that 40uS is not a long time and will definitely not cause any problems with the OP's code.
One problem that I do see is the lack of ADC initialisation. I assume that this is deliberate as there is no way that code will even build. Maybe Suraj should post his complete code. Mike. |
|
|
|
|
|
|
(permalink) |
|
Yes, I agree that. Besides, it is two samples in 1 second, and it won't cause any problem.
Since 4 MHz is used, why RC is selected? Unless you want to perform ADC in sleep.
__________________
Superman returns..
|
|
|
|
|
|
|
(permalink) | |
|
HI I'm here here is my initialization part.
Code:
Init bsf STATUS,RP0 clrf TRISB clrf TRISD movlw b'00000011' ;make RA0,RA1 inputs (sensors) movwf TRISA movlw b'10001110' ;result right justified,Vref+=Vdd,Vref-=Vss movwf ADCON1 bcf STATUS,RP0 movlw b'11000001' ;ADON,Int RC movwf ADCON0 Hi Mike ! I just want to ask your own idea what precautions do you take to minimize the bubble effect?I got some answers through past thread but I like your comments too. Quote:
|
||
|
|
|
|
|
(permalink) |
|
Hi,
That's what I was wondering. Is there any reason for you to use the internal RC as the clock source for ADC? According to the datasheet, for higher oscillation frequency (more than 1 MHz), internal RC is only recommended for performing ADC during the sleep. So you can just derive from your fosc. Besides, you can get the device into sleep just for the ADC operation, such as Code:
bsf ADCON0, GO sleep *EDIT: Around 12 Tad for the conversion. If internal RC is used, Tad is 4 µs, so the total conversion time is around 48 µs which won't affect the seven segment display.
__________________
Superman returns..
Last edited by bananasiong; 23rd January 2008 at 03:39 AM. |
|
|
|
|
|
|
(permalink) |
|
Hi bananasiong thanks for that tip. I’ll try that also.
After calling few multiplexing routines in the main program I’ll put the PIC to sleep & take the latest readings & update the digits inside the ISR. But when returning from ISR will it comes to the sleep line? |
|
|
|
|
|
|
(permalink) |
|
No, it goes the instruction after the sleep. But for a good practice add a nop after the sleep.
__________________
Superman returns..
|
|
|
|
|
|
|
(permalink) | |
|
Quote:
|
||
|
|
|
|
|
(permalink) |
|
hi suraj..
how's ur project ? did u manage to get rite source code? i'm having same prob like. i need u help. i need know hw program two input two analogue signal. thank u |
|
|
|
|
|
|
(permalink) | |
|
Quote:
__________________
Superman returns..
|
||
|
|
|
|
|
(permalink) |
|
bananasiong is it possible to sample two signals from external ADC at the same time on a PIC18XXXXXXX?
__________________
Simplicity rules Good enought - its perfect ?? 2 Gig of free online backup space Are you a Chemist? |
|
|
|
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Latest |
| The Oscilloscope | ElectroMaster | Electronic Theory | 12 | 3rd February 2008 01:45 PM |
| 3 Inputs & 3 Outputs Coding problem | Suraj143 | Micro Controllers | 16 | 17th August 2007 04:19 AM |
| Hardwiring multiple switches to common inputs | Franknstein | Electronic Projects Design/Ideas/Reviews | 7 | 25th April 2007 11:02 AM |
| PIC A/D Sampling multiple inputs | NJ Roadmap | Micro Controllers | 10 | 21st February 2007 01:53 AM |
| Multiple Units Transmission Coding | Spasm | Micro Controllers | 4 | 18th March 2004 08:52 AM |