Show Posts
Pages: 1 ... 6 7 [8]
106  Using Arduino / Programming Questions / Re: Possible to determine clock-cycles needed for code snippet ? on: November 28, 2011, 04:36:27 am
Thanks @AWOL. I think I submitted that 2nd msg within a second you did. Of course, your method should be perfect.
While I know where to look for avr-objdump.exe, I am not sure where I can find the sketch's elf output !
107  Using Arduino / Programming Questions / Re: Possible to determine clock-cycles needed for code snippet ? on: November 28, 2011, 04:28:03 am
Would this be a reasonable (if not accurate) technique to determine length of code snippet ?
For example my code snippet is a function called myISR().

step-1) place the code snippet in myISR() and compile in Arduino IDE. Note the no. of bytes reported for "Binary sketch size:", say it is X bytes.
step-2) comment out the code snippet in myISR() and compile again. Note the no. of bytes reported for "Binary sketch size:", say it is Y bytes.
step-3) the length of the code snipped is (X - Y) ?

I suspect that this is over simplification. Since I have some strings that I print using Serial.println(), I am guessing that those go into the static data segment, and not the entire chuck of (X-Y) are instructions, right ? Can, I then make an assumption that 90% would be instructions, and all of them a 1-byte instructions, with an avg. 2 clock/cycles per instruction ?

Of course, if there is a precise deterministic way, that doesn't involve JTAG/ICE, would be great.
108  Using Arduino / Programming Questions / Possible to determine clock-cycles needed for code snippet ? on: November 28, 2011, 04:09:17 am
Is it possible to determine the total no. of clock cycles needed for a certain Arduino code snippet ?
Idea is to see if it'd be prudent (or realistic) to place it in an ISR, without starving loop().

If the Arduino compiler creates intermediate assembler file with subroutine entry makers, I am guessing that this shouldn't be too hard.

Thanks, in anticipation.
109  Using Arduino / Programming Questions / Re: External interrupt (INT0) and digital Pin2 (INPUT) simultaneous usage on: November 28, 2011, 03:56:26 am
Quote
Code:
void myISR()
{
  noInterrupts();
  ...
  interrupts();
}

Those instructions achieve nothing except wasting time. Interrupts are disabled inside an ISR, and enabling them upon leaving is done automatically.

As for your results, what frequency is the square wave? Those Serial.prints take quite a bit of time to execute.

The square wave is generated at 25kHz. In fact I tried at 33.334kHz initially, then thought of reducing it to make it easier for the receiving Arduino to catch-up. Goal is not to work with square waves though. I would like to decode some arbitrary digital signal patterns. In there, the high frequency is 33.334kHz.
110  Using Arduino / Programming Questions / Re: External interrupt (INT0) and digital Pin2 (INPUT) simultaneous usage on: November 28, 2011, 03:51:27 am
Quote
I'd miss pin value toggles etc., and missing pin value toggles breaks my logic completely.
And ignoring interrupts while the ISR is running doesn't result in data loss? What, exactly, is triggering the interrupt, and what are you trying to accomplish?

Thanks @PaulS. You've got a point, and I've to admit that I am not embedded programming expert by any stretch of imagination. Trying to learn while reading and trying out stuff.

The interrupt is current triggered by an Arduino clone (on breadboard actually, using 16MHz xtal), which is currently my square wave generator. The squarewave is generated @ 25 kHz. Eventually, I intend to turn this square wave to a more arbitrary digital data pattern. 
111  Using Arduino / Programming Questions / Re: External interrupt (INT0) and digital Pin2 (INPUT) simultaneous usage on: November 27, 2011, 03:36:39 pm
@PaulS, thanks for taking time to answer.
I've tried removing the interrupt disable/enable pair, but there's hardly any noticeable change in behavior.

