Go Down

Topic: What PWM mode to select and how? (Read 2170 times) previous topic - next topic

lrdazmmlk

I am new to the embedded system programming environment. Can someone explain as to what PWM mode should I select in order to capture values at every rising edge/falling edge and at the mid bit? And how? I have been going through the ATMEGA328 datasheet but in vain. I am not sure what mode to select for the above.



DrAzzy

Not clear to me what you're trying to do, you talk about capture, but also PWM. Which is it? Details please.
ATTinyCore for x4/x5/x61/x7/x8/x41/1634/828/x313 megaTinyCore for the megaavr ATtinies - Board Manager:
http://drazzy.com/package_drazzy.com_index.json
ATtiny breakouts, mosfets, awesome prototyping board in my store http://tindie.com/stores/DrAzzy

lrdazmmlk

#2
Mar 05, 2018, 08:33 pm Last Edit: Mar 05, 2018, 08:39 pm by lrdazmmlk
PWM for setting bits in TCCR1A/TCCR1B. After generation of a square wave oscillating at 125kHz, incoming data gets superimposed on it. I want to read that data.
I have no clue what to put in these registers for initialization.

Dumb question: When and why do we use PWM settings?

TCCR1A = 0;
TCCR1B = (1<<ICNC1)|(1<<ICES1)|(CS12)|(CS11)|(CS10);//Setting noise canceller delays the ICES1/input capture by 4 oscillator cycles
TCNT1 = 0;
TIMSK = 0;
ICR1 = 
OCR1A =

DrAzzy

#3
Mar 05, 2018, 09:03 pm Last Edit: Mar 05, 2018, 09:05 pm by DrAzzy
Hmm, that was more appropriate to your question than I thought.

Can you give more detail of what the specs and constraints are here? Do you have a timing diagram for the signal you're looking at and when you need to sample at?
What do you mean superimposed on it? Are you generating some sort of signal, or reading one? Is there two lines, a data and a clock line?

ATTinyCore for x4/x5/x61/x7/x8/x41/1634/828/x313 megaTinyCore for the megaavr ATtinies - Board Manager:
http://drazzy.com/package_drazzy.com_index.json
ATtiny breakouts, mosfets, awesome prototyping board in my store http://tindie.com/stores/DrAzzy

lrdazmmlk

#4
Mar 05, 2018, 09:30 pm Last Edit: Mar 05, 2018, 09:36 pm by lrdazmmlk
I have attached a timing diagram below. The bit rate is 4.194 bits/sec. The bit duration is RF/32.

The 125 kHz square wave is the output of an analog front end - transceiver. The message signal is biphase encoded information that is superimposed upon interception.

DrAzzy

#5
Mar 05, 2018, 09:37 pm Last Edit: Mar 05, 2018, 09:37 pm by DrAzzy
So what is this signal? This is an input that you're trying to read or what? Or is it an output you're trying to duplicate?

That looks like an analog signal; you can't do analog reads fast enough for that, I think you're going to need some sort of external hardware here. What device is this that you're interfacing with?

I'm 95% sure you're in X-Y problem territory at this point.
ATTinyCore for x4/x5/x61/x7/x8/x41/1634/828/x313 megaTinyCore for the megaavr ATtinies - Board Manager:
http://drazzy.com/package_drazzy.com_index.json
ATtiny breakouts, mosfets, awesome prototyping board in my store http://tindie.com/stores/DrAzzy

lrdazmmlk

Yes an input at the transceiver end. The design is a combination of signal processing and conditioning circuits. Design reads data from an - RFID tag.

DrAzzy

What does the signal look like on the oscilloscope? What are the voltages involved? Like - could you smooth it and direct it to an opamp or comparator to convert that awful 125khz-modulated signal turned into something civilized?

Doing this in arduino seems really nasty.
ATTinyCore for x4/x5/x61/x7/x8/x41/1634/828/x313 megaTinyCore for the megaavr ATtinies - Board Manager:
http://drazzy.com/package_drazzy.com_index.json
ATtiny breakouts, mosfets, awesome prototyping board in my store http://tindie.com/stores/DrAzzy

lrdazmmlk

Not sure what the waveform looks like as of now. In the start I was trying to configure an IC that was supposed to output a 125kHz square wave. Somehow the attempt went kaput.

The smoothening and comparator is all done. All I need to do try to read the data from the intercepted signal. Arduino is by far the easiest for me at this time.But it can be later implemented on better ATMEGAs once I get a grip of it.

https://forum.arduino.cc/index.php?topic=525073.0

Smajdalf

Hi,
I don't understand how the data are encoded from the picture you posted. Anyway please look in "How to use this forum" to learn how to inline pictures - when people don't need to download them they are more likely to look at them and help you:

If I understand it correctly you supply the IC (EM4097) with 125kHz carrier frequency, it modulates it to the lower trace, than demodulates it back to the upper trace you are trying to read. So basicly you have two independent tasks:
1) Generate 125kHz carrier
2) Read the 4kHz output
For generating the 125kHz carrier signal you can use nearly any timer mode with variable TOP. If you want to use other Arduino functions (such as millis, delay and many dependant functions) don't use Timer0. Since this is simple task you may use Timer2 easily. For 50% duty cycle I would use CTC mode with "Toggle OCnx on Compare Match" mode. For generating 125kHz you need Compare Match at 250kHz (2 toggles per carrier cycle). You get one Compare Match every timer overflow, so elected timer needs to overflow every 16Mhz (Arduino default speed) / 250kHz = 64 cycles. For example using OC2B (PD3, Digital 3) you use
Code: [Select]

DDRD|=(1<<PD3);
TCCR2A=(1<<COM2B0)|(1<<WGM20);
TCCR2B=(1<<CS20);
OCR2A=63;
OCR2B=0;  //any value between 0 and OCR2A will do

You can use Timer1 in similar manner but maybe you will want to use its ICR feature to read output from the chip.

lrdazmmlk

#10
Mar 06, 2018, 07:06 pm Last Edit: Mar 06, 2018, 08:31 pm by lrdazmmlk
Hi,
Thank you for the suggestion and explanation. I really appreciate it. I will try the same and post my progress.

The output of the EM4097 IC can be anywhere in between 100-150kHz. The device (IC) generates that. But since I couldnt get it configured correctly, the PLL is not getting locked and I can only see noise components on the oscilloscope.

I did not understand how you had decided on the resolution. Are there any formulae to calculate the same? I did use some from the internet and ended up getting some bizzare values.

Why do you suggest I use CTC mode? I read in the datasheet that if the new value to be written to the OCR1A is lower than the current value of TCNT1, the counter will miss the compare match. Will that effect the decoding in any way?

The encoding is BiPhase(BPSK/Differential BPSK) at a rate of RF/32.

Smajdalf

I think I still don't understand what you need. Please try to make a picture of
1) Signal you want Arduino to output
2) Signal what should Arduino analyze and how (when it should be read)

6v6gt

This appears to be an extremely comprehensive blog on an signal encoding, with particular relevance to RFID. It is in Chinese, but a huge amount consists of English language articles and anyway there is always Google translate :
http://www.cnblogs.com/shangdawei/p/4834182.html
Maybe the OP can find a better picture in it to replace the rather cryptic picture in post #4

lrdazmmlk

#13
Mar 07, 2018, 06:07 pm Last Edit: Mar 07, 2018, 06:18 pm by lrdazmmlk


Here's a representation:

Bit duration - RF/32

Square wave (carrier frequency) - 125kHz

Modulating signal frequency - Not sure but around 4kHz

lrdazmmlk

I couldn't locate any tutorials on how to insert inline images.

Go Up