Show Posts
Pages: [1] 2 3 4
1  Using Arduino / Programming Questions / Re: ISR problem... On MEGA using timer5 COMPA actives but not B or C on: August 02, 2013, 02:20:53 pm
Thank you that makes sense.
2  Using Arduino / Programming Questions / ISR problem... On MEGA using timer5 COMPA actives but not B or C on: August 02, 2013, 10:39:23 am
I am using these ISRs in a different program I am writing. TIMER5_COMPA is firing correctly and entering the ISR. However, B and C will not. BTW this is not actually being used to toggle pins. That is just what I am using to debug the ISRs. COMPA is running some code that I need to run at 400Hz and is working great. I am already using timer 1,3, and 4 for PWM generation.

Code:
#define D22Output() DDRA |= 1<<0
#define D22High() PORTA |= 1<<0
#define D22Low() PORTA &= ~(1<<0)
#define D22Toggle() PORTA ^= (1<<0);

#define D23Output() DDRA |= 1<<1
#define D23High() PORTA |= 1<<1
#define D23Low() PORTA &= ~(1<<1)
#define D23Toggle() PORTA ^= (1<<1);

#define D24Output() DDRA |= 1<<2
#define D24High() PORTA |= 1<<2
#define D24Low() PORTA &= ~(1<<2)
#define D24Toggle() PORTA ^= (1<<2);

void setup(){
  D22Output();
  D23Output();
  D24Output();
  Timer5Setup();
}
void loop(){
}
ISR(TIMER5_COMPA_vect){
  D22Toggle();
}
ISR(TIMER5_COMPB_vect){
  D23Toggle();
}
ISR(TIMER5_COMPC_vect){
  D24Toggle();
}
void Timer5Setup(){
  TCCR5A = (1<<COM5A1);
  TCCR5B = (1<<CS51)|(1<<WGM52);
  TIMSK5 = (1<<OCIE5A)|(1<<OCIE5B)|(1<<OCIE5C);
  OCR5A = 5000;
  OCR5B = 50000;
  OCR5C = 50000;
}

I have tried doing this to see if I can at least get TIMER5_COMPB to fire and it does not work:

Code:
#define D23Output() DDRA |= 1<<1
#define D23High() PORTA |= 1<<1
#define D23Low() PORTA &= ~(1<<1)
#define D23Toggle() PORTA ^= (1<<1);

void setup(){
  D23Output();
  Timer5Setup();
}
void loop(){
}
ISR(TIMER5_COMPB_vect){
  D23Toggle();
}
void Timer5Setup(){
  TCCR5A = (1<<COM5A1);
  TCCR5B = (1<<CS51)|(1<<WGM52);
  TIMSK5 = (1<<OCIE5B);
  OCR5B = 50000;
}

Hopefully someone can shed some light on why my ISRs are working correctly. Thanks in advance.
3  Community / Exhibition / Gallery / Re: Futaba SBUS reverse engineered to work with Arduino on: April 20, 2013, 09:23:26 am
You should be able to do that no problem. Just assign the variable Z to one of the channels off the SBUS. Use that map function to map max and min of the SBUS channel to whatever you want or modify the code to work with different ranges.
4  Community / Exhibition / Gallery / Re: Futaba SBUS reverse engineered to work with Arduino on: April 17, 2013, 05:21:35 pm
Got it. What you need to do is have a way to turn SBUS into PWM.

Let's talk at little bit more about SBUS and DSM2/DSMx serial. They are simply transmitting unsigned integers in raw binary over a UART. This means once you have these values you can do whatever you want with them. DSMx and SBUS have a 2048 resolution (2^11) whereas DSM2 has a 1024 (2^10) resolution. OK so the question now is how do we do something with this information.

First you map those values to a range you want to use:

Code:

