Show Posts
Pages: 1 2 [3] 4 5 6
31  Forum 2005-2010 (read only) / Troubleshooting / Re: inverting a pwm signal on: March 30, 2010, 10:38:27 am
Quote
What i want is to create a pwm signal on pin 10 and it's reverse on pin 11. If you can modify your code to do this i would really appreciate it.

Can I suggest using pins 9 and 10, rather than 10 and 11, because 9 and 10 both run off the same timer, so they should be syncronised.
Simply do a normal analogWrite to pin 9, then run my code for pin 10.

Like so:

Code:
void invertAnalogWrite(int pin, int value)
{
    analogWrite(pin, value);
   TCCR1A = TCCR1A & ~B00110000; //switch off output B
   TCCR1A |= B00110000;  //switch on the B output with inverted output
}

void loop()
{
    analogWrite(9, value);
    invertAnalogWrite(10, value);
}

This should do the trick. There is an outside chance that there might be one pluse that is out of sync if the timer ticks between the analogWrite() command and the invert commands. If this would cause a problem, then I would be quite happy to write you some code to get round this. Basically it would require a custom analogWrite function.
If that is what you want then tell me and I would happily knock it up.

Chris
32  Forum 2005-2010 (read only) / Troubleshooting / Re: inverting a pwm signal on: March 30, 2010, 09:33:56 am
As the PMW is managed by the built in timers it sould simply be a matter of changeing the output mode.
Lets say you are using PWM on pin 10. This is controlled by the B output of timer 1. So after you set 'analogWrite(10, 100)' you need to reverse the output like this:

Code:
TCCR1A = TCCR1A & ~B00110000; //switch off output B
TCCR1A |= B00110000;  //switch on the B output with inverted output

you could combine this into a function like:

Code:
void invertAnalogWrite(int pin, int value)
{
    analogWrite(pin, value);
   TCCR1A = TCCR1A & ~B00110000; //switch off output B
   TCCR1A |= B00110000;  //switch on the B output with inverted output
}

This would do the job.

I have scoped the output and the above does work.
33  Forum 2005-2010 (read only) / Syntax & Programs / Re: Faster interrupts needed on: April 17, 2010, 11:06:26 pm
Are the LED's being switched on and off, are are you using PWM?

Assuming you are switching on and off
First thing I would do would be to work out how long it takes to read from the array and turn the led on and back off again, and then increment the pointer to the next led in the array. Perhaps add a loop to induce a small delay between the on and off commands.
Once you know how long the above operation takes you can then calculate the maximum frequency at which you can run the above code. For example, lets say it takes 80microseconds to do everything you want, round it up to 100 to give you some overhead and the maximum frequency is 10kHz. Your previous frequency (assuming a 2ms interrupt) was 500Hz.

Ok, so the next thing I would do would be to use timer2 in CTC mode, with a prescaler of 8 and a top value (set by ORC2A) of 99 (this would give a frequency of 10kHz). Then I would use the timer2 COMPA interrupt to run the above routine.

All the information on the timers can be found in the datasheet for the processor.

Does any of that make sense? It is 5:05 am here and I am very tired.
34  Forum 2005-2010 (read only) / Syntax & Programs / Re: How can I write a custom data structure to EEPROM on: March 27, 2010, 03:03:27 am
Pretty unlikely. As I said, I would phsically have to turn off the power with the switch at exactly the time I am writing to the EEPROM.
35  Forum 2005-2010 (read only) / Syntax & Programs / Re: How can I write a custom data structure to EEPROM on: March 27, 2010, 01:39:28 am
Quote
Is there a possibility the Arduino could lose power while writing the structure to EEPROM?

Well yes, but I hope it doesn't. It it looses power it would be because either: I switched it off early, or it died. I hope neither happnes. If it does loose power does that destroy the EEPROM, or just corrupt the data on it?

Quote
If you decide to use individual structures, I think I see a way for the compiler to automatically determine the offsets.

It should be pretty easy for me to work out offsets, that way I can just save the data that has changed since last save.

