SMALL - espritmodel.com SMALL - Telemetry SMALL - Radio
Reply
Thread Tools
Old Feb 22, 2013, 06:55 AM
Registered User
idonasch's Avatar
Germany, Berlin
Joined Jun 2004
71 Posts
Quote:
Originally Posted by Cesco View Post
I am reluctant to use code i dont understand, and i do not understand a single line of ppmout.h, that is one level above my ability.
shame on me, I now commented the code and here is the concept of operation. there might be other ways to skin the cat, but the concept is what counts...

/*
* Therory of operation:
* have an object that triggers a single shot positive pulse on an PWM output pin. the resolution shall be 1us.
* for simplicity we assume that the timer is running at 1MHz
* class uses OC capture interrupt which must be implemented in the application.
*
* Usage:
* the capture ISR has to be implemented in the application, because it might have to handle other things then just the pulse out....
* ISR(TIMER0_COMPA_vect)
* {
* t0a.oc_isr(); // PWMout object need to do something here.
* ... // optional application code might also be handled here
* }
*
* instanciate PWM object for the desired timer output compare pin:
* PWMout<T0A> t0a; // T0A is timer0 outputA
* ...
* t0a.begin(); // initialize timer
*
* emit a single 1500usec pulse on OC0A:
* t0a.pulse(1500);
*
* Hardware limitations:
* a 16bit timer is able to cover a time of 65ms, an 8bit timer only 250us. multiple roundtrips have to be dealt with in software.
*
* Operation:
* the pulse() function takes the current timer value (plus a grace time) and sets the OC to "set-on-compare".
* this will be the starting point for the pulse and the output will be set high at that time.
* the OC ISR will be called when the output is set high, now the idea is to set the OC to "clr-on-compare" after the desired pulse period is over.
* in case the pulse width exceed the timers range, it is determined how many times the timer will wrap until it finally can drop the output.
* the ISR is called every time the OC matches (TCNT==TCRAx).
* the last time the OC ISR is called (256 resp 65536 ticks) before the output should be cleared,
* the ISR sets it to "clr-on-compare" and the hardware will do the rest.
* using the clr/set-on-compare allows a full timer wrap time for interrupt latency.
*
* Templates:
* the only purpose for the complex looking templates is to use the same code for all timers and leave the heavy lifting
* to the compiler rather then doing it at run-time.
*/
idonasch is offline Find More Posts by idonasch
Reply With Quote
Sign up now
to remove ads between posts
Old Feb 22, 2013, 10:02 AM
Registered User
Joined Dec 2006
1,441 Posts
Quote:
Originally Posted by Cesco View Post
I am reluctant to use code i dont understand, and i do not understand a single line of ppmout.h, that is one level above my ability.
I thought I was the only one that didn't understand the code :-) particularly all the template stuff.. The explanation was much clearer, thanks for writing it up, idonasch.

BTW. The atmega32u4 in the nanowii has built in USB, so there is no DTR line to reset the device. Still looking for an easy way to reset the device without having it drop off the windows device list every time I press reset. Now I have to keep unplugging and replugging just to reboot without reflashing.
noobee is offline Find More Posts by noobee
Reply With Quote
Old Feb 22, 2013, 01:31 PM
Registered User
Joined Dec 2007
568 Posts
Thanks idonasch. The system is understandable now. The code still not, but that is a matter of working trough it.

Nobee i have no idea how to reset the thing. I do reload it everitime, the flash does have 10000 write cycels, no problem there.

Another idea i had is to avoid the same mess multiwii makes, that is lots of #define and #if defined() to adapt to different hardware. Makes the code bloated and unreadable.
I propose to separate the main calculations (PID etc) from the hardware dependent stuff (pwm generation, rc reading, sensors). The hardware stuff would go into separate files (hk V1, hk V2, nano) with a single #if defined(hardware_type) on top of each file.

I have tried a similar system with my cppm/sbus/spektrum code snipplet. Any thoughts?
Cesco is offline Find More Posts by Cesco
Reply With Quote
Old Feb 22, 2013, 03:04 PM
Registered User
idonasch's Avatar
Germany, Berlin
Joined Jun 2004
71 Posts
Quote:
Originally Posted by noobee View Post
I thought I was the only one that didn't understand the code :-) particularly all the template stuff.. The explanation was much clearer, thanks for writing it up, idonasch.

