I want to know whether you are using PIC16 or PIC18 before writing the timer routine.
This is the code for PIC16 4 MHz 10ms Timer. To get 100ms you have to use a counter which counts on every 10 ms timer interrupt overflow. If the count becomes 100 then it means 100 * 10 ms = 1000 ms = 1 sec. You have to take ADC samples on every 100th count. For 1000 counts you will have 10 samples of adc. take average of 10 samples and you will have the reault.
Code C - [expand] |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
| //Timer0
//Prescaler 1:64; TMR0 Preload = 97; Actual Interrupt Time : 9.986 ms
//Place/Copy this part in declaration section
void InitTimer0(){
OPTION_REG = 0x85;
TMR0 = 97;
INTCON = 0xA0;
}
void Interrupt(){
if (TMR0IF_bit){
TMR0IF_bit = 0;
TMR0 = 97;
//Enter your code here
}
} |