Show Posts
Pages: [1] 2 3 ... 7
1  Using Arduino / Programming Questions / Re: Timer1 interrupt debuging on: July 05, 2013, 04:43:58 am
 smiley-cool, problem here, 2 input analog is read , from code @Jack Christensen, the problem is how to separate data from reading input 1 and input 2, i mean to make array or data set for input 1 and input 2.
2  Using Arduino / Microcontrollers / Re: Interrupt execution method on: June 20, 2013, 02:32:49 am
hey use this link its very usefull for using interrupt.
http://www.gammon.com.au/forum/?id=11488
3  Using Arduino / Microcontrollers / Re: Interrupt For Every Pin on: June 20, 2013, 02:29:50 am
here is usefull for you to use interrupt change pin..
Quote
To handle a pin change interrupt you need to:


Specify which pin in the group. This is the PCMSKn variable (where n is 0, 1 or 2 from the table below). You can have interrupts on more than one pin.
Enable the appropriate group of interrupts (0, 1 or 2)
Supply an interrupt handler as shown above
you can read it full from this website.http://www.gammon.com.au/forum/?id=11488.it very useful source  for learning using interrupt
4  Using Arduino / Programming Questions / Re: Timer1 interrupt debuging on: June 14, 2013, 02:02:28 am
wow so fast you got it,i a bit confuse how you make the admux change the input:
Quote
ADMUX = _BV(REFS0) | (++mux & 1);    //flip between mux0 and mux1



there timing for to input is differ about 1000us. is that because of ADC switching time?
i have dig some page and found that arduino cannot read 2 analog input at the same time, arduino need a time to switch the mux channel. there will be some delay and the data we have is not match between to signal within time interval.
5  Using Arduino / Programming Questions / Re: Timer1 interrupt debuging on: June 13, 2013, 09:09:53 pm
wow great work thanks@Jack Christensen. i try it and it really working for me. i manage to get sample with desired interval.  i will try to work on continuous taking sample without stop the time.

 i wonder, instead of taken one input channel , can we make  arduino take sample with 2 or 3 more channel  synchronously?
6  Using Arduino / Programming Questions / Re: Timer1 interrupt debuging on: June 13, 2013, 04:35:43 am
nice work smiley  @Jack Christensen. i got some Q in your code, why are the timer interrupt enable is in loop function not in setup func? is there any effect if we just initialize all timer setting in void setup function.

Code:
void loop(void)
{
       
    cli();
    TCNT1 = 0;                           //clear the timer
    TIMSK1 = _BV(OCIE1B);                //enable timer interrupts
    sei();
    i = 0;
    TCCR1B = _BV(WGM12) | _BV(CS11);     //start the timer, ctc mode, prescaler 8

 why must disable timer when to print the data. if timer stop, then the next 10 sample taken is continue from the stop point or it will reset to new point.
 
Code:
} while (++i < SAMPLE_SIZE);
   
    TIMSK1 = 0;                          //disable timer interrupts
    TCCR1B = 0;                          //stop the timer
   
    //print the data
   
7  Using Arduino / Programming Questions / Re: Timer1 interrupt debuging on: June 12, 2013, 08:10:55 pm
Thanks @Jack Christensen will take Christensen code and an experiment on it.

Quote
but the ADC didn't have to wait for the compare match in order to trigger.  It fired as soon as the interrupt was enabled.

Sorry for asking 1 more about adc. if adc fire as soon interrupt was enable, did the value i will get is in time interval 200us or it just the value at random time when it finish conversion?
8  Using Arduino / Programming Questions / Re: Timer1 interrupt debuging on: June 12, 2013, 07:52:35 pm
Sorry guy,  im confusing with two ISR right now. If i want adc take a reading every 200us, so i must put code to take sample on ISR(TIMER1_COMPB_vect) or in ISR(ADC_vect). which one should work to take a reading. For timer and ADC initialize, did it correct?
what im try to do is like this.

my pseudo code
Code:
void setup(){
#do time int
#do adc int
}

ISR (){        //trigger when== 200us
#  take adcreading[i]; //save in array
  i++
  }