BTW. The atmega32u4 in the nanowii has built in USB, so there is no DTR line to reset the device. Still looking for an easy way to reset the device without having it drop off the windows device list every time I press reset. Now I have to keep unplugging and replugging just to reboot without reflashing.
missed the part "ATmega32u4", but found this http://arduino.cc/en/Main/ArduinoBoardLeonardo


"Automatic (Software) Reset and Bootloader Initiation
Rather than requiring a physical press of the reset button before an upload, the Leonardo is designed in a way that allows it to be reset by software running on a connected computer. The reset is triggered when the Leonardo's virtual (CDC) serial / COM port is opened at 1200 baud and then closed. When this happens, the processor will reset, breaking the USB connection to the computer (meaning that the virtual serial / COM port will disappear). After the processor resets, the bootloader starts, remaining active for about 8 seconds. The bootloader can also be initiated by pressing the reset button on the Leonardo. Note that when the board first powers up, it will jump straight to the user sketch, if present, rather than initiating the bootloader. "
idonasch is offline Find More Posts by idonasch
Reply With Quote
Old Feb 28, 2013, 05:02 PM
Registered User
Joined Oct 2012
5 Posts
Hi,

Here are photos how I did connection to V2.
First try I soldered MISO to MISO and accidentally to RST route below (on first photo you can see the naked route below MISO contact).
But it still alive :-)

Then I re-soldered all again and 5 times check all connections with tester.
The chip was detected from first try :-) !

Lo fuse = 0xF7
Hi fuse = 0xDF
Ext fuse = 0xF9
Lock fuse = 0xFC
Calibration = FFFFFFBD

V2 is from HobbyKing and firmware reading is locked too.
By the way, I was tried to ask for original firmware at HK support but no chance.

BR.
hmmars is offline Find More Posts by hmmars
Reply With Quote
Old Feb 28, 2013, 06:16 PM
Registered User
United States, NC, Raleigh
Joined Oct 2011
845 Posts
Quote:
Originally Posted by hmmars View Post
Hi,
Here are photos how I did connection to V2.
I like stickers on the connectors. Very easy to see. I used fingernail polish and that is not as obvious.

John
JohnRB is offline Find More Posts by JohnRB
Reply With Quote
Old Mar 01, 2013, 02:19 AM
Registered User
Czech Republic, Olomouc
Joined Sep 2011
126 Posts
hmmars,
you have powered it from 5V USB port from USBAsp? Did it survive?
Try not only flashing, but try gyro function too. Gyro chip is 3.3V comliant not 5V.
ablack is online now Find More Posts by ablack
Reply With Quote
Old Mar 01, 2013, 04:30 AM
Registered User
Joined Oct 2012
5 Posts
HI,

The +5V and GROUND from programer are soldered to the servo input (2nd photo).
So it goes thru internal 3.3 v voltage regulator. In this case both ATMEL and gyro are supplied with 3.3 V.

BR/
hmmars is offline Find More Posts by hmmars
Reply With Quote
Old Mar 01, 2013, 07:59 AM
Registered User
United States, NC, Raleigh
Joined Oct 2011
845 Posts
Quote:
Originally Posted by ablack View Post
hmmars,
you have powered it from 5V USB port from USBAsp? Did it survive?
Try not only flashing, but try gyro function too. Gyro chip is 3.3V comliant not 5V.
This is the proper way to connect the programmer if it is supplying 5V. This way the 5V is connected the same way as it would be with power coming from a receiver or ESC and the 3.3V regulator on the RX3S actually supplies the 3.3V VCC to the the Atmel and Gyro parts.

There is still a minor concern here as the programming signals from the programmer have 5V transitions and are trying to raise VCC (via the protection circuits inside the Atmel) whenever any of the 3 signals (Reset, MOSI or SCK) are high. However, this happens for such a short period of time that damage has not been reported.

