Show Posts
Pages: 1 ... 87 88 [89] 90 91 ... 114
1321  Using Arduino / Programming Questions / Re: Book on: April 23, 2012, 03:26:10 am
Hi,
   I have just used the suggestions in this thread to look at the disassembled code for a sketch, its very interesting to see just how much goes on some functions, digitalRead is doing an awful lot to protect the user from themselves, I will be avoiding it in ISRs from now on.

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1193790150

I know this isn't news to many members, and a lot of the code is branching so only a fraction of it will be executed, but its still a bit of a wow for me to see just how much is going on in digital read -

Code:
int digitalRead(uint8_t pin)
{
uint8_t timer = digitalPinToTimer(pin);
    10f2: 68 2f        mov r22, r24
    10f4: 70 e0        ldi r23, 0x00 ; 0
    10f6: cb 01        movw r24, r22
    10f8: 82 55        subi r24, 0x52 ; 82
    10fa: 9f 4f        sbci r25, 0xFF ; 255
    10fc: fc 01        movw r30, r24
    10fe: 24 91        lpm r18, Z+
uint8_t bit = digitalPinToBitMask(pin);
    1100: cb 01        movw r24, r22
    1102: 86 56        subi r24, 0x66 ; 102
    1104: 9f 4f        sbci r25, 0xFF ; 255
    1106: fc 01        movw r30, r24
    1108: 44 91        lpm r20, Z+
uint8_t port = digitalPinToPort(pin);
    110a: 6a 57        subi r22, 0x7A ; 122
    110c: 7f 4f        sbci r23, 0xFF ; 255
    110e: fb 01        movw r30, r22
    1110: 94 91        lpm r25, Z+

if (port == NOT_A_PIN) return LOW;
    1112: 99 23        and r25, r25
    1114: 19 f4        brne .+6      ; 0x111c <digitalRead+0x2a>
    1116: 20 e0        ldi r18, 0x00 ; 0
    1118: 30 e0        ldi r19, 0x00 ; 0
    111a: 3c c0        rjmp .+120    ; 0x1194 <digitalRead+0xa2>

// If the pin that support PWM output, we need to turn it off
// before getting a digital reading.
if (timer != NOT_ON_TIMER) turnOffPWM(timer);
    111c: 22 23        and r18, r18
    111e: 51 f1        breq .+84      ; 0x1174 <digitalRead+0x82>
//
//static inline void turnOffPWM(uint8_t timer) __attribute__ ((always_inline));
//static inline void turnOffPWM(uint8_t timer)
static void turnOffPWM(uint8_t timer)
{
switch (timer)
    1120: 23 30        cpi r18, 0x03 ; 3
    1122: 71 f0        breq .+28      ; 0x1140 <digitalRead+0x4e>
    1124: 24 30        cpi r18, 0x04 ; 4
    1126: 28 f4        brcc .+10      ; 0x1132 <digitalRead+0x40>
    1128: 21 30        cpi r18, 0x01 ; 1
    112a: a1 f0        breq .+40      ; 0x1154 <digitalRead+0x62>
    112c: 22 30        cpi r18, 0x02 ; 2
    112e: 11 f5        brne .+68      ; 0x1174 <digitalRead+0x82>
    1130: 14 c0        rjmp .+40      ; 0x115a <digitalRead+0x68>
    1132: 26 30        cpi r18, 0x06 ; 6
    1134: b1 f0        breq .+44      ; 0x1162 <digitalRead+0x70>
    1136: 27 30        cpi r18, 0x07 ; 7
    1138: c1 f0        breq .+48      ; 0x116a <digitalRead+0x78>
    113a: 24 30        cpi r18, 0x04 ; 4
    113c: d9 f4        brne .+54      ; 0x1174 <digitalRead+0x82>
    113e: 04 c0        rjmp .+8      ; 0x1148 <digitalRead+0x56>
{
#if defined(TCCR1A) && defined(COM1A1)
case TIMER1A:   cbi(TCCR1A, COM1A1);    break;
    1140: 80 91 80 00 lds r24, 0x0080
    1144: 8f 77        andi r24, 0x7F ; 127
    1146: 03 c0        rjmp .+6      ; 0x114e <digitalRead+0x5c>
#endif
#if defined(TCCR1A) && defined(COM1B1)
case TIMER1B:   cbi(TCCR1A, COM1B1);    break;
    1148: 80 91 80 00 lds r24, 0x0080
    114c: 8f 7d        andi r24, 0xDF ; 223
    114e: 80 93 80 00 sts 0x0080, r24
    1152: 10 c0        rjmp .+32      ; 0x1174 <digitalRead+0x82>
#if defined(TCCR2) && defined(COM21)
case  TIMER2:   cbi(TCCR2, COM21);      break;
#endif

#if defined(TCCR0A) && defined(COM0A1)
case  TIMER0A:  cbi(TCCR0A, COM0A1);    break;
    1154: 84 b5        in r24, 0x24 ; 36
    1156: 8f 77        andi r24, 0x7F ; 127
    1158: 02 c0        rjmp .+4      ; 0x115e <digitalRead+0x6c>
#endif

#if defined(TIMER0B) && defined(COM0B1)
case  TIMER0B:  cbi(TCCR0A, COM0B1);    break;
    115a: 84 b5        in r24, 0x24 ; 36
    115c: 8f 7d        andi r24, 0xDF ; 223
    115e: 84 bd        out 0x24, r24 ; 36
    1160: 09 c0        rjmp .+18      ; 0x1174 <digitalRead+0x82>
#endif
#if defined(TCCR2A) && defined(COM2A1)
case  TIMER2A:  cbi(TCCR2A, COM2A1);    break;
    1162: 80 91 b0 00 lds r24, 0x00B0
    1166: 8f 77        andi r24, 0x7F ; 127
    1168: 03 c0        rjmp .+6      ; 0x1170 <digitalRead+0x7e>
#endif
#if defined(TCCR2A) && defined(COM2B1)
case  TIMER2B:  cbi(TCCR2A, COM2B1);    break;
    116a: 80 91 b0 00 lds r24, 0x00B0
    116e: 8f 7d        andi r24, 0xDF ; 223
    1170: 80 93 b0 00 sts 0x00B0, r24

// If the pin that support PWM output, we need to turn it off
// before getting a digital reading.
if (timer != NOT_ON_TIMER) turnOffPWM(timer);

if (*portInputRegister(port) & bit) return HIGH;
    1174: 89 2f        mov r24, r25
    1176: 90 e0        ldi r25, 0x00 ; 0
    1178: 88 0f        add r24, r24
    117a: 99 1f        adc r25, r25
    117c: 84 58        subi r24, 0x84 ; 132
    117e: 9f 4f        sbci r25, 0xFF ; 255
    1180: fc 01        movw r30, r24
    1182: a5 91        lpm r26, Z+
    1184: b4 91        lpm r27, Z+
    1186: 8c 91        ld r24, X
    1188: 20 e0        ldi r18, 0x00 ; 0
    118a: 30 e0        ldi r19, 0x00 ; 0
    118c: 84 23        and r24, r20
    118e: 11 f0        breq .+4      ; 0x1194 <digitalRead+0xa2>
    1190: 21 e0        ldi r18, 0x01 ; 1
    1192: 30 e0        ldi r19, 0x00 ; 0
return LOW;
}
    1194: c9 01        movw r24, r18
    1196: 08 95        ret

Duane B

rcarduino.blogspot.co
1322  Topics / Robotics / Re: Advice on: April 22, 2012, 10:47:34 pm
Hi,
If you can solder, forget about shields and look up the L293E motor driver chip.

Duane B

rcarduino.blogspot.com
1323  Using Arduino / Sensors / Re: LCD+LEDs+Sensor interface on: April 22, 2012, 10:43:29 pm
hi,

No idea what your issues are, but using 10 pins just to turn on/off LEDs seems like a waste of precious pins to me. Have a look at 'shift registers' for a way to drive more LEDs with less pins.

Duane B

rcarduino.blogspot.com

1324  Using Arduino / Motors, Mechanics, and Power / Re: Issues with using ESCs and brushless motors on: April 22, 2012, 10:37:43 pm
Hi,
  and you are using a separate power supply and the ground is connected to Arduino ?

Duane B

rcarduino.blogspot.com
1325  Using Arduino / Programming Questions / Re: Book on: April 22, 2012, 02:39:47 pm
Hi,
   It looks good, I have downloaded the PDF and will have plenty of time to read through it next week when I am stuck on a plane again.

Thanks

Duane B

rcarduino.blogspot.com
1326  Using Arduino / Sensors / Re: pulsein function on: April 22, 2012, 10:55:38 am
Hi,
  If your trying to compile the three channel example, you will need to install the pcintchange library first. To keep things simple for now, try the example in the first link for now, that doesn't require any additional libraries.

Duane B
1327  Using Arduino / General Electronics / Re: Caps on: April 22, 2012, 10:51:10 am
Hi,
   Thanks for the response, I will get a large bag of these -

http://uk.rs-online.com/web/p/ceramic-multilayer/5381310/

Thanks again,

Duane B

rcarduino.blogspot.com
1328  Using Arduino / Sensors / Re: pulsein function on: April 22, 2012, 10:32:39 am
Hi,
   Yes, you can reduce the delay, but don't, pulseIn is just wrong for what most people try and use it for.

Duane B

rcarduino.blogspot.com
1329  Using Arduino / Sensors / Re: pulsein function on: April 22, 2012, 09:36:29 am
Hi,

 Don't use pulsein.

 Read this link from my blog -

http://rcarduino.blogspot.com/2012/01/how-to-read-rc-receiver-with.html

then this one -

http://rcarduino.blogspot.com/2012/04/how-to-read-multiple-rc-channels-draft.html

you might as well read the two links in my signature while you are at it.

Duane B

rcarduino.blogspot.com

rcarduino.blogspot.com
1330  Using Arduino / Programming Questions / Re: Multiple PWM signal reading on Arduino Mega 2560 on: April 22, 2012, 06:51:15 am
Hi,

It's the pinchangeint library, you don't need it on a mega, so remove the include statement and change PCintPort:: before each of the attachInterrupts

You will also need to change the pin numbers, look for the comments 'assign your channel pins' and 'assign your out pins' the channel pins should be updated to whatever pins your channels are connected to from your receiver, the out pins are you channel output pins if you want to drive servos or electronic speed controllers, again update these to whatever pins you have your devices connected to.

Duane B
1331  Using Arduino / Programming Questions / Re: Multiple PWM signal reading on Arduino Mega 2560 on: April 22, 2012, 06:06:58 am
Hi,

Do please read the link, this code below is a car crash waiting to happen as is the code you copied from the post you linked -

Code:
void loop()
 {
  delay(10);
  Serial.println(servo0,DEC); // Pulsewidth in microseconds
  Serial.println(servo1,DEC); // Pulsewidth in microseconds
 } 

When you use servo0 and servo1 in a real world application they will be all over the place.

I use my code in 40km/h RC Race car which is why I protect my shared variable access.

Duane B

rcarduino.blogspot.com
1332  Using Arduino / General Electronics / Caps on: April 22, 2012, 05:50:21 am
Hi,
   Can anyone help me with capacitor choice for decoupling, specifically -

1) Does the voltage matter ?

I often see 0.1uf Capacitors rated upto 100v as the only choice available in local outlets, are these effective in a TTL environment ?

2) Is there any advantage in paying the extra for tantalum over ceramic ?

