Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to take 10samples per second of an input in MIKROC?

Status
Not open for further replies.

swethamenon

Member level 4
Member level 4
Joined
Sep 12, 2012
Messages
70
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Visit site
Activity points
1,745
Im planning to do project in MIKROC..dc energymeter..
For that i plan to take 10samples per sec of voltage and current and want to take average of that..is it possible in MIKROC?

im new to this..what to do to get this?
 

Use a for loop which loops from 0 to 9 and each time it should assign the adc value to a array with 10 elements. finally add the 10 elements and divide it by 10 to get the average value.
 

Use a for loop which loops from 0 to 9 and each time it should assign the adc value to a array with 10 elements. finally add the 10 elements and divide it by 10 to get the average value.

For loop works here??
And how to check whether time is 1sec?wanna take 10 samples in 1second
 

Im planning to do project in MIKROC..dc energymeter..
For that i plan to take 10samples per sec of voltage and current and want to take average of that..is it possible in MIKROC?

im new to this..what to do to get this?

you have to need for .1 second timer and timer interrupt .
 

You should be able to implement a timer interrupt and ISR which can be configured to start an ADC every tenth of a second.

An interrupt and ISR also can be used to store each conversion value upon completion.

Effective use of interrupts and ISRs should allow the code to perform the required tasks on the ADC values in between handling the interrupts.

BigDog
 

You should be able to implement a timer interrupt and ISR which can be configured to start an ADC every tenth of a second.

An interrupt and ISR also can be used to store each conversion value upon completion.

Effective use of interrupts and ISRs should allow the code to perform the required tasks on the ADC values in between handling the interrupts.

BigDog

In MikroC how to start timer for 1sec and use timer interrupt??
Can give example?? Or can explain with my program??
 

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
  }
}

 

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
  }
}


Im usinng PIC16.Is dis code works in the MikroC??
Im nt using MPLAB..actually im new to PIC..thiss timer section i wanna detail idea..
How it's do in Mikro C?
 

My code generates 10 ms interrupt. So, you have to use a counter in the interrupt routine. The counter will increment on every interrupt. So, on 100th count you will set a flag in interrupt routine and then in the main function you will check if the flag is set and if the flag is set you will take a sample of adc and clear the flag. The process repeats every 100 ms. After you get all the 10 samples take the average of it.

As you are using mikroC Compiler you can find online book about PIC Microcontrollers at mikroE website. See timer related info in that.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top