Show Posts
Pages: [1]
1  Products / Arduino Due / Re: Arduino due / ppm on: December 11, 2013, 08:57:43 pm
Thank you very much for your help, I will be able to check the code on Friday (I do not have an osciloscope at home  smiley-cry ).

Here is what i would like to learn to do on the arduino due ( in green is the equivalent code for the arduino uno):

1. Setup a timer on the due & Start a timer  
  TCCR1A = 0;                        // set entire TCCR1 register to 0
  TCCR1B = 0;
  OCR1A = 100;                     // compare match register
  TCCR1B |= (1 << WGM12);   // turn on CTC mode
  TIMSK1 |= (1 << OCIE1A);    // enable timer compare interrupt

2. Set a presacaler
  TCCR1B |= (1 << CS11);    // 8 prescaler: 0,5 microseconds at 16mhz

3. Change the match register (trigger)
  OCR1A = XXX // what every value i decide

4. Run into a loop every time the match register is reached
  ISR(TIMER1_COMPA_vect){ code }

Is it possible to do ?
2  Products / Arduino Due / Re: Arduino due / ppm on: December 10, 2013, 09:33:04 am
Thanks Sijjim,

you are right, i should learn to read comments! Do you have a picture of your transmitter?

Here is mine:

version 0 (cardboard lol)

Version 1


I would like to use a counter and i do not know how to do it.  Something that use  the due version of

ISR(TIMER1_COMPA_vect){  } & OCR1A

Any help will be appreciated.
3  Products / Arduino Due / Re: Arduino due / ppm on: December 09, 2013, 03:59:16 pm
I would like to ask one more question to our group. Would it be possible to do something similar to the code posted right at the beginning of this thread?

Something like:

1  start counter
2  when counter reach trigger value then digitalWrite(pin, HIGH)
3  reset counter and trigger value
4  when counter reach new trigger value then digitalWrite(pin, LOW)

writing the code like this allows much more flexibility (for example futaba transmitters require negative shift ppm).

Thank you for your help.

4  Products / Arduino Due / Re: Arduino due / ppm on: December 09, 2013, 03:47:39 pm

