2011年10月4日星期二

Arduino LCD programming

Today, I wrote an arduino program to control the LCD at Chaihuo. There are eight channels on the LCD, you can press the button to change the channel, current channel has a asterisk "*" mark, and tuning the knob will adjust current channel's value.



P.S: I think Tully is very good at photography, I like his photos so much :-)

2011年9月12日星期一

Be the change you want to see!

These days, I am so happy to meet a guy whose name is Mitch, a versatile person from Australia. While talking about software, I am convinced that he is a software engineer; while talking about hardware, I am also sure he is a hardware engineer; while even talking about economy, I was wondering if he is a economist? With so many deep understanding :-) .

Moreover, he is a guy who fully understands the spirit of open source. He brought beer, playpause and lots of interesting projects to SZDIY, and all of these projects are open source. So Mitch really truly thoroughly makes a change to SZDIY, that is why SZDIY has a big day called "Mitch joins SZDIY".

For me, he suggested me that "be the change you want to see". I think I am ready to go, even every step is tiny, the combination will make that change!

Thank you Mitch, I appreciate all the help you've given me!

2011年8月10日星期三

AMCC 1.0 release

I am happy to announce that AMCC 1.0 is coming, have fun!
AMCC github









/*
* AMCC (Anders Ma Copter Control)
* (www.andersma.net)
*/


General Information
===================

AMCC is an utility for copter development.
With AMCC you can monitor copter's sensors data, you can use sensors data
to develop flight control algorithm. In the future, you can use AMCC to
config and operate copter.

Licensing
=========

AMCC is released under BSD license.

Requirements
============

To compile AMCC, you must install following packages:

* libgtk2.0-dev
* libgtkglext1-dev
* freeglut3-dev
* lib3ds-dev
* libxml2-dev

HOW-TO
============

To use AMCC to monitor/control copter, copter must support AMCC protocol, How?

1) Copter MCU software must contain following code and linked with src/packet.c:

#include "packet.h"

char buffer[50];
packet_t p;

p.type = ANALOG_DATA_RESPONSE;
p.raw.analog_data.channel_number = 6;
p.raw.analog_data.value[0] = accx; /* accelerometer X axes data got from ADC */
p.raw.analog_data.value[1] = accy; /* accelerometer Y axes data got from ADC */
p.raw.analog_data.value[2] = accz; /* accelerometer Z axes data got from ADC */
p.raw.analog_data.value[3] = gyrox; /* gyroscope X axes data got from ADC */
p.raw.analog_data.value[4] = gyroy; /* gyroscope Y axes data got from ADC */
p.raw.analog_data.value[5] = gyroz; /* gyroscope Z axes data got from ADC */

packet_encode(&p);
memcpy(buffer, &p.data, p.data_length);
txd_buffer[p.data_length] = 0;
printf("%s", buffer); /* output data over serial port */

2)connecting PC with copter as below:

[PC] ---serial line----- [Copter]

3) #./amcc -d /dev/SERIALDEV -s SPEED
(replace SERIALDEV and SPEED according your environment, default is ttyUSB0, 57600)

4) Click menuitem "Monitor->Start", if copter is sending sensors data, AMCC will draw Acc & Gyro voltage graph and render 3D copter.



2011年8月6日星期六

日记 2009 07~09

2009年折腾一款STM32F103开发板的日记。回顾日记,发觉自己每年七月八月很多产,很努力!