I have now tied it, and it works like a charm. Now all I need to do is build a working menu system, or failing that some kind of serial interface....

Superb.

Thanks
36  Forum 2005-2010 (read only) / Syntax & Programs / Re: How can I write a custom data structure to EEPROM on: March 27, 2010, 01:00:45 am
Hello again Coding Badly,

The structures won't change now, I seem to have got the bugs out of the rest of the code so I don't see any need to change them.

I will take a look at that writeAnything command. If I am interpretting it correctly, I would be able to simply create a master structure containing all the config data, then just write the whole thing to the EEPROM. Is that right?

Chris
37  Forum 2005-2010 (read only) / Syntax & Programs / How can I write a custom data structure to EEPROM on: March 26, 2010, 10:12:43 pm
Hello all you clever folk.

I have a project underway to construct an RC transmitter using an Arduino for the PPM encoder board. What I want to do is to be able to have the user change certain paramenters (servo end-stops, direction, mix properties etc) and to then be able to save these to the eeprom.

I have several custom data structures, such as:
Code:
typedef struct
{
  int top;                  //stick top value
  int center;               //stick center value
  int bottom;               //stick bottom value
  int dead_zone;            //stick dead zone. A zero value disables the dead zone feature
  int input;                //stick input port
  int type;                 //stick type (0: center/deflection, 1: end/offset)
  int trim;                 //stick trim
  int rates;                //stick rate switch
  bool exponential;         //exponential
  int position;             //current stick position
}
stick;

typedef struct
{
  int top;                    //servo top value (micro seconds)
  int center;                 //servo center value
  int bottom;                 //serve bottom value
  float prop_throw_adjust;    //proportial throw reduction
  float neg_throw_adjust;        //negative throw adjust
  float pos_throw_adjust;        //positive throw adjust
  bool reverse;               //servo reverse
}
tx_output_channel;


typedef struct
{
  int idle_point;              //Throttle idle point
  int mid_point;               //Throttle mid point
  int top_point;               //Throttle top point
  bool allow_negative;         //allow negative throttle, useful for cutting the engine on an IC plane
}
throttle;


typedef struct
{
  bool enable;                 //mixer enabled
  float differential;          //Amount of differential
  int mix_dir;                 //mix direction
  int secondary_channel;       //The channel on which to output the second aileron signal
  int secondary_direction;     //The direction in which to deflect the second servo. can be 1 or -1.
  bool reverse_ailerons;       //reverse ailerons.
}
diff_mixer;


typedef struct
{
  bool enable;                 //mixer enable
  float e_ratio;               //mix elevator ratio, 0 - 0.5
  float r_ratio;               //mix rudder ratio, 0 - 0.5
  int mix_direction;                 //mix direction
}
vtail_mixer;

typedef struct
{
  bool enable;                //mixer enable
  float e_ratio;              //elevator ratio
  float a_ratio;              //aileron ratio
  float differential;          //Amount of differential
  int dmix_dir;                 //differentail mix direction
  int emix_dir;                 //elevator mix direction
  int secondary_direction;     //The direction in which to deflect the second servo. can be 1 or -1.
  bool reverse_ailerons;       //reverse ailerons.
  bool reverse_elevators;      //reverse elevators
}
delta_mixer;

I want to be able to write and read data using these data types to the EEPROM.

Now the £1,000,000 question: Is there a way to do this relativly easily?

A little information:
All the float values contain no more than 2 decimal places.
The majority of int values are between 0 and 100, the only exceptions being the 'stick' top, center and bottom values,  and the 'output' top, center and bottom values which go to a maximum of 1023 and 2000 respectivly.
The '_mixer' and 'throttle' types only have one instance of each, the 'stick' and 'tx_output_channel' have 4 and 7 instances respectivly.

Answers on the back of a postcard.....


Chris Parish
38  Forum 2005-2010 (read only) / Syntax & Programs / Re: Problem with custom data types on: March 23, 2010, 09:08:03 pm
Thankyou Coding Badly,
I don't feel quite so bad now smiley-mad)

Next time I will take into account the fact that I was starting at 0, not 1.

That's what I get for nocturnal coding!
39  Forum 2005-2010 (read only) / Syntax & Programs / Re: Problem with custom data types on: March 23, 2010, 08:08:12 pm
Thanks guys.
40  Forum 2005-2010 (read only) / Syntax & Programs / Re: Problem with custom data types on: March 23, 2010, 08:01:26 pm
You have no idea how stupid that makes me feel.  :-[

Looks like I have always mis-understood the second parameter of the for loop syntax.

DUHHHHHH! *when I think I hurt myself*
41  Forum 2005-2010 (read only) / Syntax & Programs / Problem with custom data types on: March 23, 2010, 07:57:33 pm
Hello all!

I am trying to get some code to work using custom data types.
The types is defined like this:

Code:
typedef struct
{
  int top;
  int center;
  int bottom;
  int input;
  int type;
  int trim;
  int rates;
  int position;
} stick;

I then create an array:

Code:
stick sticks[4];

I then try to set the contents of the array using this function

Code:
void set_sticks()
{
  for (int i = 0; i < 5; i++) {
    sticks[i].top = stick_limits[i][0];
    sticks[i].center = stick_limits[i][1];
    sticks[i].bottom = stick_limits[i][2];
    sticks[i].type = stick_types[i];
    sticks[i].input = stick_inputs[i];
    sticks[i].trim  = stick_trims[i];
    sticks[i].rates = stick_rates[i];
    sticks[i].position = 0;
  }
}

but when I do the arduino crashes. smiley-sad

I can access any item in the array from any other point like this:
Code:
sticks[0].top = 200;

or using a look like in the set_sticks() function.

Does anyone have any idea why this might not be working? I can't get my head around it.
42  Forum 2005-2010 (read only) / Interfacing / Re: Aquarium Reef Controller, stage 1, the LCD shield, on: March 30, 2010, 10:54:55 am
Hi Luke,

That look like an interesting project. I have a freshwater tank myself and you have got me thinking about the automation possabilities.

All the temperature monitoring should be really easy, the difficult point is deciding which of about ten million methods to use! smiley-grin

I look forward to seeing your code, and I hope I can help you with your project.

Keep us posted!

Chris
43  Forum 2005-2010 (read only) / Interfacing / Re: Aquarium Reef Controller, stage 1, the LCD shield, on: March 30, 2010, 10:27:08 am
If the LCD is visibly flickering then the chances are that you are clearing the LCD screen on each loop. Simply removing the clear statement and just overwriting will get rid of the flicker.

Also, if the sheild is blocking the pins then just make yourself some leads to connect it instead of plugging it straight in on top of the arduino.

What are you hoping to achive with the Aquarium Reef Controller?

Can't really do much more without seeing your code; any chance you could post it?

Chris
44  Forum 2005-2010 (read only) / Interfacing / Re: tryiing to get a stepper motor to work on ardiuno on: March 30, 2010, 10:12:58 am
Closer inspection of your picture leads me to think that you have a L239D H bridge chip.
Assuming you have then try running the MotorKnob example bundled with the Arduino IDE, you might need to change some of the pin bindings. If this works then replace the code in setup() and loop() with this:

Code:
void setup()
{
    stepper.setSpeed(30);
}

loop()
{
    stepper.step(100);
}

watch your motor turn, if it goes more than one turn, then reduce the number of steps set by #define STEPS on line 13. If it goes less then a turn then increase the number of steps. Once you have found the number of steps per turn then you can follow the code suggested by PaulS

Chris
45  Forum 2005-2010 (read only) / Interfacing / Re: tryiing to get a stepper motor to work on ardiuno on: March 30, 2010, 09:54:27 am
Ok, so we have no information; lets try and get some.

1) What is the chip in the picture?

2) Can you make the motor do anything?

3) are there any numbers on the motor?

If you can give me the chip number and/or the numbers on the motor I might be able to help you.

Chris
Pages: 1 2 [3] 4 5 6