The preferred method is to use a 3.3V programmer if available.

John
JohnRB is offline Find More Posts by JohnRB
Reply With Quote
Old Mar 04, 2013, 10:13 PM
Registered User
Joined Dec 2010
120 Posts
Quote:
Originally Posted by JohnRB View Post
This is the proper way to connect the programmer if it is supplying 5V. This way the 5V is connected the same way as it would be with power coming from a receiver or ESC and the 3.3V regulator on the RX3S actually supplies the 3.3V VCC to the the Atmel and Gyro parts.

There is still a minor concern here as the programming signals from the programmer have 5V transitions and are trying to raise VCC (via the protection circuits inside the Atmel) whenever any of the 3 signals (Reset, MOSI or SCK) are high. However, this happens for such a short period of time that damage has not been reported.

The preferred method is to use a 3.3V programmer if available.

John
Hello,

I am very new to Atmel programming and am not yet sure how connect the programmer and the RX3S.

Is there a diagram or photos where the correct connections can be easily seen/identified?

Thank you.
Daniel
dgomes is offline Find More Posts by dgomes
Reply With Quote
Old Mar 05, 2013, 06:44 AM
Registered User
Czech Republic, Olomouc
Joined Sep 2011
126 Posts
Im little confused about choosing right firmware for V2. Why there are two FW?
8MHz and 20MHz? Frequency is set by used resonator, isnt it?
ablack is online now Find More Posts by ablack
Reply With Quote
Old Mar 05, 2013, 07:43 AM
Deviant
sbstnp's Avatar
Joined Jul 2012
1,190 Posts
Quote:
Originally Posted by ablack View Post
Im little confused about choosing right firmware for V2. Why there are two FW?
8MHz and 20MHz? Frequency is set by used resonator, isnt it?
Read the whole thread you'll understand.
sbstnp is online now Find More Posts by sbstnp
Reply With Quote
Old Mar 05, 2013, 08:10 AM
Registered User
Czech Republic, Olomouc
Joined Sep 2011
126 Posts
Thanks for really helpful answer.
ablack is online now Find More Posts by ablack
Reply With Quote
Old Mar 05, 2013, 09:00 AM
Registered User
United States, NC, Raleigh
Joined Oct 2011
845 Posts
Quote:
Originally Posted by ablack View Post
Im little confused about choosing right firmware for V2. Why there are two FW?
8MHz and 20MHz? Frequency is set by used resonator, isnt it?
The crystal is 16MHz, however there is an programmable clock divider that allows for 8MHz operation. If you search back earlier in this thread you will find that 16MHz is just a little outside of the Safe Operating Area (SOA) listed in the full Atmel datasheet. If you have issues running at 16MHz or just don't feel safe working outside of the SOA, use the 8MHz version.

The best I can determine, the original HK code runs at 16MHz.

John
JohnRB is offline Find More Posts by JohnRB
Reply With Quote
Old Mar 05, 2013, 09:32 AM
Registered User
Czech Republic, Olomouc
Joined Sep 2011
126 Posts
Thank you JohnRB,
I have read posts and understand SOA of CPU on 3.3V, but was suprised by selecting 8/16MHz frequency without changing XTAL resonator.
Now I have read datasheet of ATmega168PA and it has system clock prescaler so now its clear that is able to set the clock in FW.
ablack is online now Find More Posts by ablack
Reply With Quote
Reply


Thread Tools

Similar Threads
Category Thread Thread Starter Forum Replies Last Post
Sold Flight Stabilization System with Programing Card Woody_99 Aircraft - Electric - Helis (FS/W) 1 Mar 23, 2012 01:50 PM
Sold Flymentor Flight Stabilization with Field Programmer Woody_99 Aircraft - General - Radio Equipment (FS/W) 0 Mar 17, 2012 08:43 AM
Sold Totally Tricked out 400 size with flight stabilization installed, BNF Woody_99 Aircraft - Electric - Helis (FS/W) 2 Mar 12, 2012 07:56 AM
Wanted FY-30A Flight Stabilization System Casey_S FPV Equipment (FS/W) 0 Mar 05, 2012 03:40 PM