Advice on clock speed.

Hi,
So I've been messing about with my BBB arduino for a few months now, and I'm working on a project.
It's more of a modification of an old project, rather than using a ProMini as most people do, I am using just an atmega on a board in an effort to shrink the physical size as much as possible.

I am still new to programming, so I need help. The code has only been used on 16mhz and 8mhz, however I am hoping that someone could modify it to run on 4mhz, or even the 1mhz internal oscillator to, even negligibly, increase efficiency.

I see the part that says "use 0x42 for 8mhz and 0x43 for 16mhz" but I'm not sure how to modify this for 4mhz or 1mhz.

and I would be using the original project thread here Build your own DSM2 transmitter module (its working!) - RC Groups but they're becoming abit difficult.

Here is the section of code dealing with timing (I believe). Sorry if this is a really noob question.

//PPM to DSM v1.1 - July 2011

typedef enum {
    NULL_ST = -1, NOT_SYNCHED, ACQUIRING, READY, FAILSAFE
} State_t;

#define PRESCALE           0x43             // if 8Mhz CPU set perscaler to 8 = 0x42, if 16Mhz CPU set prescaler to 64 = 0X43       
#define TICKS_PER_uS       1             // number of timer ticks per 1 microsecond (CPU Speed/Prescale) e.g. CPU at 8MHz/PRESCALE = 1MHz , if CPU at 16Mhz/PRESCALE = .25Mhz 
#define MAX_CHANNELS      8                 // maximum number of channels we can store, don't increase this above 8
#define MIN_IN_PULSE  (1000 * TICKS_PER_uS) // valid pulse must be at least 750us, JR 9X ~= 1050
#define MAX_IN_PULSE  (2300 * TICKS_PER_uS) // valid pulse must be less than 2250us, JR 9X ~= 2211
#define SYNC_GAP_LEN  (4400 * TICKS_PER_uS) // we assume a space at least 5000us is sync, JR 9X ~=4441
#define VALID_FRAMES     10                 // must have this many consecutive valid frames to transition to the ready state.
#define BIND_TIME        10000               // How long to run BindDSM2 8000= mCPx
#define BINDinterval     50
#define ERRORinterval    250

I think we need to know that the "Prescale" value is used for. What register is it loaded into?

I'm sorry, but I'm not sure what you mean.
here is the next part of the code where it appears.

 void begin() {                            // The following is to setup Interrupts / Timers                         
    pinMode(8, INPUT);                      // Timer1 interrupt handler uses pin 8 as input, do not change it
    ChannelNum = 0;                         
    State = NOT_SYNCHED; 
                                                                          // Timer 1 used to trigger on PPM edge
    TIMSK1 = 0x21;                                                        // enable input capture(ICIE1 is bit 5) and overflow (TOIE1 is bit 0) interrupts for timer 1, 0x20 = capture, 0x21 = capture and overflow    
    TCCR1A = 0x00;                                                        // Timer/Counter 1 to Normal Port operation                                          
    TCCR1B = PRESCALE; //(1<<ICES1) | (0<<CS12) | (1<<CS11) | (1<<CS10);        // (ICES1) = capture rising edge on pin ICP1(a.k.a Pin 8),  set prescaler to 64 for 16Mhz  = 0X43
//    TCCR1B = 0x03; //(0<<ICES1) | (0<<CS12) | (1<<CS11) | (1<<CS10);      // (ICES1) = capture falling edge on pin ICP1(a.k.a Pin 8),  set prescaler to 64 for 16Mhz

And here is the full original code. Sorry that I didn't say it before, the code is used to convert ppm signals (what our RC transmitters output) to serial, so that we can use an external module and transmit different protocols.
Thanks!

DSM2_5.zip (5.74 KB)

however I am hoping that someone could modify it to run on 4mhz, or even the 1mhz internal oscillator to, even negligibly, increase efficiency.

Lowering the clock frequency is going to increase the efficiency of what?

I was thinking power consumption and/or use of board space.

Legot:
I was thinking power consumption

How is the board powered? Directly from batteries? Through a regulator?

and/or use of board space.

Using the internal oscillator obviously eliminates the crystal / resonator. However, the internal oscillator is not tuned. How accurate does the clock need to be? Are you prepared to tune it? Does the voltage vary? Or the temperature?

[quote author=Coding Badly link=topic=98261.msg737269#msg737269 date=1332655362]

Using the internal oscillator obviously eliminates the crystal / resonator. However, the internal oscillator is not tuned. How accurate does the clock need to be? Are you prepared to tune it? Does the voltage vary? Or the temperature?

[/quote] I read up more about the Internal Oscillator, and decided against it :sweat_smile: It's too situation specific. I'd eventually like to get this out so that more people would be willing to make it for their transmitters, so simplicity is a must.

It is powered through a 3.3v regulator, from a battery.

Legot:

    TCCR1B = PRESCALE; //(1<<ICES1) | (0<<CS12) | (1<<CS11) | (1<<CS10);        // (ICES1) = capture rising edge on pin ICP1(a.k.a Pin 8),  set prescaler to 64 for 16Mhz  = 0X43

TCCR1B is the Timer/Counter1 Control Register B.
0x40 = ICES1 = Input Capture Edge Select = RISING
0x03 = Divide clock by 64
Other choices for clock divider are:
0x01 = No divider
0x02 = Divide by 8
0c04 = Divide by 256
0x05 = Divide by 1024