void MapVar (float *x, float *y, float in_min, float in_max, float out_min, float out_max){
  *y = (*x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
void MapVar (int16_t *x, float *y, float in_min, float in_max, float out_min, float out_max){
  *y = (*x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}

void MapVar (uint16_t *x, float *y, float in_min, float in_max, float out_min, float out_max){
  *y = (*x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}


In the above code I am using pointers. In addition to using pointers you could simple pass the variables or make the variables global. For the servo control you want to generate a PWM signal. Here is a great article about the difference between the two:

http://www.endurance-rc.com/ppmtut.php

Both PPM and PWM use square waves of varying width to convey information. Let's look at servos and ESC (electronic speed controllers). They are controlled by PWM signal with a frequency between 50 - 500Hz and a pulse width of around 1000 - 2000us. For this signal we are concerned with the pulse width and not the PWM's duty cycle. The center is 1500us, but many servos center at 1520. If you run a servo at too high a frequency it will break the servo. This is also for ESCs.

There are a number of ways that you can generate these signals with the arduino. The easiest is to use servo.h. It will allow you to make a lot of these signals on any pin you want. It also doesn't run all that fast. The maximum refresh rate is ~125Hz. A good flight controller runs the control loops very fast and updates the ESCs at ~400Hz. You want to use AVR C. I know that can be a big turn off for a lot of people here since it is considered difficult. And it is, but it is not too bad. If you do it right you only have to figure it out once. Here is another code sample to illustrate how to generate higher frequency ESC PWM signals. This code was written for the mega, but if you look at the datasheet for the 128 it will become clear to you as to how to do it. If it not don't be afraid to ask for assistance with a concept you are struggling with.

Code:

//motor defines
#define FREQ 400
#define PRESCALE 8
#define PERIOD ((F_CPU/PRESCALE/FREQ) - 1)

#define Motor1WriteMicros(x) OCR3B = x * 2//motor 1 is attached to pin2
#define Motor2WriteMicros(x) OCR3C = x * 2//motor 2 is attached to pin3
#define Motor3WriteMicros(x) OCR3A = x * 2//motor 3 is attached to pin5
#define Motor4WriteMicros(x) OCR4A = x * 2//motor 4 is attached to pin6

void setup(){
  MotorInit();
  //do other stuff
}

void loop(){
  Motor1WriteMicros(1250);
  Motor2WriteMicros(someVar);
  //do other stuff
}

void MotorInit(){
  DDRE |= B00111000;//set the ports as outputs
  DDRH |= B00001000;

 
  // Init PWM Timer 3                                       
  // WGMn1 WGMn2 WGMn3  = Mode 14 Fast PWM, TOP = ICRn ,Update of OCRnx at BOTOM
  TCCR3A = (1<<WGM31)|(1<<COM3A1)|(1<<COM3B1)|(1<<COM3C1);  // Clear OCnA/OCnB/OCnC on compare match, set OCnA/OCnB/OCnC at BOTTOM (non-inverting mode)
  TCCR3B = (1<<WGM33)|(1<<WGM32)|(1<<CS31);                 // Prescaler set to 8, that gives us a resolution of 0.5us
  ICR3 = PERIOD;                                // Clock_speed / ( Prescaler * desired_PWM_Frequency) #defined above. 

  TCCR4A = (1<<WGM41)|(1<<COM4A1);
  TCCR4B = (1<<WGM43)|(1<<WGM42)|(1<<CS41);
  ICR4 = PERIOD;
 
  Motor1WriteMicros(1000);//set the output compare value
  Motor2WriteMicros(1000);
  Motor3WriteMicros(1000);
  Motor4WriteMicros(1000);
 
}


This code will not run on the miniPro. This is meant to be an example as to how to set this all up. Furthermore, the 128 only has 1 16bit timer. The above code gives a 0.5us resolution. To use this method with the 128 it will give you two channels with 16bit resolution and two channels with 8 bit of resolution.

Hope that helps. Let me know if there is anything further I can clear up for you.
5  Community / Exhibition / Gallery / Re: Futaba SBUS reverse engineered to work with Arduino on: April 17, 2013, 08:29:32 am
Sorry for the slow response guys, I thought I was subscribed to this thread. In the future if someone needs some help with this library PM me if I don't respond fairly quickly.

m_marc0 - I have updated the library to no longer require SerialPort.h. It now uses the standard arduino conventions. The library is currently configured to run off of Serial1 on a mega. To change the edit the FUTABA_SBUS.h line 12

Code:
#define SBUS_SIGNAL_OK          0x00
#define SBUS_SIGNAL_LOST        0x01
#define SBUS_SIGNAL_FAILSAFE    0x03
#define BAUDRATE 100000
#define port Serial1  <---- this is the line to change

Tissy -I'm not quite clear on what you are trying to accomplish. You can create a PPM signal based off the different channels, but to what end? If you could describe your project in a little more detial hopefully I can give you a better answer. Also, are you sure you aren't confusing PPM with PWM?
6  Community / Exhibition / Gallery / Re: A new IMU which I'm thinking of calling openIMU on: February 01, 2013, 03:31:23 pm
Thanks for the compliment!

Hopefully my board will fix the yaw problems people have. Of course only so much can be done in the presence of a strong magnetic field. Those deflect north. On my tests I have very little yaw drift. Hopefully my boards will fix the problem entirely. I'm anxiously awaiting them.

Have you checked out openCopter in my github?

https://github.com/mikeshub/openCopter

As it stands right now I will have three boards. All of the boards will have the gyro and acc on the SPI bus. The first will be a basic break out for the sensors. The next two will be most of what is required for openCopter. The GPS and telemetry radios will have to connect to the uarts. No built in bluetooth. The mega shield will have the sensors as well as all of the required pins for esc / servo control. It will also have SBUS, dsmx and dsm2 ports, as well as standard RC. The final one will be an all in one flight controller.   The sensors will be the L3GD20 gyro, ADXL345 accelerometer, HMC5883L compass, and BMP085 barometer.  Hope that answers your questions about the board.  I am typing this from cell phone so I am sorry if this is not clear.  I have had excellent results so far with you.  Let's hope that the new boards provide even better results.  Keep an eye on this thread.  I will post as soon as I have the boards assembled.

Thanks again for the interest.
7  Community / Exhibition / Gallery / Re: A new IMU which I'm thinking of calling openIMU on: January 31, 2013, 07:38:05 am
The breakout board is on its way back from China right now. I'll have to solder the components on etc. This first one is just a very limited run. Hopefully there will be much better performance from the compass. The algorithm I'm using works quite well for yaw. The problem is if north is skewed by a field it points to where the compass then thinks north is. I have tested it along side a regular compass and the results matched. You might compare the output of the freeIMU to that of an actual compass and see how the results match / vary.
8  Community / Exhibition / Gallery / Re: A new IMU which I'm thinking of calling openIMU on: January 30, 2013, 05:01:02 pm
I am planning a port of that board. But that is on my back burner. Currently I am doing board design. I am going to sell a break out board for the IMU, a MEGA shield for the openCopter flight controller, and an all in one unit for the flight controller. It will also be porting multiWii and arduPilot to work with my hardware. My software auto-detects whether you are using SBUS, DSM2 or DSMx serial, or standard RC signals. But I digress. Here is why freeIMU, arduIMU, sparkfun razor IMU etc have so much trouble with yaw. Look at the datasheet for that compass:

http://www51.honeywell.com/aero/common/documents/myaerospacecatalog-documents/Defense_Brochures-documents/HMC5883L_3-Axis_Digital_Compass_IC.pdf

Notice that it says nothing about layout considerations. Now look at this version on the bottom of page 5

http://dlnmh9ip6v2uc.cloudfront.net/datasheets/Sensors/Magneto/HMC5883L-FDS.pdf

They specifically say to not put any pour under that IC. All those people do that. I doubt that even full soft and hard iron calibration would take care of those problems. I also consider it to be lazy design to not have all of the axes point in the same direction for the chips. Please don't get me wrong I think very highly of everything 3DR ardupilot and freeIMU. They have done awesome work. That was just the one nitpicky thing I noticed.

Not to mention that there are tons of fields around which really mess with compasses. My boards will not have that defect. Also, my boards employ 2 3.3v regulators. One for the 3.3v IO and another for the 3.3v analog inputs to the ICs. This hopefully will mean that my boards will significantly outperform the other guys boards.

If you want to do a sketch using the openIMU on that board I will be happy to offer you any guidance needed and include your code in the code examples. Good luck. Keep me posted.
9  Community / Exhibition / Gallery / RC detector - DSMx and DSM2 serial, SBUS, standard RC on: January 01, 2013, 10:55:52 am
To use SBUS an inverter such as the 74HC14 must be used. SBUS works fine on 5v, but the spektrum satellites require 3.3v

https://github.com/mikeshub/RC_detect
10  Community / Exhibition / Gallery / Re: A new IMU which I'm thinking of calling openIMU on: December 20, 2012, 04:42:05 pm
I have fixed the bugs in the pololu openIMU software. Be warned version two of the board works much better than version one. I have fixed some bugs in the razor version. Included  is the calibration of the magnetometer.

The biggest part of this post is to announce that the general library has been finished. It will work with either a 6 or 9 degree of freedom (DOF) system. To use make sure that your coordinate is in the North East Down convention. The accelerometer must be measuring gravity as positive along the positive direction of the axes. As far as I know all MEMs accelerometers will need to have the sign negated for each axis to meet this criteria. The gyroscope measurements must be in radians per second. Included in the software is a calibration sketch for the compass. Skipping this calibration will almost certainly make the yaw measurement incorrect. Further than that if the complete soft and hard iron compensation procedure is used the results will be optimal. As they say in the text books that will be left as an exercise for the reader since it is not absolutely necessary for the filter to work properly. Coming soon will be an altimeter that runs off of a simple two state Kalman filter fusing the accelerometer and a barometer as well as more complete documentation. I attempted to make the example for the openIMU clear and easy to understand.

https://github.com/mikeshub/openIMU

https://github.com/mikeshub/Razor_10736_Open_IMU

https://github.com/mikeshub/Pololu_Open_IMU

If anyone uses this on a different IMU board please post the code and I will include it in the examples. Also, thank you to the early adopters of this IMU port.
11  Community / Exhibition / Gallery / Re: Futaba SBUS reverse engineered to work with Arduino on: December 12, 2012, 11:13:49 am
The library has been updated to no longer rely on the SerialPort.h library
12  Community / Exhibition / Gallery / Re: A new IMU which I'm thinking of calling openIMU on: December 11, 2012, 08:49:42 am
I have ported the code out for the sparkfun Razor 10736 9dof IMU.

https://github.com/mikeshub/Razor_10736_Open_IMU
13  Community / Exhibition / Gallery / Re: Futaba SBUS reverse engineered to work with Arduino on: December 08, 2012, 03:15:09 pm
https://github.com/mikeshub/FUTABA_SBUS
14  Community / Exhibition / Gallery / Re: A new IMU which I'm thinking of calling openIMU on: December 08, 2012, 03:00:24 pm
To correct the yaw problem change this line

Code:
if (loopCount == 40){//attempt full update at 10hz
        compass.read();
        gyro.read();
        AHRSupdate(&G_Dt);
        loopCount = 0;
      }

To this:

Code:
if (loopCount == 32){//attempt full update at 10hz
        compass.read();
        gyro.read();
        AHRSupdate(&G_Dt);
        loopCount = 0;
      }

I have updated the code in github. If you get unsatisfactory results or the system is taking up too much time the frequency of the updates can easily be changed by adjusting the loopCount comparisons. Thanks for your interest in the openIMU. I am working on porting the code to the razor 9dof board from sparkfun. Sorry for the slow reply. I now am being notified when a reply to this thread is made and I will be better at staying on to of my responses.

If that doesn't work try this:

Code:
void loop(){
  compass.read();
  gyro.read();
  G_Dt = (micros() - timer)/1000000.0;
  timer=micros();
  AHRSupdate(&G_Dt);

  if (millis() - printTimer > 50){
    printTimer = millis();
    GetEuler();
    Serial.print(printTimer);
    Serial.print(",");
    Serial.print(pitch);
    Serial.print(",");
    Serial.print(roll);
    Serial.print(",");
    Serial.println(yaw);
  }

}

It will run the full update at the maximum rate possible. Please let me know how this works out for you.
15  Community / Exhibition / Gallery / Re: A new IMU which I'm thinking of calling openIMU on: November 18, 2012, 12:33:58 pm
That is correct. The code just tracks your pitch, roll, and yaw angles. If you want to do controls based off it you can with no problems.

I never use the serial monitor in arduino. I think real term http://realterm.sourceforge.net/ is a much better option. If you capture the data as a .csv file you can open it in excel and make graphs etc.

Also, this code should work for either v1 or v2 of the board.
Pages: [1] 2 3 4