7/27/2009
Vista上安装MDK 设置J8J9启动方式
7/28/2009
NOR/SRAM/NAND
仿真软件Openocd JLINK读回Flash数据并做了对比,发现板子程序与我编译出来的程序只有时间上的差异。
用MDK生成bin文件方法:fromelf.exe --bin -o $L@L.bin #L
7/29/2009
STM32 demo using Eclipse, OpenOCD and GCC http://developers.stf12.net/eclipse-demo
根据"图解MDK 3.5+Jlink V7在STM32中SRAM调试成功"文档, 成功下载GPIO程序到板子上,在不烧FLASH的情况下对程序进行了验证,非常好玩!
7/30/2009
学习 cortexm3_macro.s & stm32f10x_vector.s 文件
使用Keil Simulator 来仿真调试,查看汇编代码 分析Keil Linker control code: --ro-base 0x08000000 --entry 0x08000000 --rw-base 0x20000000 --entry Reset_Handler --first __Vectors -结论是编译出来的程序以__Vectors文本区块打头
7/31/2009
阅读STM32103XX参考手册
8/10/2009 研究用串口烧写程序,用那个Demonstrator总是不能成功操作,非常不爽 :(
8/13/2009
从Micrium官方下载了 STM32的uC/OS-II,看了些文档,并与红牛板子的包做了些对比。
8/14/2009
看了一些LCD的接口,了解了大概操作LCD的步骤。下面是红牛板子的相关信息:
LCD 采用FSMC_NE4 PIN做片选,访问地址为 0X6C000000
NOR 采用FSMC_NE2 PIN做片选,访问地址为 0X64000000
SRAM 采用FSMC_NE3 PIN做片选,访问地址为 0X68000000
NAND 采用FSMC_NCE2 PIN做片选,访问地址为 0X70000000
回家把ouravr网友的tft程序放到我的板子里,可以看到屏幕显示文字,不过字却是反的,需要继续debug。
8/15/2009
合并了板子自带的LCD驱动初始化代码,依然没有解决问题,反而不显示文字了,看来需要更深入的读一下DS。
8/16/2009
修改了一下绘制行和字符的函数,目前可以正常显示字符。
8/17/2009
阅读了ILI9325的DS 1-7章
8/21/2009
阅读STM32103XX参考手册ADC章节[ST11.3.7]
8/22/2009
阅读STM32103XX参考手册ADC章节[ST11.9]
折腾串口程序,发现接收卡死在那里,最后我认定是串口有问题,与卖家协商更换。
深圳市龙岗区布吉荣超花园xx栋x单元xxx,胡先生,13392xxxxxx
8/23/2009
1. 粗略阅读STM32103XX参考手册 Memory and Bus Architecture 和 RCC 章节, 基本掌握系统架构
2. 弄清楚Rcc_Configuration()函数细节
3. 粗略阅读STM32103XX参考手册 Interrupts and Events 章节
8/24/2009
1. 阅读一下ST ADC3的例子
2. 阅读Cortex-M3 Tech Ref Manual NVIC 部分
8/25/2009~8/26/2009
1. 拿回来了板子,在家做测试
2. 目前串口可以烧写程序了,之前烧写不成功主要是速度过快的问题,设置低速比较好
3. 烧写程序应该使用hex的格式,bin的烧进去不能执行
8/26/2009
1. 晚上花了2个小时对加速度传感器模块进行实验,得出如下结论
a. SLEEP PIN 需要拉高(3.3V),才能使加速度传感器进入工作模式
b. Z轴长期处于+-g的输出电压模式,其他轴如果水平状态下呈0g电压状态
c. 实验数据:X 1.69,Y 1.50, 0.83
备注:中途实验不成功,我打算明天焊接实验班再做实验,不过时间足够,我逼迫自己继续下去,我又一次战胜自己的懒惰!
8/27/2009
1. 白天在公司写了ADC数据处理程序,带串口和LCD数据输出
2. 晚上回来对程序进行验证,串口和LCD都正常,靠,有点佩服自己了,哈~
3. 接好ADC线,发现数据正常,ADC用[0~4096]来诠释[0~3.3v]电压,目前我的XYZ轴数据分别为
8/28/2009
1. 阅读MK 0.71代码,
a 寻找如何传送加速度计调试数据
b 寻找MK如何处理加速度计的方法(起飞前用200次的数据校正加速度计,Nature/Mean方式设计得还算巧妙)
2. MK 利用了"卡尔曼滤波"理论来控制飞行姿态
3. 晚上回来调试程序,目前可以用MK的程序来显示我ADC的变化了,哈哈啊哈~
8/28/2009
1.开始重头学习高等数学
2. 尝试使用SD卡程序,结果不能读,看来是SD卡读那块有问题,需要继续解决。
1/9/2009~2/9/2009
1 研究飞控算法,有些突破的就是明白如何校正那些传感器。(a 左上校正sensor,同时NICK&ROLL的数值决定选择哪套参数 b 右上保存传感器信息到EEPROM c 右下开启马达准备飞行)
2 ENC03采用科里奥里力来获取角速度,所以我需要弄清楚陀螺仪原理 http://zh.wikipedia.org/wiki/科里奥利力
3/9/2009
1 了解电磁波/射频(>100KHZ的电磁波)定义 a c=λf
2 雷达是用电磁波来探测目标,并检测其速度和其他特征的一种电子设备
3 回想起当初TVBGONE 38K红外载波的意思,只是形成频率是38K的脉冲去驱动红外发射LED而已。
4 UAV unmanned aerial vehicles
5 1 000 000 nm = 1m
6 微波波长范围在 1mm~1m
5/9/2009
1 飞控算法电机调整口诀: 左+右-;前+后- (+-pd_result)
7/9/2009
1 为什么MK中计算陀螺仪的积分就变成了单纯的ADC差值?
13/9/2009
1 这个周末去学校玩了一下飞行器,基本掌握如何操纵它

2011年8月3日星期三

2011年7月29日星期五

NOVELL She Calves Puzzle

iIf a cow produces its first she-calf at age two years and after that
produces another single she-calf every year, how many she-calves are
there after 12 years? assuming none die.

My Answer

2011年7月17日星期日

Linux 0.11 内核完全注释 笔记(三)

>2 fork 做什么?
>半斤回答:准备LDT,TSS,页目录,页表...

在Linux内核中,一个进程是用struct task_struct类型的变量来标记。所以fork首先是创建了一个新的struct task_struct类型的变量,对其进行相应的赋值。

重要的是,新建进程的TSS,LDT表,页目录和页表是全新创建的,在存储上和父进程完全没有关系,不同的两个实体。但新进程LDT所指向的数据段和代码段完全照抄父亲进程,指令指针也同父进程一致。也就是说,父子进程共享代码段,数据段和堆栈段都是相同的地址空间。好比两个锦囊装着同一妙计,嘿嘿!

插一句:从这里看fork的两次返回是那么的自然,两个进程指令指针(EIP)都一样,能没有两个返回吗?

更重要的事,fork过程中将父子进程所有页表都设置成了Read Only, 为啥子啊? 为了实现Copy On Write技术。由于页表项设置成了只读模式,每次写页表项所对应的页面时(比如函数调用把参数放入堆栈)都会引起写保护页异常,CPU会自动执行异常处理函数,进而调用 do_wp_page 函数来分配一个新的页面,挂载到引起写异常的页表项目,之后设置页表项可读可写。这个技术就叫Copy On Write。Copy On Write 完全是一种按需分配的技术,缺页/写保护页面异常是伟大的设计,因为它缔造了Copy On Write,缔造了虚拟内存技术!

这里还有一个问题值得思考,假设fork之后的程序马上会对数据段进行写动作,进而导致CPU进入写保护页面异常处理程序,谁的页表项会指向新分配的空间呢?父 or 子?

答案取决于谁先引起写保护页面异常。假设儿子引起了异常,那么儿子的页表项会指向新的分配空间;假设是父亲引起了异常,父亲的页表项会指向新空间,这样之前父亲占用的空间就归儿子所有了。很有趣的逻辑啊!

代码参考:
sys_fork -> copy_process
http://oldlinux.org/lxr/http/source/kernel/fork.c#L68
un_wp_page
http://oldlinux.org/lxr/http/source/mm/memory.c#L221