How to generate a 125kHz square wave and read values at every 4us or less?

Go To Last Post
58 posts / 0 new

Pages

Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi there,

I want to generate a 125kHz square wave and read at every 4 us or less say 2 us. I m not sure if the below program is generating that square wave. How do I check it?

 

 


********************************/
#include <stdio.h>// for verbose debugging using sprintf
#include <avr/io.h>
#include <avr/interrupt.h>
//#include "TimerOne.h"
//#include "Timer.h"
#include "PWM.h"

#define icpPin 8 //ICP input pin on arduino - DATA IN HERE.
#define pwmoutPin 11        // OCR1A pin on arduino
//#define outPin 9        // output pin that will shadow the input, can be monitored with a scope

volatile uint8_t rising;                      

unsigned long currentMicros;
unsigned long previousMicros;
unsigned long elapsedMicros;
unsigned long Period = 8000000UL; // overall period
// pick the high time, calculate the low time from what's left
unsigned long highPeriod = 4000000UL; // microseconds, x 2 = 10mS = 100 Hz
// probably best if times are increments of 4uS to match up with micros()
unsigned long lowPeriod; // microseconds,  set to = Period - highPeriod in setup()                       

byte highTime;

// some variables to help see that something is happening in the interrupt handlers
volatile unsigned int Value;     // this stores the current ICR1 value

volatile unsigned int Overflows;
volatile unsigned int PulseCount;

unsigned long duration;

char in_buffer[800];
short i;

/* Overflow interrupt vector */
ISR(TIMER2_OVF_vect){                 // here if no input pulse detected
  Overflows++;                       // incriment overflow count
}

/* ICR interrupt vector */
ISR(TIMER2_CAPT_vect){
  TCNT1 = 0;                            // reset the counter
  OCR1B = 0;                            //data

  TCCR1B ^= (1<<ICES1);                 // toggle bit value to trigger on the other edge

  if(bit_is_set(TCCR1B, ICES1)){
    catchRisingEdge();
    Value = OCR1B;
    digitalRead(pwmoutPin);
  }
   else{
    catchFallingEdge();
    Value = OCR1B;
    digitalRead(pwmoutPin);
    PulseCount++;
   }

}

void setup() {
 Serial.begin(9600);

 DDRB |= (1<<PINB5)|(1<<PINB6); //OC1A and OC1B on arduino Pin 11 and Pin 12.

 pinMode(11, OUTPUT);//2MHz carrier generated here
 pinMode(8, INPUT_PULLUP);

 

 //USE FAST MODE TO ENABLE DOUBLE BUFFERING - GIVES A GLITCH FREE OUTPUT

 TCCR1A = (1<<COM1A1)|(0<<COM1A0)|(1<<COM1B1)|(0<<COM1B0)|(1<<WGM11)|(1<<WGM10);
 TCCR1B = (1<<ICNC1)|(1<<ICES1)|(1<<WGM13)|(1<<WGM12)|(0<<CS12)|(1<<CS11)|(0<<CS10);  //250kHz; prescaler 64; Set to Fast PWM Mode - 8 bit; enable noise canceller; enable input capture
 OCR1A = 30000;
 OCR1B = 0;

 TIMSK1 = (1<<ICIE1)|(1<<TOIE1);                       // enable input capture interrupt for timer// enable overflow interrupt to detect missing input pulses 

 DDRB |= (1<<PINB4);
 pinMode(10, OUTPUT); //125kHz carrier here
 TCCR2A |= (1<<COM2A1)|(0<<COM2A0)|(1<<WGM21)|(1<<WGM20);
 TCCR2B |= (1<<WGM22)|(1<<CS22)|(1<<CS20);
 OCR2A = 127;

 Serial.print("Finished setup\r\n");

 Serial.println(in_buffer);
 Serial.println(Value);

}

short j;

void catchRisingEdge()   {TCCR1B |= (1<<ICES1); TIFR1 |= (1<<ICF1); rising = 1;}
void catchFallingEdge()  {TCCR1B &= ~(1<<ICES1); TIFR1 |= (1<<ICF1); rising = 0;}

// this loop prints the number of pulses in the last second, showing min and max pulse widths
void loop() {

while(1){

  if(i<800){

    in_buffer[i] = digitalRead(10);
    int val = in_buffer;

    }i++;

}

/*currentMicros = micros();
elapsedMicros = currentMicros - previousMicros;
if (highTime == 1 && elapsedMicros >= highPeriod) {
PINB = PINB | 0b00000011;
previousMicros = previousMicros + lowPeriod;
highTime = 0;
}
if (highTime == 0 && elapsedMicros >= lowPeriod) {
PINB = PINB | 0b00000011;
previousMicros = previousMicros + highPeriod;
highTime = 1;
}*/

 //int val = digitalRead(9);
/* uint8_t state = 0;
 while(1) {
    if(state == 0) {
      digitalWrite(9, LOW);
      state = 1;
      delay(8);
      catchRisingEdge();
      //Serial.println(state);
      //Serial.println(rising);
    }
    else {
      digitalWrite(9, HIGH);
      state = 0;
      delay(8);
      catchFallingEdge();
      //Serial.println(state);
      //Serial.println(rising);
    }}*/

/*
  int analogValue = analogRead(9);
  int newdataState = (analogValue > 600);//need to check, hoping boolean will evaluate to 1 when true

  if(dataState == 0 && newdataState == 1){//if the led was off, but will be turned on, start the stop watch
    lastTime = millis();//store the current time
    dataState = newdataState;
  }

  if(dataState == 1 && newdataState == 0){//if the led was on, but will be turned off, get the difference between the last time we started counting time
    long difference = millis() - lastTime; //get the current time, but subtract the last stored time
    dataState = newdataState;
    Serial.println(difference);
  }

  digitalWrite(9,dataState);*/

}

void takeReading(){
  int val = digitalRead(11);
  val++;
  Serial.println(val);
}

Please discard the excessive comments for this is a test program.

 

Thanks.

Amateur programmer.
Believe when I tell you that my struggle on here is real.

Last Edited: Wed. Apr 25, 2018 - 05:07 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

azimmali wrote:
I m not sure if the below program is generating that square wave. How do I check it?

 

Well a frequency counter, logic analyzer or Oscilloscope would be the way to measure!

 

It helps to know the background of the project, or why you want to do, what you want to do!

 

 

Jim

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274

 

 

 

Last Edited: Wed. Apr 25, 2018 - 04:29 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well, I have none of the instrumentation as mentioned above at the moment. The purpose is to read a signal that overlaps on the 125kHz carrier wave. Although the carrier will be generated by an analog IC, I want to do a test using the arduino without the IC. Is it possible to read it digitally and store it in a buffer? I tried doing that, and all I get is 0 on the plotter with no variation in signal states (high/low).

Amateur programmer.
Believe when I tell you that my struggle on here is real.

Last Edited: Wed. Apr 25, 2018 - 04:36 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

First:

I'm not going to look deep into such code.

Make it conform to a reasonable coding standard, (For example, format functions one statement per line). Remove the commented out code and then ask some more specific questions about problems you encounter while debugging your code.

azimmali wrote:
Please discard the excessive comments for this is a test program.
Yup, just did that (along with all the code).

Don't understand me wrong I (and others) want to help, but show us you want to be helped by putting in some effort to clean up your code first.

While cleaning up your own code, you often make it easier to understand for yourself and you may well solve your own problem without even having to ask.

 

Second:

What is the clock frequency of your AVR?

If you run it at the (usually) maximum of 20MHz, then you have 40 cpu cycles to read a pin with software.

This is doable in a small loop, but Interrupts have to be disabled during that time or you will miss events.

 

Third:

azimmali wrote:
How do I check it?
A USD 5 Logic Analyser is an excellend piece of equipment for this. Search Ali / Ebay for "24m 8ch". and use it with Sigrok. (I have posted many times before about this)

 

Fourth:

What do you want to do with this?

Have you considered using one of the hardware timers for counting or timing these pulses?

Tell us more, if we know the final goal you want to achieve here, we may have ideas of better overall solutions.

Doing magic with a USD 7 Logic Analyser: https://www.avrfreaks.net/comment/2421756#comment-2421756

