radio multi-channels PWM using attachinterrupt.

23 views
Skip to first unread message

Fu Na

unread,
Mar 31, 2015, 10:31:59 PM3/31/15
to arduino-pincha...@googlegroups.com
I'm using arduino micro.My purpose of writing the code is to use the attachinterrupt to interrupt the input signal and transfer the interrupted signal to output pin for each channel, I need to do 6 channel in total.

Example: for channel 3, the signal at input pin2 =the signal at output pin4.

Problem:Using the code i attached,i can get the desired output signal (same pulse width as input signal)for channel 3 only,but the duty cycle becomes smaller  which means the period of PW is longer for output.For channel 1 there is no any output signal .
PCintPort:attachInterrupt(1,calcThrottle,CHANGE);
I also do not understand why the above code use only 1 ":" in order for me to get the wanted output signal., 
PCintPort::attachInterrupt(1,calcRoll,CHANGE);
but here i have to use 2 "::" in order to compile the code successfully.

READING_PWM_SIGNAL_1.ino

Michael Schwager

unread,
Apr 3, 2015, 7:52:04 PM4/3/15
to arduino-pincha...@googlegroups.com, naven...@gmail.com
I see a number of issues with the code. First, this line is not doing what you think: PCintPort:attachInterrupt(1,calcThrottle,CHANGE);

It causes a warning about PCintPort, and what is actually called in that line is "attachInterrupt" from the Arduino codebase, not the PinChangeInt code. I think you may want to use the attachInterrupt and not use the PinChangeInt library at all, if you have only 2 input lines. You are actually getting a warning in the compiler output but you are missing it because it's near the beginning of the output.

Next, you are trying to set up two interrupt routines on the same pin. This will not work. According to your code, only calcRoll is getting applied- never calcThrottle because it is replaced by the second interrupt attach. This means you will only act on changes to pin 3.

This line:

PCintPort:attachInterrupt(1,calcThrottle,CHANGE);

should look like this:

attachInterrupt(0,calcThrottle,CHANGE);

...assuming that your input is connected to pin 2 on your board. If you need more pins that 2 and 3, then you'll need to use the PinChangeInterrupt library. But if you only use the 2 then stick with attachInterrupt().

Lastly, what is  it seems that you do not take into account switch bounce. I don't know if you need to or if you care, but that's something perhaps to consider. Finally, know that micros() only lasts for 70 minutes, then it rolls over. You need to be sure that it will a) never roll over or b) if it does, you care or c) if it does, you handle it properly.

I hope that helps.



--
You received this message because you are subscribed to the Google Groups "arduino-pinchangeint-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to arduino-pinchangeint...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
-Mike Schwager

Michael Schwager

unread,
Apr 3, 2015, 7:58:54 PM4/3/15
to arduino-pincha...@googlegroups.com, naven...@gmail.com
Ah, I see you are using 6 channels in all. Perhaps you would like to try my new library, EnableInterrupt, found here:  https://github.com/GreyGnome/EnableInterrupt

This will be easiest to set up, and you can use any pin on the Arduino that you want. Be sure to read about the types of interrupts on the Arduino micro (External and Pin Change).

Let me know if you have issues with the library.
--
-Mike Schwager
Reply all
Reply to author
Forward
0 new messages