Reason for putting the interrupt disable/enable pair was to avoid any kind of race-condition around the 'lastState' and 'howLong' values. Since the ISR itself can be interrupted (if I understood what I read so far, correctly), interruption of ISR, before 'lastState' is updated, vs if it were interrupted after 'lastState' is updated, would give very different results. I'd miss pin value toggles etc., and missing pin value toggles breaks my logic completely.
112  Using Arduino / Programming Questions / External interrupt (INT0) and digital Pin2 (INPUT) simultaneous usage on: November 27, 2011, 03:00:29 pm
Hi,

While I read most of the standard Arduino reference documents, but I've not found a clear answer on if it is possible to use external interrupt (in 'CHANGE' mode, i.e. ISR invoked everything pin-state changes from 0 to 1, or 1 to 0), i.e. INT0 on same pin as DigitalPin#2, while also doing digitalRead(2). Is this a safe combination on a single pin ?

Here is what I was thinking of doing:

Code:
volatile char direction;
volatile unsigned long lastTime;
volatile unsigned long howLong;

void setup()
{
  pinMode(2, INPUT);
  lastTime = micros();
  lastState = digitalRead(2);
  attachInterrupt(0, myISR, CHANGE); 
}

void myISR()
{
  noInterrupts();
  direction = (lastState == HIGH) ? 'U' : 'D';
  lastState != lastState;
  howLong = lastTime - micros();
  interrupts();
}

void loop()
{
  switch (lastState)
  {
    case 'U':
      Serial.print("Going up... ");
      Serial.println(howLong);
      break;
    case 'D':
      Serial.print("Going down... ");
      Serial.println(howLong);
      break;
  }

  lastState = 0;
}


Objective of the above code being tracking the direction (going up/going down) of the leading edge of signal on pin# 2, along with the duration of how long it stays in the previous state.

Reason for asking is that I am getting somewhat erratic behaviour regarding the duration of pin being in certain states, even when what I am feeding it is a squarewave. With a squarewave, I was expecting to see absolutely repeating cycle of Going-up/Going-down, at roughly same duration, but duration seems to over a not-so-narrow range.

Thanks,
f74
113  Using Arduino / Networking, Protocols, and Devices / Re: HT12E library on: April 22, 2011, 01:37:36 pm
@Boffin1, I do not think the address pins could be used to send data, although that does seem like a possible thing at first.  Note that on the transmitting side (encoding side), address/data are virtually indistinguishable, and IMHO if their logic levels are same (& no inversion etc. is used), they are as good as 12 encodable bits. The challenge is on the receiving/decoding side. The HT-12D, decoder after 3 cycles of continuous address matches, will lead to VT being signalled, and all you have are the 4 data pin's output. And remember that the output, post match is latched. AFAIK, there is no reliable way to without the VT signal, to figure out using this IC, 12-bits of all-data, although using tri-state there should've been a way.

Here's text, verbatim from the "HT 12D" datasheet --
Code:
A signal on the DIN pin activates the oscillator which in turn decodes the incoming address and data. The decoders will then check the received address three times continuously. If the received address codes all match the contents of the decoder's local address, the 12-N bits of data are decoded to activate the output pins and the VT pin is set high to indicate a valid transmission. This will last unless the address code is incorrect or no signal is received.
The output of the VT pin is high only when the transmission is valid. Otherwise it is always low.

Having said that, you might like to look at the VirtualWire protocol, where in the manchester decoding is done completely in software. VirtualWire protocol, IMHO, is not directly usable in this case, but could be modified, especially leveraging it's fine play with the timing, matching it to the timing of the HT-12D, and then decode 12-bits ! This is like turning the receiver into a promiscuous-mode sniffer. I would like to do this myself, but at the moment have multiple other priorities stacked up.
114  Using Arduino / Networking, Protocols, and Devices / 433MHz RX spewing junk on: April 18, 2011, 12:10:48 pm
Hi,

Doing this without VirtualWire.

