vincer's profilevincer's moodPhotosBlogListsMore Tools Help

Blog


    December 31

    08小结

    有惊无险混到了2008年的最后一天。
     
    08总体来说还是不错的,快乐与痛苦并存,还算过得充实。
     
    最过瘾的就是上半年跟silence、peace、vit、hh、yinstone打dota了。
    打真三,hh说菜鸟来到先用马岱,不爽转战dota,其乐无比。
    N场下来筋疲力尽,过度兴奋。 
    静下来,大家发现宿舍风扇的响声居然很像dota的片头音乐!
    期末,两个实验室聚大餐之后就各奔东西了。
    怀念...
     
    来到sz还不错,参加的活动居然比学校多,打篮球、羽毛球,爬山,运动会...
     
     
    认定了就不要回头,follow your heart
     
     
    最后,祝各位朋友在新的一年身体健康!惊喜不断!
     
    ^_^
     
     
     
     
    February 22

    小孩不笨

    “没有教育不好的孩子,只有不会教育的父母。”
    小孩不笨1(电影)- 严肃沉重 *_*
    小孩不笨2(连续剧)-轻松幽默 ^_^
     
     
    January 08

    ccup工具使用篇

    工欲善其事,必先利其器。

     

    1. avr编译仿真工具:

    前期:avrstudio+winavr(NP),编译用NP,仿真用avrstudiomakefile设置灵活,不过前提是对makefile文件熟悉。

    后期:AVR GCC,跟上面一个样(集成版),设置makefile方便,对makefile熟知度要求相对低。

    其实一个样(gcc),差别在于是否集成。

     

    2. 串口调试工具:

    Serial Port Monitor-强烈推荐,串口监视器,有四种文本模式选择,串口通信收发数据全部可以截取。(得益于这个软件,进度加速)

     

    AccessPort-比超级终端强多了,传输数据少时用它的监视功能还是挺不错的。

     

    3.   Avr下载工具:

    PonyProg2000

    下载速度较慢,支持器件较多;而且下载时cpu几乎都是100%

     

    DownloadMcu-晓奇工作室:

    下载速度较快,支持器件有限,常用的avr芯片都支持就足够了,最好的就是设置熔丝位时有相应的提示。

    ccup小结

     

    本来早就应该写的。

     

     

    可行性:Mega128处理图像(主要是图像格式及大小转换)能否胜任的问题,是否要借助fpga/cpld加以实现?-_-# —> ^_^

     

    1. Gprs模块:TR800相关数据手册, 注意ATE0这个命令(让我郁闷了一阵),此后决定认真的重读数据手册。

     

    2. Xmodem通信协议(已写)。

     

    3. Spi总线:XF-S4240语音芯片的通信方式有I2C,SPI,UART,选用SPI

    设置如下:atmega128- SPI初始化时,将PORTBMOSISCLKSS引脚作为输出,同时将MISO作为输入引脚,并打开上拉电阻,设置主机模式,高位优先,数据速率f/ 16

    SPI的寄存器进行初始化设置时,应注意以下几点:
        .
    正确选择和设置主机或从机,以及工作模式(极性),数据传输率;

        .
    注意传送字节的顺序,是低位优先(LSB First)还是高位优先(MSB Frist);

        .
    正确设置MOSIMISO接口的输入输出方向,输入引脚使用上拉电阻。

     

    4. Usart:由于数据量比较大,误差累积将导致后面的数据出错,故用无误差的晶振频率(试过用16Mhz,但往往是只有前面的一小部分数据正确,往后的数据都出错,改用11.0592后没有发生过数据出错问题,出错就重传);中断+数据缓存区(FIFO),若直接对buffer操作,则注意先把index置零。

     

    5. 全彩Led屏通信协议:由于屏只有windows下的开发dll,肯定不能用在atmega128上了,屏提供的windows程序与Led屏的通信用serialport分析得到通信协议格式。

     

    6. 摄像头通信协议:使用的是zm460RS232接口,相当郁闷的是数据手册是有误的,只能设定被动模式,而且波特率不能改动,加上指令格式有些错误,庆幸的是有串口监控。

     

    7. 串口硬件设计:公、母串口要配备好,弄清串口线需要交叉还是直通,gprs模块要求硬件流控制信号(rts&cts),不用则将其屏蔽掉(7-8短接),否则不能通信。

     

    8. 红外探头:测试后,红外探头没有描述的灵敏,没办法,只能把红外检测程序考虑完善(就利用这个不灵敏的特点),经调试最后得到很好的稳定性。

     

    9. 图像转换:jpeg->xmp

     

    10. 硬件的布局及布线:

    布线要合理,不要跳线太多,做pcb布线的话还是好好的学习一下其相关理论。

    后期正式做板时,由于硬件布线不好,程序经常跑飞,那种心情叫无奈。

    提高硬件可靠性的考虑: 

    硬件-

    .大面积铺地(网格)

    .晶振用地围住;

    .每个ICVCC加上一个0.1uF的电容。

    .外围设备控制光耦隔离

    软件-
        .
    采用振荡电路的输出小幅度;

        .
    选择合适的启动延时参数
        .
    片内的看门狗
        .
    不用I/O口设定输出低电平

     

     

    由于没有JTAG仿真器,程序的调试都是用串口回传数据,在适当的地方设置把裸机上的数据回传同样起到仿真器的效果。

    xmodem protocol

    Xmodem通信协议:

    协议的细节这里不涉及,只说明一下编程注意的事项。数据包有两种:128bytes1024bytestr800模块只支持128bytes。没有采用校验和,而是采用CRCCCITT校验。由于RAM有限及通信特性,Uart接收采用FIFO结构。

    协议格式:
    MESSAGE BLOCK LEVEL PROTOCOL, CRC MODE
     Each block of the transfer in CRC mode looks like:

    <SOH><blk #><255-blk #><--128 data bytes--><CRC hi><CRC lo>
        in which:
    <SOH>           = 01 hex
    <blk #>     = binary number, starts at 01 increments by 1, and
                 wraps 0FFH to 00H (not to 01)
    <255-blk #> = ones complement of blk #.
    <CRC hi>    = byte containing the 8 hi order coefficients of the CRC.
    <CRC lo>    = byte containing the 8 lo order coefficients of the CRC.

    Flow Diagram        

    SENDER                            RECEIVER
                         <---          <C>
                               times out after 3 seconds,
                         <---          <nak>
    <soh> 01 FE -data- <xx> --->
                         <---          <ack>
    <soh> 02 FD -data- <xx> --->      (data gets line hit)
                         <---          <nak>
    <soh> 02 FD -data- <xx> --->
                         <---          <ack>
    <soh> 03 FC -data- <xx> --->
       (ack gets garbaged)  <---       <ack>
                               times out after 10 seconds,
                         <---          <nak>
    <soh> 03 FC -data- <xx> --->
                         <---          <ack>
    <eot>                --->
                         <---          <ack>

    Program Tips
    * The character-receive subroutine should be called with a parameter specifying the number of seconds to wait.  The receiver should first call it with a time of 10, then <nak> and try again, 10 times.

    * After receiving the <soh>, the receiver should call the character receive subroutine with a 1-second timeout, for the remainder of the message and the <cksum>.  Since they are sent as a continuous stream, timing out of this implies a serious like glitch that caused, say, 127 characters to be seen instead of 128.

    * When the receiver wishes to <nak>, it should call a "PURGE" subroutine, to wait for the line to clear.  Recall the sender tosses any characters in its UART buffer immediately upon completing sending a block, to ensure no glitches were mis-interpreted.

    * The most common technique is for "PURGE" to call the character receive subroutine, specifying a 1-second timeout,and looping back to PURGE until a timeout occurs.  The <nak> is then sent, ensuring the other end will see it.(关键:实现PURGE-字符接收子程序设定1s超时)

    * You may wish to add code recommended by John Mahr to your character receive routine - to set an error flag if the UART shows framing error, or overrun.  This will help catch a few more glitches - the most common of which is a hit in the high bits of the byte in two consecutive bytes.  The <cksum> comes out OK since counting in 1-byte produces the same result of adding 80H + 80H as with adding 00H + 00H.

    key:协议的流程、时间次数控制、出错处理。

    January 07

    avr-gcc笔记1-data structure in ram

     

    前言:把前段时间做的事情总结一下。

     

    DATA STRUCTURE IN RAM

      Many of the devices that are possible targets of avr-libc have a minimal amount of RAM. The smallest parts supported by the C environment come with 128 bytes of RAM. This needs to be shared between initialized and uninitialized variables (sections .data and .bss), the dynamic memory allocator, and the stack that is used for calling subroutines and storing local (automatic) variables.

      Also, unlike larger architectures, there is no hardware-supported memory management which could help in separating the mentioned RAM regions from being overwritten by each other.

      The standard RAM layout is to place .data variables first, from the beginning of the internal RAM, followed by .bss. The stack is started from the top of internal RAM, growing downwards. The so-called "heap" available for the dynamic memory allocator will be placed beyond the end of .bss. Thus, there's no risk that dynamic memory will ever collide with the RAM variables (unless there were bugs in the implementation of the allocator). There is still a risk that the heap and stack could collide if there are large requirements for either dynamic memory or stack space. The former can even happen if the allocations aren't all that large but dynamic memory allocations get fragmented over time such that new requests don't quite fit into the "holes" of previously freed regions. Large stack space requirements can arise in a C function containing large and/or numerous local variables or when recursively calling function.

       avr-gcc的栈由内部RAM的顶部向下生长,这样就潜在两个危险性:一是动态分配的堆和栈有可能互相覆盖;二是.data &.bss的数据过多和栈数据覆盖。实际上以上两个问题都发生了,图像数据10Kbytes左右,处理时所需空间大概30Kbytes(动态+静态)。小插曲1:当时由于LED彩屏的中间位置图像发生奇变才注意到这个问题-_-!

    Note:

    The pictures shown in this document represent typical situations where the RAM locations refer to an ATmega128. The memory addresses used are not displayed in a linear scale.

    malloc-std

    RAM map of a device with internal RAM

      On a simple device like a microcontroller it is a challenge to implement a dynamic memory allocator that is simple enough so the code size requirements will remain low, yet powerful enough to avoid unnecessary memory fragmentation and to get it all done with reasonably few CPU cycles. Microcontrollers are often low on space and also run at much lower speeds than the typical PC these days.

      The memory allocator implemented in avr-libc tries to cope with all of these constraints, and offers some tuning options that can be used if there are more resources available than in the default configuration.

    Internal vs. external RAM

      Obviously, the constraints are much harder to satisfy in the default configuration where only internal RAM is available. Extreme care must be taken to avoid a stack-heap collision, both by making sure functions aren't nesting too deeply, and don't require too much stack space for local variables, as well as by being cautious with allocating too much dynamic memory.

      If external RAM is available, it is strongly recommended to move the heap into the external RAM, regardless of whether or not the variables from the .data and .bss sections are also going to be located there. The stack should always be kept in internal RAM. Some devices even require this, and in general, internal RAM can be accessed faster since no extra wait states are required. When using dynamic memory allocation and stack and heap are separated in distinct memory areas, this is the safest way to avoid a stack-heap collision.

    Tunables for malloc()

      There are a number of variables that can be tuned to adapt the behavior of malloc() to the expected requirements and constraints of the application. Any changes to these tunables should be made before the very first call to malloc(). Note that some library functions might also use dynamic memory (notably those from the <stdio.h>: Standard IO facilities), so make sure the changes will be done early enough in the startup sequence.

      The variables __malloc_heap_start and __malloc_heap_end can be used to restrict the malloc() function to a certain memory region. These variables are statically initialized to point to __heap_start and __heap_end, respectively, where __heap_start is filled in by the linker to point just beyond .bss, and __heap_end is set to 0 which makes malloc() assume the heap is below the stack.

      If the heap is going to be moved to external RAM, __malloc_heap_end must be adjusted accordingly. This can either be done at run-time, by writing directly to this variable, or it can be done automatically at link-time, by adjusting the value of the symbol __heap_end.

      The following example shows a linker command to relocate the entire .data and .bss segments, and the heap to location 0x1100 in external RAM. The heap will extend up to address 0xffff.

    avr-gcc ... -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff ...

      实际上如果你使用avrstudio内嵌gcc的话只要在Project->Configuration Options->Memmory中通过Add,选择Sram,在Name输入.dataAddress输入0x801100即可,你也通过这个功能可方便移动自定义的数据或是默认的数据区。小插曲2:不知道是不是版本的原因,根据上面的方法在低版本(具体那个版本忘了,建议下载最新版)设置,完全没有效果,结果可以在编译信息或者看map文件,map文件很清晰的给出编译后数据的存放位置。如果你使用外部makefile或者是在PN下编译的话,你可以通过修改makefile中的Linker Options下的内容,如下所示:

    #---------------- Linker Options ----------------

    #  -Wl,...:     tell GCC to pass this to linker.

    #    -Map:      create map file

    #    --cref:    add cross reference to  map file

    LDFLAGS = -Wl,-Map=$(TARGET).map,--cref

    LDFLAGS += $(EXTMEMOPTS)

    LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)

    LDFLAGS += -Wl,--section-start=.data=0x801100

    #加上上面这个语句即可以,当然上面的其他设置的关键参数也需要修改

     

    小插曲3:把PN编译后的文件都删除时,再次编译时发现没有生成文件,有bug?关闭再打开又可以编译生成文件,但再次删除编译生成的文件时->再编译->仍旧没文件生成->bug,PN version v.2.0.7.667

     

    Note:

    See explanation for offset 0x800000. See the chapter about using gcc for the -Wl options.

    ram map of avr

    Internal RAM: stack only, external RAM: variables and heap

       If dynamic memory should be placed in external RAM, while keeping the variables in internal RAM, something like the following could be used. Note that for demonstration purposes, the assignment of the various regions has not been made adjacent in this example, so there are "holes" below and above the heap in external RAM that remain completely unaccessible by regular variables or dynamic memory allocations (shown in light bisque color in the picture below).

    avr-gcc ... -Wl,--defsym=__heap_start=0x802000,--defsym=__heap_end=0x803fff ...

    untitled 

    Internal RAM: variables and stack, external RAM: heap

        If __malloc_heap_end is 0, the allocator attempts to detect the bottom of stack in order to prevent a stack-heap collision when extending the actual size of the heap to gain more space for dynamic memory. It will not try to go beyond the current stack limit, decreased by __malloc_margin bytes. Thus, all possible stack frames of interrupt routines that could interrupt the current function, plus all further nested function calls must not require more stack space, or they will risk colliding with the data segment.

    The default value of __malloc_margin is set to 32.

    contd……

    December 27

    随笔

     
    很久没来这里了,发现livespace风格还是不错的,至少没什么ad。
     
    想早点出去工作,工作的同学都说压力大。
     
    明天开始常到lab去,浮躁的心,应静下来踏实的做事情。
     
    准备一本技术日记,记下每天学的或想的,心情日记就来这里了。
     
    读研可能后悔三年,不读研可能后悔一辈子。
     
    记得刚开始时心情真的很down,现在还是有所收获的。
     
    不要遇到不顺的事情就埋怨,努力的改变自己。
     
    以后就混合着写了,e文太烂了^_^
     
     
    February 16

    broadcast yourself

    Three months ago,I read a message about youtube from one newspaper.Its main meaning is the cover of Time in 2007 is you!Youtube? I have never heard about it.What's it?At that time,I immediately wrote it down for lest I forgot it after a sudden curious.Then,after watched several funny videos,I signed up a account.The address of my own webpage in youtube is http://www.youtube.com/profile?user=mhz54. But there is no any videos in my account now.Surely,I will upload some funny videos later.
    February 06

    prison break

    Everyweek I was excited for the Tuesday to come in  during the period of preparing for the MA candidate's examination.And now it is the same experience for me.However,the feelings are absolutely different for the nervous now are rather relaxed.Okay,let's come back to the subject.The TV show Prison Break.Only a few words to describe Prison Break.Fantastic?Nervous?Or beyond description?At the beginning, I didn't care about the story I felt like it was kind of stupid to break into prison to break someone out. Nonetheless I gave it a try and I was blown away by the acting, the directing and the writing. So,every night after a 1600 meters'running ,I sat down in front of my moniter to watch Prison Break.(My classmate had downloaded it (every epsiode),indeed he is more crazy,exactly speaking,all of my college classmate.^_^)The episodes are so exciting all the time that I scream almost every time(maybe a bit exaggeration) one episode is over and I have to wait another week. Sometimes it's so exiting that I find myself shaking. I strongly recommend you have a try if you still don't watch or even hear little about it.Maybe after just a short time of episode ,you can't help saying why it's so late for me to find it.Wow,I am not willing to be a advisor!

     

    One of the  most impression person for me :Michael Scofield 

    THEN Lincoln Burrows   T-bag!

    I'm back

    After half a year's painstaking work,the MA candidate's examination is finally over.These days which i do my best
    to achieve my goal are valuable and worth remmbering.I'm back.But what about next step?
    Depend on the result,which will be published about the early of March,I will take my action that i've made.
    Indeed,i've getting ready for the coming final exam.No matter what the result will be ,i am preparing for it.
    no one will just wait the things happen.During the vacation ,i plan to study toefl ibt course and revise two subject of my major.
    Of course,it is Spring Festival!Every day will be fantastic.
    I hope all of my family,relations,and my friends will enjoy themself in the coming year.
    Happy pig's year.^_^
    March 01

    think over before action

    nothing special. just a simple  way.
    February 02

    new year

    Happy Chinese New year!
    December 16

    How to Read a Datasheet(major English)

    In order to use a PIC microcontroller, a flip-flop, a photodetector, or practically

    any electronic device, you need to consult a datasheet. This is the document

    that the manufacturer provides telling you

    • the typical device performance

     • minimum and maximum requirements and characteristics

    • what you can do to the device without harming it

    • suggested uses and hints

    Manufacturers want you, the designer, to have a successful experience with their device.

    They are trying to be helpful. They don’t always succeed. The datasheet on the following

    pages is a relatively good datasheet. It tries to concisely tell you everything you need to

    know about the device, a common 555 timer chip (the duct-tape of the electronics hobbyist).

    Most datasheets for ICs follow the same general layout. You don’t have to understand

    everything in a datasheet. There’s a lot of information that might not be of any use to you.

    The annotations that follow try to point out parts of the datasheet that you should pay

    particular attention to. Where do you find datasheets? Nowadays you can find almost any

    datasheet on the internet, often in PDF (Acrobat) form.

    For example, the LM555 datasheet from National Semiconductor is on their website

    at www.national.com.

    October 07

    do more

    National Day had gone.

    Everything will be normalization.

    Do more say less.

    Life can sure throw a good curve ball when you least expect it.

    So make a little  progress each day.

    And you will make a different.

     

     

    September 19

    Love at first sight

    Thought that I was going crazy
    Just having one of those days yeah
    Didn't know what to do
    Then there was you
     
     
    And everything went from wrong to right
    And the stars came out and filled up the sky
    The music you were plalying really blew my mind
    It was love at first sight
    Cause baby when I heard you
    For the first time I knew
    We were meant to be one
     
     
    Was tired of running out of luck
    Thinking 'bout giving up yeah
    Didn't know what to do
    Then there was you
    ---by Kylie Minogue
    September 13

    my five foibles

    Do you want to know my five foibles?
     
    Go and have a look at my Chinese version blog.
     
    September 08

    get right

    Two weeks for cource design of electronic circuit of low frequent was over.
     
    I will get right next week.
     
    haha,finally I can ……WON'T LET YOU KNOW!
    August 30

    Nothing to say

    A new semester  begin now.Nothing to say.
    August 25

    A visit to dentist

    Tomorrow I will go to see a dentist.
     
    Maybe the environment I grew up.ah...
     
    I never realize the importance of teeth.
     
    Laughter makes a difference,espcially with a white and regular teeth.
     
    Something absolute,I think.
     
    The ad supported by Crest is also very funny.
     
    ^_^
     
    August 23

    Think of you

                     In the morning
     
                    when the sun
     
                    is just starting to light the day
     
                    I am awakened
     
                    and my first thoughts are of you
     
                    At night
     
                    I stare at the dark trees
     
                    Silhouetted against the quiet stars
     
                    I am entranced into a complete peacefulness
     
                    and my last thoughts are of you