Bunch of old projects with AVR's: http://www.hoevendesign.com

Last Edited: Wed. Apr 25, 2018 - 04:48 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Paul,

I posted the code with the comments to give an idea of what I had used in the code before and after. I have removed some unwanted sections in the code.

 

The F_CPU is 16 MHz - Arduino Uno.

 

I am using the serial monitor/plotter at this time to view the outputs.

 

I want to read the modulated signal at every 4 us or less. I m not quite sure of the implementations of hardware timers. I am still learning on this platform.

 

Thanks

Amateur programmer.
Believe when I tell you that my struggle on here is real.

Last Edited: Wed. Apr 25, 2018 - 05:02 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

azimmali wrote:
125kHz carrier wave.

You're not still trying to decode RFID, are you:

 

https://www.avrfreaks.net/forum/fsk-decoding-0

 

 I have none of the instrumentation as mentioned above

They really are essential tools for this kind of project!

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yeah.frown.

Amateur programmer.
Believe when I tell you that my struggle on here is real.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

azimmali wrote:
The purpose is to read a signal that overlaps on the 125kHz carrier wave. Although the carrier will be generated by an analog IC, I want to do a test using the arduino without the IC.

That's still dancing around the purpose, I was looking for something  like I need to read the digital data from an RFID tag, or I'm looking to read the value of a sensor on an instrument using modbus, with enough detail that someone with that experience can jump in and help answer your questions.    Data on a carrier wave does not tell us much. 

It sounds like you want to do DSP by sampling an analog signal, and the ADC on the AVR is not fast enough to sample a 125kHz signal. 

 

Jim

 

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I don't have an input signal at the moment to say that I want to read the digital data from a tag or a sensor. I was considering that before, but it seems very complex to me. I was wondering whether I could use the timing or polling mechanisms instead.

Amateur programmer.
Believe when I tell you that my struggle on here is real.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Please discard the excessive comments for this is a test program.

 

 

Well, I noticed they were excessive (did you write from scratch and were things commented for further testing? did you try at random lines, and comment out if it did not work? Do you try to adapts something existing (then, the adress of the original might be very useful)

 

 

I did not find an automatic way of removing unuseful -and distracting - comments

Maybe this version (shows what is now doing)  is "better"/less intimidating :

********************************/
#include <stdio.h>// for verbose debugging using sprintf
#include <avr/io.h>
#include <avr/interrupt.h>
#include "PWM.h"

#define icpPin 8 //ICP input pin on arduino - DATA IN HERE.
#define pwmoutPin 11        // OCR1A pin on arduino

volatile uint8_t rising;

unsigned long currentMicros;
unsigned long previousMicros;
unsigned long elapsedMicros;
unsigned long Period = 8000000UL; // overall period
// pick the high time, calculate the low time from what's left
unsigned long highPeriod = 4000000UL; // microseconds, x 2 = 10mS = 100 Hz
// probably best if times are increments of 4uS to match up with micros()
unsigned long lowPeriod; // microseconds,  set to = Period - highPeriod in setup()

byte highTime;

// some variables to help see that something is happening in the interrupt handlers
volatile unsigned int Value;     // this stores the current ICR1 value
volatile unsigned int Overflows;
volatile unsigned int PulseCount;

unsigned long duration;

char in_buffer[800];
short i;

//Timer t;
/* Overflow interrupt vector */

ISR(TIMER2_OVF_vect) {                // here if no input pulse detected
    Overflows++;                       // incriment overflow count
}
ISR(TIMER2_CAPT_vect) {
    TCNT1 = 0;                            // reset the counter
    OCR1B = 0;                            //data

    
    TCCR1B ^= (1<<ICES1);   // toggle bit value to trigger on the other edge

    if (bit_is_set(TCCR1B, ICES1)) {
        catchRisingEdge(); // should be inlined
        Value = OCR1B;
        digitalRead(pwmoutPin);// digitalRead might be slow
    } else {
       catchFallingEdge(); // should be inlined
        Value = OCR1B;
        digitalRead(pwmoutPin);
        PulseCount++;
    }

}

void setup() {
    Serial.begin(9600); // should be faster : any PC/RPi can handle 115200 bauds

    DDRB |= (1<<PINB5)|(1<<PINB6); //OC1A and OC1B on arduino Pin 11 and Pin 12.

    pinMode(11, OUTPUT);//2MHz carrier generated here
    pinMode(8, INPUT_PULLUP);

//USE FAST MODE TO ENABLE DOUBLE BUFFERING - GIVES A GLITCH FREE OUTPUT

    TCCR1A =
  (1<<COM1A1)|(0<<COM1A0)|(1<<COM1B1)|(0<<COM1B0)|(1<<WGM11)|(1<<WGM10);
    TCCR1B = (1<<ICNC1)|(1<<ICES1)|(1<<WGM13)|(1<<WGM12)|(0<<CS12)|(1<<CS11)|(0<<CS10);  //250kHz; prescaler 64; Set to Fast PWM Mode - 8 bit; enable noise canceller; enable input capture
    OCR1A = 65535;
    OCR1B = 0;

    TIMSK1 = (1<<ICIE1)|(1<<TOIE1);
// enable input capture interrupt for timer// enable overflow interrupt to detect missing input pulses

    DDRB |= (1<<PINB4);
    pinMode(10, OUTPUT); //125kHz carrier here
    TCCR2A |= (1<<COM2A1)|(0<<COM2A0)|(1<<WGM21)|(1<<WGM20);
    TCCR2B |= (1<<WGM22)|(1<<CS22)|(1<<CS20);
    OCR2A = 127;

    Serial.print("Finished setup\r\n");
    Serial.println(in_buffer); // at this stage, is empty???
    Serial.println(Value);
}
short j;
inline // is called from interrupts
void catchRisingEdge()   {
    TCCR1B |= (1<<ICES1);
    TIFR1 |= (1<<ICF1);
    rising = 1;
}
inline // is called from interrupts
void catchFallingEdge()  {
    TCCR1B &= ~(1<<ICES1);
    TIFR1 |= (1<<ICF1);
    rising = 0;
}

// this loop prints the number of pulses in the last second, showing min and max pulse widths
void loop() {
    const uint MAX800 = 800;
    while(1) {
        if (i < MAX800) {

            in_buffer[i] = digitalRead(10);
            int val = in_buffer; // are you sure

        }
        i++;
    }
}
void takeReading() { // is useless at this stage
    int val = digitalRead(11);
    val++;
    Serial.println(val);
}

 

 

Last Edited: Wed. Apr 25, 2018 - 05:38 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

azimmali wrote:
it seems very complex to me.

That's why people make chips & modules to do it for you!

 

EDIT

 

modules

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Wed. Apr 25, 2018 - 05:26 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I wrote some from scratch and some adaptations from exisiting examples on forums and othe sources.

Amateur programmer.
Believe when I tell you that my struggle on here is real.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have not come across any modules that do all the software processing at such low frequencies(LF) but at HF and UHF.

Amateur programmer.
Believe when I tell you that my struggle on here is real.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

azimmali wrote:
I don't have an input signal at the moment

Ok, so you have no signal (from what is still not clear) and you have no test equipment (at the moment), I'm still not clear on what it is you want to do, why or how?

Start at the beginning and fill us in on what you are trying to do, please.

 

Jim

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well, you should have a frequencemeter : some 30E$ multimeters have one (and you REALLY should have a multimeter).

If you want to generate complex waveshapes, a scope would be very useful (and you should sample at -at least- 15 times the frequency you are interested in- in this case > 2 Msamples/second.)

 

Maybe testing small chunk of codes would be less ... terrible.

 

If you pick things/pieces of code  from the internet, having the adress (do they work? were typos introduced?) can help anyone trying to debug.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Niel, I am sure there are modules but each of them was designed for a restricted number of protocols or standards. Like the above modules is for EM4100 type transponders. It cannot be used for other type of tags that require to be read from a distance greater than 50mm and have different encoding formats.

Amateur programmer.
Believe when I tell you that my struggle on here is real.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Jim,

I need to devise an algorithm for a reading modulated on a 125kHz carrier. The incoming signal is encoded in some format, ex like Manchester. In order to extract the encoded information, the s/w should be able to read at certain time intervals or instants of time, say a capture is triggered at the rising edge of the clock and so on, but also be able to read the mid-bit transitions. Does that make any sense?

 

 

Amateur programmer.
Believe when I tell you that my struggle on here is real.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I was trying to generate the carrier using the hardware alone by using the timer/counter, prescaling - But I think there is limit to what Arduinos can do with Timer 0 and Timer1 already being used by the Arduino alone.

Amateur programmer.
Believe when I tell you that my struggle on here is real.

Last Edited: Wed. Apr 25, 2018 - 06:36 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This "overlapping signal" you are trying to sample. Is it logic level or an analog "sorta-square-wave"?

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Square wave - digital - two levels - either zero or one.

Amateur programmer.
Believe when I tell you that my struggle on here is real.

Last Edited: Wed. Apr 25, 2018 - 07:39 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

boolean toggle1 = 0;

void setup() {
  // put your setup code here, to run once:

  pinMode(13, OUTPUT);
  Serial.begin(57600);
  //Serial.print(buffer_in);

  cli();

  //Timer 1 interrupt at 125kHz
  TCCR1A = 0;
  TCCR1B = 0;
  TCNT1 = 0;
  OCR1A = 1;
  //turn on CTC mode
  TCCR1B |= (1<<WGM12);
  //Set prescaler 64
  TCCR1B |= (1<<CS11)|(1<<CS10);
  //enable timer compare interrupt
  TIMSK1 |= (1<<OCIE1A);

  sei();
  //allow interrupts

}

ISR(TIMER1_COMPA_Vect){//timer1 interrupt 125kHz toggles pin 13
  //generates a wave of frequency 125kHz/2 = 62.5kHz
  if(toggle1){
    digitalWrite(13, HIGH);
    toggle1 = 0;
    }
  else{
    digitalWrite(13, LOW);
    toggle1 = 1;

    }

  }
int val;
short i;
char buffer_in[800];
void loop() {
  // put your main code here, to run repeatedly:
while(1){
  if(i<800){
  buffer_in[i] = digitalRead(13);
  }i++;
  }

Serial.println(buffer_in);
}

Here's a new piece of code that I just did, I am not sure if I am doing it right. It's in CTC mode for 125kHz generation.frown

 

 

 

Amateur programmer.
Believe when I tell you that my struggle on here is real.

Last Edited: Wed. Apr 25, 2018 - 07:37 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm just a software engineer. Someone else will have to explain to me what an analog square wave is?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

corrected the post.

Amateur programmer.
Believe when I tell you that my struggle on here is real.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

I work with all types of RFID tags for access control and inventory. Could you provide some links to the tags you are using, or PM if it's that secretive? I have used tags and readers that work in vehicles and read from a distance of over ten feet so this is not something that has not been done before.

125KHZ is the standard most medium level security readers use here in the USA with HID Global being the defacto standard.

East Coast Jim

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You should not be using Arduino digitalWrite, known for it's slowness, to generate the square wave. The timer has hardware controlled outputs that can do it automatically.

 

To see if the wave is being generated, use a LED connected to the output pin (don't forget the current limiting resistor) and program the frequency to 1 Hz or so. The LED should blink at the expected frequency. If that is working ok, then set the correct frequency.

 

But you should really get actual instrumentation as recommended in previous posts.

Last Edited: Wed. Apr 25, 2018 - 08:15 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:

I'm just a software engineer. Someone else will have to explain to me what an analog square wave is?

For me it's been any square wave that does not adhere to conventional logic levels. For example if the square wave high and low sides are above and below ground then that would be an analog square wave.
Of course this opens the argument/debate about RS232 levels but let's save that for another thread shall we?(probably not LOL)

East Coast Jim

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 2

Why don't you start over with a complete explanation instead of mumbling around, with a series of vague or contradictory statements?  Forgetting software details for the moment, what are you trying to do?  Be complete & thorough, in a full paragraph. No one should have to traipse through long code to determine what is the question.  Which devices are you using & how should they interact with each other, for example.

Once this is clear, specific help is easier to give (do this with such a timer mode, use this pin config, avoid doing...)

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I was thinking of a 10mV signal, maybe with slow rise and fall as compared to a 3.3V or 5V logic level square wave. The OP's "0" or "1" does not help unless that implies that there is some sort of "receiver" that outputs standard logic level signals.

 

My point is that "sampling" on a logic input does not do much good unless there is (close to) a logic level signal to work with.

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

azimmali wrote:
I am sure there are modules but each of them was designed for a restricted number of protocols or standards.

Yes, of course they are - because tags adhere to a restricted number of protocols & standards!

 

So just choose a module which supports the protocol(s) and standard(s) that you require.

 

Starting from scratch, do you really think that you're even going to come close to a module designed by specialists who know what they're doing and have decades of experience ... ?

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Well I suggest we all stop,adding to the thread until the OP answers my question in#25 and posts a response as suggested in #28.

To the OP, do not start a new thread. Simply follow the suggestions in post #28 for your response.

East Coast Jim

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 2

Methinks the OP wants something like a nxp htrc110 chip. This generates the carrier, drives the coil and takes care of rx demodulation. It doesn’t care about protocol - your code handles that. There’s also heaps of examples, including arduino.

Last Edited: Thu. Apr 26, 2018 - 07:54 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

jgmdesign wrote:
Well I suggest we all stop,adding to the thread until the OP answers my question in#25 and posts a response as suggested in #28.

I agree, but

In #28, avrcandies wrote:
Be complete & thorough, in a full paragraph.

It should certainly be more than just a single paragraph!

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:
It should certainly be more than just a single paragraph!

 

Oh for cryin' out loud Andy don't be such a weenie!  As long as the OP is clear on the requirements and the intent who the bloody hell cares if it's a paragraph or two, or three?  Oh wait, i know who will care...awneil will! devil

 

Time for tea, and to find a fresh wall to bang my head against.

 

East Coast Jim

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The question of raw signal or processed one is exactly what I was trying to get at in #29.

 

Jim

 

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sorry, my point is not about the structure of the prose - just the quantity of text that's going to be necessary to provide the complete and detailed description requested.

 

A diagram (or diagrams) will also help - especially as there's probably a bit of a language barrier here...

 

EDIT

 

To put it in context, if I were being asked to quote for this, I would expect the description to contain:

  • An overview description of the project - what is it supposed to do
  • A description of the signals
  • A description of what is to be done with these signals
  • References to any standards, protocols, 3rd-party products, etc

 

I would expect that to be supported with:

  • A block diagram of the system
  • Illustration(s) of the signals

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Thu. Apr 26, 2018 - 10:11 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Please check your inbox.

Amateur programmer.
Believe when I tell you that my struggle on here is real.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Candies,

 

I am trying to generate a 125kHz carrier signal using the arduino's hardware. I am not sure of my timer/counter settings. What prescaling factor to use, what mode to use. I have used fast mode because in the datasheet it was mentioned that input capture is more efficient in fast mode citing double buffering. 

 

All I have to do for now, is generate a 125kHz (carrier) square wave and read the signal at specific time instants, say 4 us apart or less. The ICP should trigger a capture at a rising or falling edge of the clock. Store it in the ICR or OCR and repeat the process for about some duration. Then retrieve that data from a buffer(that stores it) and subject it to an algorithm for further data processing and breakdown.

Best,

Amateur programmer.
Believe when I tell you that my struggle on here is real.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It would make the system very bulky. I was trying to conserve space but that is definitely an option to consider.

Amateur programmer.
Believe when I tell you that my struggle on here is real.

Last Edited: Tue. May 1, 2018 - 02:46 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

All I have to do for now, is generate a 125kHz (carrier) square wave and read the signal at specific time instants, say 4 us apart or less

WHAT signal?  The signal you are generating or something else?  If you are generating it, you would probably not have to read it.  Why are you having so much trouble describing what you are doing?  I get a bad feeling about your programming, if you can't describe a simple matter clearly.

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Everybody hold off....the op PM'd me and is making their life way too complicated.  And frustrating all of us in the meantime as well.  They are using an off the shelf RFID tag that has the corresponding reader IC so there is no need for all of this frequency generating stuff.  THere are ready made modules for this as well.

 

Once the OP has replied to my PM I will post what the parts are and we can move on...

 

Jim

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Modulated signal sorry. An incoming rf signal from a transponder, gets superimposed on the RF carrier. The RF carrier is used to power the passive transponder and on its way back to the receiver, it transmits information contained in the transponder's memory.

 

Amateur programmer.
Believe when I tell you that my struggle on here is real.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Unfortunately, azimmali, its way more complex than you imagine. The returned signal is much smaller than the "carrier". So, you have to do something  to separate those two signals. What you pick up is not a nice, big square wave that just cancels out the transmit signal. Sorry, but you are up against some pretty basic laws of fields, here, and it takes  some effort to make it work. That is exactly why folks use one of the dedicated low frequency RFID chips.

 

Jim

 

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

As simple as it can sound, can someone tell me how to generate the 125kHz using an arduino and read that very same 125kHz square wave at 4 or 2 us?? If I generate a 1-0-1-0 (logic levels) square wave at 125kHz, I want the serial monitor to display values(whatever that maybe bits/state/voltages for pulse durations 4uS or 2uS. This way, if the carrier gets overlapped with a transponder's information, I maybe able to read that as well.

Amateur programmer.
Believe when I tell you that my struggle on here is real.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Arduino has delayMicroseconds(). Try

 

while(1) {
    delayMicroseconds(4);
    YOURPORT |= (1<<YOURPIN);   //sets YOURPIN on YOURPORT high
    delayMicroseconds(4);
    YOURPORT &= ~(1<<YOURPIN);   //sets YOURPIN on YOURPORT low
}

Avoid the built in Arduino set/clear functions as they take far too much time. Even this will give you a period closer to 9us. This just creates a signal generator.

 

Now, PLEASE don't tell me that you want to sample and do something on the same MCU. With a 16MHz clock, you only have 128 clock cycles in one period. Period.

 

I still do not understand how you are going to detect the returned signal. Say that you have a 5V transmit signal. Maybe the returned signal is 100mV (probably REALLY optimistic). If you do logic level sampling (eg, read the logic level on the port pin), how is that 100mV going to effect your "1" or "0" logic read value?

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

Last Edited: Tue. May 1, 2018 - 04:41 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

After some back and forth with the OP in PM, the project is for a commercial 'do all' product.  Problem is that I do not think the OP understands that one cannot simply spit out a 125khz signal from an AVR/arduino and an RFID tag will respond and the AVR will simply decode this.  I explained privately, and others have done here publicly, that there is much more to this and that the manufacturers of the tags he/she is looking to use make devices for reading these tags, but the idea of using several of these devices in one product to perform the 'do all' is not acceptable.

 

The op is having other issues as well with the big one being stubborn.  this post makes the count over 45 and there has been nothing gained to this point.  Since the OP and his/her company are refusing to use devices already made for the task...even for evaluation and development purposes I do not see this ending well.

 

 

For me, I'm out.  No sense typing to a brick wall.

 

The rest of the community can do as they wish.

 

I wish the OP all the best in their quest.

 

JIm

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

jgmdesign wrote:
this post makes the count over 45 and there has been nothing gained to this point

Not to mention the 50-odd in the previous thread

 

For me, I'm out.  No sense typing to a brick wall.

+1

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Rather than drag this out, I'll just reference a few things the OP might want to take a look at, at least to get some ideas.  Maybe this will shine some light on some of the things involved.

(I can not answer much about these notes, I have not used them)

 

http://www.serasidis.gr/circuits/RFID_reader/125kHz_RFID_reader.htm

 

Never knew about this device...an AVR with integrated 125 KHz reader

https://www.mouser.com/ds/2/36/doc9219-13368.pdf

 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you for sharing the links avrcandies. The ATA5505, is currently off the market. Thank you all.

Amateur programmer.
Believe when I tell you that my struggle on here is real.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am out, also. This has been singularly unproductive.

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

Last Edited: Tue. May 1, 2018 - 08:06 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

At least the first link makes some sense, with an AM detector, data slicer and the opamp limiter. 

 

Jim

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274

 

 

 

Pages