I have some el-cheapo sensors e.g. hall-effect door-open sensor, that send out a short coded message using 433.92MHz ASK module. So I rigged up my Arduino with a RXD1 (433MHz receiver unit) connecting it to the Arduino, just as explained in the VirtualWire documentation. However I am not using the VirtualWire library, because my transmitting device doesn't follow the VirtualWire protocol. So I wrote a very small program to read what the module is throwing at the Arduino input pin. What amazes me is that there is a continuous / steady stream of 0's, 1's, in no particular pattern, which seems more like noise. On removing the connection between data-out from the RXD1 and Arduino, the random flipping stops, and restarts as soon as I plug the wire in. Looking for advise on how to improve the code, and how to actually start detecting the code sent out by my sensor to my Arduino.

Code:
int lastVal = 0;
int lastBitCount = 0;
  
void setup() {
  Serial.begin(9600);
  pinMode(11, INPUT);
}

void loop() {
  int sensorValue = digitalRead(11);
  if (lastVal != sensorValue) {
    Serial.print("Lc: ");
    Serial.print(lastBitCount, DEC);
    Serial.print("   Bit: ");
    Serial.println(lastVal, DEC);
    lastBitCount = 0;
    lastVal = sensorValue;
  }
  else {
    lastBitCount ++;
  }
  delay(10);
}

And here's a small excerpt of what it spews out in Serial-port monitor...

Code:
Lc: 1   Bit: 0
Lc: 0   Bit: 1
Lc: 2   Bit: 0
Lc: 4   Bit: 1
Lc: 0   Bit: 0
Lc: 1   Bit: 1
Lc: 10   Bit: 0
Lc: 6   Bit: 1
Lc: 1   Bit: 0
Lc: 0   Bit: 1
Lc: 0   Bit: 0
Lc: 2   Bit: 1
Lc: 4   Bit: 0
Lc: 0   Bit: 1
Lc: 10   Bit: 0
Lc: 2   Bit: 1

Thanks for pointers, guidance.

regards,
F
115  Using Arduino / Networking, Protocols, and Devices / Re: VirtualWire-1.3 compilation fails in Arduino-022, for Duemilanove on: April 18, 2011, 11:49:42 am
Dumb me. Just had to upgrade to the latest, i.e. VirtualWire-1.5, and the compilation worked well.
Even for v1.3 the issue is just ordering of inclusion of header files as I found from another thread here.
116  Using Arduino / Networking, Protocols, and Devices / VirtualWire-1.3 compilation fails in Arduino-022, for Duemilanove on: April 18, 2011, 08:11:11 am
Hi,

Trying to interface a Duemilanove with a RXD1 (433MHz Rx module). I've followed the wiring instructions for the VirtualWire 1.3 pdf doc, installed the VirtualWire library, although the location doesn't match, I guess because the file organization was changed sometime between 018-022 ?! I placed the VirtualWire under C:\arduino-0022\libraries\ dir.

Code:
In file included from C:\arduino-0022\hardware\arduino\cores\arduino/WProgram.h:6,
                 from receiver.cpp:13:
c:/arduino-0022/hardware/tools/avr/lib/gcc/../../avr/include/math.h:439: error: expected unqualified-id before 'double'
c:/arduino-0022/hardware/tools/avr/lib/gcc/../../avr/include/math.h:439: error: expected `)' before 'double'
c:/arduino-0022/hardware/tools/avr/lib/gcc/../../avr/include/math.h:439: error: expected `)' before 'double'

Where exactly is this "receiver.cpp" ?

PS> Resuming learning of Arduino after a haitus of almost a year, so while I am somewhat familiar with the Arduino programming & usage, I'm not very comfortable with the innards, quite yet, and might be forgetting something quite elementary.

thanks,
F
117  Forum 2005-2010 (read only) / Development / Re: Induino - Low Cost Arduino USB Clone on: August 10, 2010, 04:29:05 am
regarding the 495/- Riduino board, can it be purchased anywhere ? with the atmege328 retailing around 350/-, wondering if remaining 145/- covers the cost of discrete components and PCB... even if sold at cost !

~f74
Pages: 1 ... 6 7 [8]