Stimmer your code was awesome, I modified it to generate 8 channel ppm with 0.5ms pulse and 22ms total length. It is working perfectly ( I'll click a few times on your name to increase your karma lol)


// timer is clocked at 42MHz, so 42 ticks per us

uint32_t periods[]={1000*42,1000*42,1000*42,1000*42,1000*42,1000*42,1000*42,1000*42,1000*42};
uint32_t num_periods=8+1;      // number of channels +1

int ppm_channels[8];
long Frame;
long Sum;
int val = 1;

void TC0_Handler()
    long dummy=REG_TC0_SR0;    // vital - reading this clears some flag
                               // otherwise you get infinite interrupts
    static int i=0;
    if (i>=num_periods)i=0;

void setup(){
  pinMode(2,OUTPUT);           // port B pin 25  
  analogWrite(2,255);          // sets up some other registers I haven't worked out yet
  REG_PIOB_PDR  = 1<<25;       // disable PIO, enable peripheral
  REG_PIOB_ABSR = 1<<25;       // select peripheral B
  REG_TC0_WPMR  = 0x54494D00;  // enable write to registers
//REG_TC0_CMR0  = 0b00000000000010011100010000000000; // set channel mode register (see datasheet)
  REG_TC0_CMR0  = 0b00000000000001101100010000000000; // alternative CMR for inverted output
  REG_TC0_RC0   = 100000000;   // counter period
  REG_TC0_CCR0  = 0b101;       // start counter
  REG_TC0_IER0  = 0b00010000;  // enable interrupt on counter = rc
  REG_TC0_IDR0  = 0b11101111;  // disable other interrupts
  REG_TC0_RA0   = 0.5*1000*42; // Pulse lenght     = .5ms
  Frame         = 22 *1000*42; // ppm frame lenght = 22ms  
  ppm_channels[0]= 0;          // channel 1 from 0 to 255
  ppm_channels[1]= 0;          // channel 2 from 0 to 255
  ppm_channels[2]= 255;        // channel 3 from 0 to 255
  ppm_channels[3]= 0;          // channel 4 from 0 to 255
  ppm_channels[4]= 0;          // channel 5 from 0 to 255
  ppm_channels[5]= 0;          // channel 6 from 0 to 255
  ppm_channels[6]= 0;          // channel 7 from 0 to 255
  ppm_channels[7]= 0;          // channel 8 from 0 to 255
  NVIC_EnableIRQ(TC0_IRQn);    // enable TC0 interrupts

void loop(){
  // 1. Setup 8 channels (changing only channel 1 here just for fun)
  ppm_channels[0]= ppm_channels[0] + val;
  if(ppm_channels[0] >= 255){ val = -1; }
  if(ppm_channels[0] <= 0)  { val = 1;  }
  // 2. Calculate the 8 channels
  Sum = 0;
  for (int i = 0; i < 8; i++)  {
    periods[i] = map(ppm_channels[i], 0, 255, 1000*42, 2000*42);
    Sum = Sum + periods[i];
  // 3. Calculate the sync frame
  periods[8] = Frame - Sum;

And a picture (worth a 1000 words):

mantoui , I did not comment your code because it use delays to generate ppm. It's OK if your mc does only one thing but it is a problem if you run something else at the same time. Thank you for your help, I'll click a few times on your karma too lol.

5  Products / Arduino Due / Re: Arduino due / ppm on: December 06, 2013, 05:21:06 pm
Thank you so much guys. I'll run the codes over the weekend and let you know how it goes.

6  Products / Arduino Due / Re: Arduino due / ppm on: December 04, 2013, 09:53:20 am
Here is what we need to do:

1 - start only one timer in ctc mode
2 - change the trigger
3 - reset the timer to 0

and back to step 2 over and over again.

This is what the code poster above is doing. I hope someone has a clue on how to do this on a Due.


7  Products / Arduino Due / Re: Arduino due / ppm on: December 03, 2013, 05:48:49 pm
Thank you for you answers. I am trying to generate a ppm signal for an RX transmiter. The "servo"  and the "due timer" (which is amazing by the way) libraries works great but can generate only one pulse (pwm). I was able to generate pwm easily, but ppm is more complicated, because the distance (time) between pics change all the time.

Only one timer with a variable trigger is necessary (as shown in the code above), but i am not sure how to set up the timer and change the trigger on the fly.

Thank you all.


Just to remove any confusion (ppm/pwm), a picture is worth a thousand words
8  Using Arduino / Project Guidance / Re: Lost key finder? on: December 03, 2013, 03:32:10 pm
Two of these wireless transceiver would do the trick:

and they are quite cheep!

Also you could be interested by this thread:

Good luck  smiley-lol

9  Products / Arduino Due / Arduino due / ppm on: December 03, 2013, 03:03:20 pm
I would like port some code generating ppm for an RC transmitter from the Uno to the Due. The code is not mine, but it is so simple and elegant that I am not planing to change the structure. It can be downloaded here:

I wish i could set up a counter in the same manner and change the trigger every time it is necessary, it sounds simple when the code is written, but i am kind of stuck. (I spend quite some time reading : and

Any help to jump start my progress would be appreciated.

Thank you in advance,


PS: Here is the code

//this programm will put out a PPM signal

#define chanel_number 8           //set the number of chanels
#define default_servo_value 1500  //set the default servo value
#define PPM_FrLen 22500           //set the PPM frame length in microseconds (1ms = 1000┬Ás)
#define PPM_PulseLen 300          //set the pulse length
#define onState 1                 //set polarity of the pulses: 1 is positive, 0 is negative
#define sigPin 10                 //set PPM signal output pin on the arduino

/*this array holds the servo values for the ppm signal
 change theese values in your code (usually servo values move between 1000 and 2000)*/
int ppm[chanel_number];

void setup(){ 
  //initiallize default ppm values
  for(int i=0; i<chanel_number; i++){
    ppm[i]= default_servo_value;

  pinMode(sigPin, OUTPUT);
  digitalWrite(sigPin, !onState);  //set the PPM signal pin to the default state (off)
  TCCR1A = 0; // set entire TCCR1 register to 0
  TCCR1B = 0;
  OCR1A = 100;              // compare match register, change this
  TCCR1B |= (1 << WGM12);   // turn on CTC mode
  TCCR1B |= (1 << CS11);    // 8 prescaler: 0,5 microseconds at 16mhz
  TIMSK1 |= (1 << OCIE1A);  // enable timer compare interrupt

void loop(){
  while(1){ }

  static boolean state = true;
  TCNT1 = 0;
  if(state) {   //start pulse
    digitalWrite(sigPin, onState);
    OCR1A = PPM_PulseLen * 2;
    state = false;
  else{         //end pulse and calculate when to start the next pulse
    static byte cur_chan_numb;
    static unsigned int calc_rest;
    digitalWrite(sigPin, !onState);
    state = true;

    if(cur_chan_numb >= chanel_number){
      cur_chan_numb = 0;
      calc_rest = calc_rest + PPM_PulseLen;//
      OCR1A = (PPM_FrLen - calc_rest) * 2;
      calc_rest = 0;
      OCR1A = (ppm[cur_chan_numb] - PPM_PulseLen) * 2;
      calc_rest = calc_rest + ppm[cur_chan_numb];

10  Using Arduino / Sensors / Re: IMU - magnetometer - quadcopter on: July 12, 2013, 02:50:16 pm
The Excel file with IMU data and equations can be found here:

The graph shows results (first i rolled 90 degrees, then I pitched 90 degrees then I yawed 90 degrees). Roll and pitch are calculated by the IMU (programmed with Arduino IDE), they are good.

Yaw is calculated in Excel using gyro (good but drift over time) and I also calculated Yaw using the equation above (green line) and it is totally wrong (it should follow the purple line).

Any help will be appreciated.

Thank you

11  Using Arduino / Sensors / IMU - magnetometer - quadcopter on: July 12, 2013, 02:47:57 pm
I am in the process of building a simple IMU for an autopilot. I am using Sparkfun, 9 Degrees of Freedom - Razor IMU ( It is surprisingly user friendly.

I was able to get accelerometer, gyro and magnetometer data right out of the box. After calibration of the sensors and a simple complementary filter i have reliable roll and pitch values.

Now I have a problem with the yaw...

I found here the equation to get the yaw out of the magnetometer value:

Xh= Xm cosPitch + Zm sinPitch
Yh= Xm sinRoll sinPitch + Ym cosRoll - Zm sinRoll cosPitch
with Xm, Ym, and Zm are magnetic sensor measurements

Yaw = Heading = arctan( Yh / Xh )

It sound be simple, but I can't do it. I hope that someone who already worked on IMUs can help me solve this problem.
12  Using Arduino / Displays / Re: Arduino due with 4D systems LCD on: March 08, 2013, 06:16:26 pm
Solution found!

I showed the library to a friend and he found that a flush in the library was the problem... He says that it is a problem with the due's driver. (it's his opinion, I am not an expert)

Anyway, here is the solution: remove the flush in the Picaso_Serial_4DLib.cpp like this and it will work.

Picaso_Serial_4DLib::Picaso_Serial_4DLib(Stream * virtualPort) {
        _virtualPort = virtualPort;
//_virtualPort->flush();       // PROBLEM WITH ARDUINO DUE modified by Francois 3/8/2013
13  Using Arduino / Displays / Arduino due with 4D systems LCD on: March 08, 2013, 01:39:15 pm
I bought the uLCD-32PTU ( and it worked fine using it as a slave with Aduino uno R3 and mega 2560, but I have problems with the Arduino due. I explain: I first loaded the Serial Library for the Picaso ( to Aduino's library folder then loaded this code to an arduino uno:

#include <Picaso_Serial_4DLib.h>                
#include <Picaso_Const4D.h>
#define DisplaySerial Serial
Picaso_Serial_4DLib Display(&DisplaySerial);

void setup(void){
  pinMode(2, OUTPUT);
  DisplaySerial.begin(9600) ;
  Display.TimeLimit4D = 5000 ;
  digitalWrite(2, HIGH);
  digitalWrite(2, LOW);
  Display.gfx_Cls() ;
  Display.putstr("Hello World\n") ;

void loop(void){


Then connected power, ground RX and TX to the arduino uno, it worked fine (see pictures 1 and 2).
Then I connected and Arduino mega uploaded the same code and it worked fine.
Then I connected an Arduino due uploaded the same code, but there is problem, there are no serial communication on the Serial port and no display on the LCD screen. I am wondering if there is a problem bettween the Serial library for the Picaso and the Arduino due... (I hope I did not make a stupid mistake, pictures 3 and 4 might help).

Thank you in advance for your help.


PS: if your webbrwoser does not show the pictures, you can find them here:
Pages: [1]