Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

NetduinoGauiQuad


  • Please log in to reply
6 replies to this topic

#1 Kenny

Kenny

    New Member

  • Members
  • Pip
  • 9 posts

Posted 27 August 2010 - 03:57 PM

Hey guys As planned, I finally got my quad flying, not as stable as I wish, but, near. Still have some algo to try! I'm now thinking of translating the Arduino code to the c# for the netduino to use the netduino power processing and I really need help for the receiver part. I do not really understand that volatile part since I've got it from AeroQuad forum. My project site here http://sites.google.com/site/gauiquad/ Can someone help me with that! https://code.google....Quad/Receiver.h mostly for that part of code #################################################################### #################################################################### volatile uint8_t *port_to_pcmask[] = { &PCMSK0, &PCMSK1, &PCMSK2 }; volatile static uint8_t PCintLast[3]; // Channel data typedef struct { byte edge; unsigned long riseTime; unsigned long fallTime; unsigned long lastGoodWidth; } pinTimingData; volatile static pinTimingData pinData[24]; // Attaches PCINT to Arduino Pin void attachPinChangeInterrupt(uint8_t pin) { uint8_t bit = digitalPinToBitMask(pin); uint8_t port = digitalPinToPort(pin); uint8_t slot; volatile uint8_t *pcmask; // map pin to PCIR register if (port == NOT_A_PORT) { return; } else { port -= 2; pcmask = port_to_pcmask[port]; } // set the mask *pcmask |= bit; // enable the interrupt PCICR |= 0x01 << port; } // ISR which records time of rising or falling edge of signal static void measurePulseWidthISR(uint8_t port) { uint8_t bit; uint8_t curr; uint8_t mask; uint8_t pin; uint32_t currentTime; uint32_t time; // get the pin states for the indicated port. curr = *portInputRegister(port+2); mask = curr ^ PCintLast[port]; PCintLast[port] = curr; // mask is pins that have changed. screen out non pcint pins. if ((mask &= *port_to_pcmask[port]) == 0) { return; } currentTime = micros(); // mask is pcint pins that have changed. for (uint8_t i=0; i < 8; i++) { bit = 0x01 << i; if (bit & mask) { pin = port * 8 + i; // for each pin changed, record time of change if (bit & PCintLast[port]) { time = currentTime - pinData[pin].fallTime; pinData[pin].riseTime = currentTime; if ((time >= MINOFFWIDTH) && (time <= MAXOFFWIDTH)) { pinData[pin].edge = RISING_EDGE; } else { pinData[pin].edge == FALLING_EDGE; // invalid rising edge detected } } else { time = currentTime - pinData[pin].riseTime; pinData[pin].fallTime = currentTime; if ((time >= MINONWIDTH) && (time <= MAXONWIDTH) && (pinData[pin].edge == RISING_EDGE)) { pinData[pin].lastGoodWidth = time; pinData[pin].edge = FALLING_EDGE; } } } } } SIGNAL(PCINT0_vect) { measurePulseWidthISR(0); } SIGNAL(PCINT1_vect) { measurePulseWidthISR(1); } SIGNAL(PCINT2_vect) { measurePulseWidthISR(2); } #################################################################### #################################################################### here is the complete code repository! https://code.google..../trunk/GauiQuad I also need information how to use the I2C library and how to do some PWM. thank

#2 Steven Behnke

Steven Behnke

    Advanced Member

  • Members
  • PipPipPip
  • 70 posts
  • LocationLas Vegas, NV

Posted 27 August 2010 - 04:39 PM

Volatile is a hint to the compiler that the value could be modified by some other mechanism. This means that instead of reading the value once and then reading from the CPU cache, the assembly generated has to read from system ram each time. I don't believe you'd have to do the same in C#.

#3 Kenny

Kenny

    New Member

  • Members
  • Pip
  • 9 posts

Posted 28 August 2010 - 04:55 AM

Well, I know what volatile means... it's the &PCMSK0, &PCMSK1, &PCMSK2 part that I don't know how to map. I thing that those are register name and that they are written by another process... and that the main process loop of the arduino read those register... then, the main process read the the last value written... I'm pretty sure that there is almost the same in the netduino! Otherwise, how to read the receiver value? Any of you can pinpoint me to some PWM and I2C sample? and, is there an EEPROM solution?

#4 Kenny

Kenny

    New Member

  • Members
  • Pip
  • 9 posts

Posted 31 August 2010 - 05:35 PM

bump, anyone for the &PCMSK0, &PCMSK1, &PCMSK2 have an idea?

#5 Steven Behnke

Steven Behnke

    Advanced Member

  • Members
  • PipPipPip
  • 70 posts
  • LocationLas Vegas, NV

Posted 31 August 2010 - 06:34 PM

bump, anyone for the

&PCMSK0,
&PCMSK1,
&PCMSK2

have an idea?



"The PCMSK register allows you to select which pin change interrupt pin or pins trigger PCINT0. One or more of them may provide the trigger. Selected pin change interrupts trigger on both the rising and falling signal edge."

http://www.avrfreaks...wtopic&p=561286

#6 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 31 August 2010 - 07:06 PM

bump, anyone for the

&PCMSK0,
&PCMSK1,
&PCMSK2

have an idea?

You don't have to care about this, just replace any attachPinChangeInterrupt(pin) call with new InterruptPort(pin, ..., InterruptModes.InterruptEdgeBoth) instance and attach measurePulseWidthISR(...) with appropriate parameters to its OnInterrupt event (you'd need to convert the measuring code too). You can re-use the same handler for all pins, the event handler receives portId (pin), state and time, so it is easy to measure pulse width and store rising/falling edge times. I have already posted sample pulse width measurement snippet.

#7 Kenny

Kenny

    New Member

  • Members
  • Pip
  • 9 posts

Posted 01 September 2010 - 02:35 PM

great, thank guy's I'll try this soon!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.