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.

Kenny

Member Since 13 Aug 2010
Offline Last Active Private
-----

Topics I've Started

NetduinoGauiQuad

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

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.