void loop(){
if (i =100){
for(j=0;j<100;j++){
#  print result of adcreading[];
}

9  Using Arduino / Programming Questions / Re: Timer1 interrupt debuging on: June 12, 2013, 03:31:16 am
after i see my timer1 is correct setting, i try to implement with ADC to timer1. Here my code after i digging around for a few day. I try to set up timer1 to 200us work along with ADC. the adc will read analogvalue when timer1 is trigger. But sadly it wont work. What did i make wrong?
Code:
volatile int readValue;


void setup() {
Serial.begin(115200);
delay(100) ; //wait for serial com to ready

//Int timer counter 5kHz
TCCR1A = 0;   //
TCCR1B = 0;   // reset the timer control register
TCNT1 = 0;   // clear counter.
OCR1A = 399;  //compare value for timer
//(frequency speed at 5000Hz with 8 pre scale).
OCR1B = 399; // compare timer to trigger ADC at 5kHz.
TCCR1B |= (1<<CS11); //pre scale set to 8.
TCCR1B |= (1<<WGM12); //turn on CTC mode.
TIMSK1 |= (1<<OCIE1B);  //Timer/Counter Compare Match B interrupt is enabled

//ADC setup
// Since we are using ADC0 here, which corresponds
// with all 5 MUX bits being zero, we don't need to set anything here.

ADMUX  |= (1<< REFS0) ; //ADC ref Volt to AVCC.
ADCSRA |= (1<<ADPS2) | (1<<ADPS1)|(1<<ADPS0); //set pre scale to 128. Speed 125kHz
ADCSRB |= (1<<ADTS2) | (1<<ADTS0); //select timer/counter1 compare match B
ADCSRA |= (1<<ADEN)  //Enable ADC
   |(1<<ADIE) //Enable interrupt
   |(1<< ADATE); // enable auto trigger
 
sei(); //enable global interrupt.

}

ISR(ADC_vect){

ADCSRA |= (1<<ADSC) ; //to start new conversion.
while(ADCSRA & (1<<ADSC)); //wait for conversion is done.
readValue =ADC; // read the full 16-bit ADC value.


}
void loop() {
Serial.println(readValue);
}
10  Using Arduino / Programming Questions / Re: Timer1 interrupt debuging on: June 10, 2013, 07:32:54 pm
@Jack Christensen thank for correcting it. So my setting for the timer1 1 is correct right except for OCR1A must be 399. if serial.print take long timer to executed what other method to see timing in my code?

@tmd3 thanks for idea.  i want to is to take analog reading every 200us. How to set the adc trigger with timer interrupt, can give link for example, im not really understand how to set it.
11  Using Arduino / Programming Questions / Timer1 interrupt debuging on: June 10, 2013, 03:43:48 am
hi all.. i have problem with my code here. i try to set the interrupt to trigger every 200us, but when i do some checking it show 400us instead of 200us as the timer1 is setting.. can anyone help me what is wrong with my setting.

here my code:
Code:
volatile int val;
volatile int isNewVal;
volatile unsigned long time;
unsigned long timer;


void setup() {
 
Serial.begin(115200); //setup serial comm.
delay(500);

noInterrupts(); //disable interrupt first
TCCR1A =0;    // clear timer setting
TCCR1B =0;    // ~~
TCNT1=0;       //~~
OCR1A= 400;         // 16M/8/5000 = 400. Target Freq is 5kHz
TCCR1B |= (1<<WGM12);     //enable ctc mode
TCCR1B |= (1<<CS11);      //setup prescaler by 8.
TIMSK1 |= (1<< OCIE1A);       //enable timer interrupts
interrupts();                  //enable interrupt
}

ISR(TIMER1_COMPA_vect){
 // val = analogRead(A0);
 
  isNewVal=1;
  } 
 
 
void loop() {
    if (isNewVal == 1){
  timer = micros()-time;
  time = micros();
  Serial.println(timer);
    isNewVal =0;
   
   
  }
}

here result that i get from serial monitor
12  Using Arduino / General Electronics / Re: Voltage divider from Ac signal on: June 06, 2013, 03:58:42 am
ok.. my new simulation.. tell me if im wrong..





 smiley


if i analogread the output with arduino. what voltage did i get? is it in Vp-p, vdc or Vrms.  smiley-eek
13  Using Arduino / General Electronics / Re: Voltage divider from Ac signal on: June 05, 2013, 10:45:23 pm
now i get it..after doing simulations i get the result that the output is a straigh line.. here the pic from my simulation

.
so now if i want the sine waveform i have to get it output from transformer not from the rectifier right?
14  Using Arduino / General Electronics / Re: Voltage divider from Ac signal on: June 05, 2013, 09:59:19 pm
u mean by the output of rectifier only dc voltage. not ac volt? so i must get it directly from transformer not from rectifier?
15  Using Arduino / General Electronics / Re: Voltage divider from Ac signal on: June 05, 2013, 07:52:32 pm
owh..sorry for misunderstood. actually i want to get AC waveform from the supply, so i can measured the voltage, current. just like power meter. i thought from transformer i make the rectifier circuit to stabilize it and i can get the smooths signal. SO if i want to get the waveform should i put voltage divider directly to transformer or else.?
Pages: [1] 2 3 ... 7