Go Down

Topic: Vishay output interpreter (Read 616 times) previous topic - next topic

claire

Hello forum goers,

I'm trying to create a code to interpret the output of a Vishay receiver. i.e. code that measures the length of a pulse (but I don't want to use PulseIn). I initially wrote a big long code that would interpret it all for me, but I'm having trouble making it go into the interrupt so I reduced my code down to:

#include <avr/io.h>
#include <avr/interrupt.h>

ISR(TIMER1_CAPT_vect) {
  Serial.print("G");
}

void setup()
{
  Serial.begin(9600);
  pinMode(8, INPUT);
 
  TCCR1A = 0x00;     //not using PWM
  TCCR1B = 0x01;     //no prescaling
  TIMSK1 = _BV(ICIE1); // enable input capture interrupt
}

void loop()
{
  Serial.print("L");
  delay(100); //so we're not overwhelmed with values
}

So that all I'm trying to do is get the program to enter the interrupt and print "G" (I know, I know, shouldn't print from an interrupt) at the moment. Does this seem right? It's only printing me a line of Ls, not a G in sight.
I'm testing it with a 2Hz, 5 V peak to peak square wave signal.

Thanks in advance! I've only just started using Arduino.
Claire

CrossRoads

Pins 2 & 3 are  the hardware interrupt pins, you attach an interrupt to them.
I don't see that happening with your code (but I'm not much into the register stuff either).
What is pin 8 supposed to be doing?

Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

CrossRoads

Here's a collection of the bits I used in an RF remote control - push a button, create an interrupt.

Code: [Select]

//***************************************************
// *  Name:        pin2Interrupt, "ISR" to run when interrupted in Sleep Mode
void pin2Interrupt()
{
  g_flag = 1;
}


Code: [Select]

byte g_flag;

void setup() {
  pinMode(pin2, INPUT);                 // our sleep interrupt pin
  digitalWrite(pin2, HIGH);            //enable internal pullup resistor - pin going low causes interrup
  attachInterrupt(0, pin2Interrupt, LOW);  // ready to be interrupted
}



Code: [Select]

void loop(){

If (g_flag == 0){
Serial.print ('L');
}
else {
detachInterrupt(0);                 //disable interrupts while printing
Serial.print ('G');
g_flag = 0;   // reset the interrupt flag
attachInterrupt(0, pin2Interrupt, LOW);   // ready for next interrupt
}
}


If you can get that working, then you will see a G on each rising edge.
Next you can change it to have the ISR be
g_flag = 1-g_flag;
and not clear g_flag with the serialprint, but hold it,
and let the state will change in the interrupt  1-0-1-0  with each edge.

Then, add stuff to capture the time when the g_flag changes.

Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy