Go Down

Topic: Help needed with Input Capture Regester (Read 231 times) previous topic - next topic

AlaaNoah

I am new to the Arduino and I love the way i can use it  when i know how to useit. but for now i need a help with my project please.


I'm working on project that can read 16 bit High resolution PWM in very high speed (10 or 20   microsecond) for for 5 millis second all the time and to be able to intercept the signal, at that speed and send a different 16 bit command . ("this project is for controlling a small cart brake")
i did some research on how to do that, most the result direct me to using ICR register,to read the signal. and use timer 1 or 3,4,and 5 to generate the signal command

I also try to find any thread that might can help me with the project but i couldn't understand cleare how is it done.
http://forum.arduino.cc/index.php/topic,72092.0.html
http://forum.arduino.cc/index.php?topic=408078.0
http://forum.arduino.cc/index.php?topic=40748.0

I'm using mage board and not sure how to start the code since i don't have a lot of experience in coding generally can you please help me and proved me a simple code or something i can use.


For now I'm generating the signal from the Waveform generator.
1k hz
50% duty cycle
3 Vpp

Thanks in advance

Jiggy-Ninja

I'm working on project that can read 16 bit High resolution PWM in very high speed (10 or 20   microsecond) for for 5 millis second all the time
Usually, signal speeds are measured in hertz, not seconds. What is 10 or 20 microseconds? The resolution? minimum high time? Period?

What is 5 milliseconds?

You're on the right track with using the input capture peripheral, but there are many things to be considered that are missing from your post. Please provide an answer to all the following questions:

1) What is the minimum and maximum frequency that you expect to read?
2) How much resolution? can you accept degraded resolution at higher frequencies?
3) What are the voltages? Peak to peak measurements aren't enough, what are the HIGH and LOW levels? Is it a 0/3V signal? -1.5/1.5V? -3/0V? 100/103V? If it's not a VCC/GND signal that the controller can natively accept, it may require preconditioning.

AlaaNoah

#2
Oct 03, 2016, 06:26 pm Last Edit: Oct 03, 2016, 06:32 pm by AlaaNoah
Hi Jiggy-Ninja,

Thank you for the response.

Sorry for confusing (English is not my first language)
answer to all the following questions:

The period 5 mils, where the single will be On for only 1 mils and during that 1mils the information well be read .
What is 10 or 20microseconds ?
Is the time fram that need to read the data when the data are available at 1mils so every 20 microseconds so it would be 5 reading at 1 mils

1) What is the minimum and maximum frequency that you expect to read?

Min is 14Mhz
Max is 16Mhz

2) How much resolution? can you accept degraded resolution at higher frequencies?

It have to be always 16 bit.  Sending and resiving.

3) What are the voltages? Peak to peak measurements aren't enough, what are the HIGH and LOW levels?

Yes is Is it a 0/3V signal?.
At duty cycle of 33%


Jiggy-Ninja

#3
Oct 03, 2016, 07:28 pm Last Edit: Oct 03, 2016, 07:28 pm by Jiggy-Ninja
However, I think the language barrier is causing confusion, because the things you're saying are conflicting. Let's try another way.



Pretend this is the signal you are trying to measure.  What are the largest and smallest values that big T (period) will be? What are the largest and smallest values that small t (on time) will be?

A 16 MHz signal has a big T period of about 63 nanoseconds (62.5 x 10-9 s). To measure a 16 MHz PWM signal with 16 bits of accuracy would require a clock speed of more than 1 terahertz (16 x 106 Hz  x  216 = 1.048576 x 1012 Hz). This is, to put it mildly, very difficult to get.

I don't think it's actually a 16 MHz signal though, since you mention a 5 ms period, which would be 200 Hz.

If you have purchased a sensor that is producing this signal, can you link to it's datasheet? If you have made a circuit to generate the signal, can you post a schematic?

AlaaNoah

Thank you for you Help and understanding

If you have purchased a sensor that is producing this signal, can you link to it's datasheet? If you have made a circuit to generate the signal, can you post a schematic?

No i didn't Purchase the sensor yet. I want to make sure the the arduino is capable to read the signal first. so i'm using waveform Generator for now .


I attach the picture with the response showing the speed the waveform when is in active mode or normal mode.

Jiggy-Ninja

Unfortunately, those figures still aren't consistent with each other.

Even if you haven't bought a sensor yet, it sounds like you are doing research to buy one. Can you link to the sensors you're researching right now?

AlaaNoah

#6
Oct 03, 2016, 10:15 pm Last Edit: Oct 03, 2016, 11:33 pm by AlaaNoah
Unfortunately, those figures still aren't consistent with each other.
what I'm trying to do is having the arduino reading the the sensor all the time and intercept whatever it need to, so it have two mode
1 - normal when is not intercept (during that time the ON is 1ms and Off 300ms total of 301ms)
2- when the signal is intercept   (during that time the ON is 4ms and Off 300ms total of 304ms)

Even if you haven't bought a sensor yet, it sounds like you are doing research to buy one. Can you link to the sensors you're researching right now?
I'm for now looking for a trailer brake sensor but not sure which one yet.
the only think i know is the data speed
http://www.usdigital.com/products/encoders/absolute/rotary/shaft/MA3?specification=pwm-output-operation

just help me by give me a start code please

i know the processes of the code but not sure how to put all together.
after a lot of reading
i know i need to assign ICP requester 
than assign TCCR requester
than add TIMSK reg
and shifting the the input from the pin into requester and save it
than start counter to count the plus with by the rising  and flowing

IDk how to do all of that



I also found this code Online but not sure if this well help me start
Code: [Select]
#include
#include
volatile uint16_t Capt1, Capt2;//VARIABLES TO HOLD TIMESTAMPS
volatile uint8_t Flag; //CAPTURE FLAG
float deltatime;
#define icpPin 8 // PB0 ICP D8 Interrupt input
/*--------------------------------------------------------------------------------------------------
INTIALIZING TIMER
---------------------------------------------------------------------------------------------------*/
void InitTimer1(void)
{
TCNT1=0; //SETTING INTIAL TIMER VALUE
TCCR1B|=(1<<ICES1); //SETTING FIRST CAPTURE ON RISING EDGE ,(TCCR1B = TCCR1B | (1<<ICES1)
TIMSK1|=(1<<ICIE1)|(1<<TOIE1); //ENABLING INPUT CAPTURE AND OVERFLOW INTERRUPTS
}
/*--------------------------------------------------------------------------------------------------
STARTING TIMER
---------------------------------------------------------------------------------------------------*/
void StartTimer1(void)
{
TCCR1B|=(1<<CS12); //STARTING TIMER WITH PRESCALER 256
sei(); //ENABLING GLOBAL INTERRUPTS
}
/*--------------------------------------------------------------------------------------------------
CAPTURE ISR
---------------------------------------------------------------------------------------------------*/
ISR(TIMER1_CAPT_vect)
{
if (Flag==0)
{
Capt1=ICR1; //SAVING CAPTURED TIMESTAMP
TCCR1B&=~(1<<ICES1); //CHANGE CAPTURE ON FALLING EDGE
}
if (Flag==1)
{
Capt2=ICR1; //SAVING CAPTURED TIMESTAMP
TCCR1B|=(1<<ICES1); //CHANGING CAPTURE ON RISING EDGE
}
Flag++; //INCREMENTING FLAG
}
/*--------------------------------------------------------------------------------------------------
MAIN FUNCTION
---------------------------------------------------------------------------------------------------*/
int main(void)
{
volatile uint8_t FINALTIME; //VARIABLE TO HOLD THE FINAL TIME
pinMode(icpPin,INPUT);
digitalWrite(icpPin,HIGH); //pull up
// pinMode(13, OUTPUT);
InitTimer1(); //CALLING FUNCTION INITTIMER1 TO INITIALIZE TIMER 1
StartTimer1(); //CALLING FUNCTION STARTTIMER1 TO START TIMER 1
while(1)
{
//calculate duty cycle if all timestamps captured
if (Flag==2)
{
Serial.begin(115200);
Serial.print("\r");
Serial.print(" :");8
Serial.print(Capt1);
Serial.print(" :");
Serial.print(Capt2);
Serial.print("\n");
Serial.print(":");
deltatime = (Capt2-Capt1)*0.016; // Prescaler 256
Serial.print((float)deltatime);
Serial.print(" Millisecond");
Serial.print("\n");
Flag=0; //CLEARING FLAGS
TIMSK1|=(1<<ICIE1)|(1<<TOIE1); //ENABLING INPUT CAPTURE AND OVERFLOW INTERRUPTS
TCNT1 = 0;
}
}
}

Go Up