3) I assume that 0.1uf poly film caps are not suitable for decoupling due to internal inductance, right or wrong ?

Thanks

Duane B

rcarduino.blogspot.com
1333  Using Arduino / Programming Questions / Book on: April 22, 2012, 05:44:31 am
Hi,
   Does anyone have any feedback on this book or can suggest an alternative resource for learning AVR Assembler. I have very limited experience in assembler so need to basics as well as the AVR Specifics, this book seems to cover both.

http://www.amazon.com/Some-Assembly-Required-Programming-Microcontroller/dp/1439820643/ref=sr_1_sc_1?s=books&ie=UTF8&qid=1335087290&sr=1-1-spell

Duane B

rcarduino.blogspot.com
1334  Using Arduino / Programming Questions / Re: Multiple PWM signal reading on Arduino Mega 2560 on: April 22, 2012, 05:42:02 am
Hi,
  Yes, I know, I was referring to the post I linked where I am using an UNO which has only two external interrupts and so I am using the pinchangeint library to get acccess to additional interrupts.

Also from my blog - http://rcarduino.blogspot.com/2012/03/need-more-interrupts-to-read-more.html

Rakma74,
   Your Mega has more external interrupts than my UNO so you can use attachInterrupt and do not need to use the pcintchange library which provides those of use using UNO's with access to upto 20 additional interrupts. The principles and code are the same for both boards so I suggest you do read the post I linked originally and again below, you can imply drop the PCintChange:: before attachInterrupt, everything else remains the same.

Duane B.

rcarduino.blogspot.com
1335  Using Arduino / Programming Questions / Re: Multiple PWM signal reading on Arduino Mega 2560 on: April 22, 2012, 05:30:41 am
Hi,
   Your missing several important points most of which are covered here  -

http://rcarduino.blogspot.com/2012/04/how-to-read-multiple-rc-channels-draft.html

As your using a Mega, you do not need to use the pinchangeint library as you have enough external interrupts already, but you still need to pay attention to shared variable access, could benefit from using bit flags to signal new values are available rather than outputting data whether it has changed or not etc etc.

I am planning a new post showing finished code and standalone hardware that runs in my RC Car based on this code with some additionals to any errors that might occur.

Duane B

rcarduino.blogspot.com
Pages: 1 ... 87 88 [89] 90 91 ... 114