Freescale HCS12 微控制器TMFreescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2005.A/D转换模块 转换模块ATD 1 ATD 0 12K SRAM 256K FLASEEPROMSCI 1SCI 1Internal BusSPI 2 SPI 1 or or PWM PWM PWM SPI 0 8 CH CH CHAN 4-7 0-3 BKP INT MMIStar12 CPUCMSIMBDMMEBI PITPIM PLLmsCAN 4 or IICmsCAN 3msCAN 2msCAN 1BDLC or msCAN 04K BYTES EEPROMECT 8 CHANSlide 1TMFreescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2005.AD转换模块 转换模块特点: 特点: 8/10 位精度 • 7 us, 10-位单次转换时间 位单次转换时间. 位单次转换时间 • 采样缓冲放大器 • 可编程采样时间 • 左/右 对齐 有符号 无符号结果数据 右 对齐, 有符号/无符号结果数据 • 外部触发控制 • 转换完成中断 • 模拟输入 通道复用 模拟输入8通道复用 • 模拟 数字输入引脚复用 模拟/数字输入引脚复用 • 1到8转换序列长度 到 转换序列长度 • 连续转换模式 • 多通道扫描方式Slide 2TMFreescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2005.A/D 寄存器控制寄存器 状态寄存器转换结果寄存器Slide 3TMFreescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2005.A/D 控制寄存器2 控制寄存器ADPU - A/D 电源使能/禁止 1 = A/D模块上电 0 = 禁止A/D,以减少功耗 AWAI - A/D 等待模式 1 = 等待模式下,转换 0 = 等待模式下,禁止转换 ASCIE - A/D 顺序完成中断使能 ASCIF - A/D 顺序完成标志位ATDCTRL2Address offset $0002AFFC - A/D 快速转换完成标志位清零 1 = 快速标志位清零顺序 每次读取结果寄存器自动清零 0 = 正常标志位清零顺序 需要手动对状态标志位清零ETRIGLE x x 0 0 1 1Slide 4TMETRIGP x x 0 1 0 1ETRIGE 0 0 1 1 1 1SCAN 0 1 X X X X描述 忽略外部触发,执行一次转换后停止 忽略外部触发,执行连续转换后 下降沿触发,每次触发,执行一次转换 上升沿触发,每次触发,执行一次转换 低电平触发,每次触发,执行连续转换 高电平触发,每次触发,执行连续转换Freescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2005.A/D 控制寄存器 控制寄存器3ATDCTRL3 Address offset $0003FIFO – 结果寄存器 FIFO 1 = 结果寄存器没有映射到转换序列 0 = 结果寄存器没有映射到转换序列转换序列长度FRZ 00 01 10 11 ReservedResponse Ignore IFREEZE Finish conversion, then freeze Freeze Immediately转换序列长度就是需要转换的通道数 比如: 通道0,1,2作为AD采集通道 则转换序列为3,即S2C=1,S1C=1 在控制寄存器5 ATD0CTL5中: 设CC CB CA = 0 0 0,转换序列从通 道0开始;ATD0DR0, ATD0DR1,ATD0DR2存放转换结果 设CC CB CA = 0 1 0,转换序列从通 道2开始。
仍然是ATD0DR0, ATD0DR1,ATD0DR2存放转换结果Slide 5TMFreescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2005.A/D 时钟选择 预分频 时钟选择/• 最大 A/D 时钟 = 2.0 MHz (最小 A/D CLOCK = 0.5 MHz) 最小ATDCTL4(HI) - A/D 控制寄存器 Address offset $0004采样时间选择SRES8 - A/D 精度选择 1=8位 0 = 10位 位 5位 模数计数器预分频器 - 由A/D控制寄存器中的PRS[4:0]控制 - 分频系数从2到64 - 如果 PRS[4:0] = 0, 预分频不起作用 注: 设置PRS[4:0]时, A/D Clock 不能大于 2 MHz.PRS0-PRS4SMP [1:0] 00 01 10 11采样时间 2 A/D时钟周期 4 A/D时钟周期 8 A/D时钟周期 16 A/D时钟周期系统时钟5位 模数计数器 位 预分频器Slide 6TM除2A/D 时钟Freescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2005.转换时间A/D 时钟总是2 个 时钟周期2, 4, 8, 16 时钟周期CCF标志位置位,如果在8通道模式下,序列结束转换时间计算举例:(假设 2MHZ A/D 时钟频率)例 1: 转换时间 = Initial Sample Time + Programmed Sample Time + Resolution Period = 2 + 2 + 10 = 14 A/D Clocks = 7uSec 例 2: 转换时间= Initial Sample Time + Programmed Sample Time + Resolution Period = 2 + 16 + 10 = 28 A/D Clocks = 14uSecSlide 7TMFreescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2005.A/D控制寄存器 控制寄存器5 控制寄存器Address offset $0005ATDCTRL5SCAN – 连续转换模式 1 = 连续转换模式 0 = 单次转换 DSGN – 符号选择 1 = 有符号 0 = 无符号 MULT – 多通道采样模式 1 = 多通道转换 0 = 单通道转换DJM – 对齐方式 1 = 右对齐 0 = 左对齐通道选择 0 0 0 = Chan 0 1 1 1 = Chan 7注意:对这个寄存器写操作时,将会中断当前的转换,然后重新启动新的转换序列 注意:对这个寄存器写操作时,将会中断当前的转换,Slide 8TMFreescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2005.A/D 状态寄存器ATDSTAT0Address Offset $0006ATDSTAT1 SCF – 转换序列完成标志 - 在单次转换模式时,当转换完成后置位 (SCAN = 0) 在连续转换模式时,当第一次转换完成后置位 (SCAN = 1). 当 (AFFC = 0) ,写1清零. ETORF - 外部触发覆盖标志 - 如果在转换过程中高/低电平出现,置位 FIFOR – 当结果寄存器在读出之前已经被写入时,置位 ( CCF没有清零) CC[2:0] – 转换计数器 3-位计数器指向下一个将要转换的通道 CCF7 -CCF0 – 独立通道转换完成标志位 每个相应的通道转换结束后置位, 当相应的A/D结果寄存器被读出 时,清零Slide 9TM$0007Freescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2005.转换结果寄存器左对齐数据存放格式Address Offset $0010 - $0011 $001E - $001F//假设左对齐10位精度 Word AD_wValue;右对齐数据存放格式 右对齐数据存放格式AD_wValue = ATD0DR0>>6; Address Offset $0010 - $0011 $001E - $001FSlide 10TMFreescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2005.A/D口寄存器 口寄存器Address Offset $000FPORTAD1ADA7 ADA6A T D P TADA5 ADA4 ADA3 ADA2 ADA1 ADA0ATDDIEN - ATD 数字输入使能注意:任何一个引脚可以用作A/D或数字输入Slide 11TMFreescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2005.AD使用示例 查询方式 使用示例-查询方式 使用示例void AD_Init(void) //初始化 { ATD0CTL2=0xC0; //AD模块上电, 快速清零, 无等待模式, 禁止外部触发, 中断禁止 ATD0CTL3=0x20; // 每个序列4次转换, No FIFO, Freeze模式下继续转换 ATD0CTL4=0x83; // 8位精度, 2个时钟, ATDClock=[BusClock*0.5]/[PRS+1] ; PRS=3, divider=8 ATD0CTL5=0xA0; //右对齐无符号,单通道采样,通道0 ATD0DIEN=0x00; // 禁止数字输入 } void AD_GetValue(word *AD_wValue) //读取AD转换结果 { *AD_wValue = ATD0DR0; //Read out the Result Register }word AD_wValue; void main(void) { word i; AD_Init(); //AD初始化 DDRB = 0xFF; PORTB = 0x00; EnableInterrupts; for(;;) { while(!ATD0STAT1_CCF0); //等待转换结束 AD_GetValue(&AD_wValue); //读取转换结果 PORTB = (byte)AD_wValue; //在B口显示转换值 } }Slide 12TMFreescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2005.AD使用示例 中断方式 使用示例-中断方式 使用示例word AD_wData = 0; void main(void) { word i; AD_Init(); DDRB = 0xFF; PORTB = 0x00; EnableInterrupts; for(;;) { PORTB = (byte)AD_wData; } } void AD_Init(void) { ATD0CTL2=0xC2; //AD模块上电, 快速清零, 无等待模式, 禁止外部触发, 中断开放 ATD0CTL3=0x20; ATD0CTL4=0x83; ATD0CTL5=0xA0; ATD0DIEN=0x00; } #pragma CODE_SEG NON_BANKED void interrupt 22 Int_AD0(void) { AD_wData = ATD0DR0; //Read out the Result Register }Slide 13TMFreescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2005.AD使用例程 使用例程void AD_Init(void) //AD初始化 { //控制寄存器2: 上电,标志位快速清零,开中断 ATD0CTL2 = (ATD0CTL2_ADPU_MASK|ATD0CTL2_AFFC_MASK|ATD0CTL2_ASCIE_MASK); //控制寄存器3:转换序列长度为3,FIFO模式 ATD0CTL3 = (ATD0CTL3_S2C_MASK|ATD0CTL3_S1C_MASK|ATD0CTL3_FIFO_MASK); //控制寄存器4: ATD0CTL4 = (ATD0CTL4_SRES8_MASK|ATD0CTL4_PRS1_MASK|ATD0CTL4_PRS0_MASK); //控制寄存器5: ATD0CTL5 = (ATD0CTL5_DJM_MASK|ATD0CTL5_SCAN_MASK|ATD0CTL5_MULT_MASK); ATD0DIEN=0x00; // 禁止数字输入缓冲 } #pragma CODE_SEG NON_BANKED //中断服务程序 void interrupt 22 Int_AD0(void) { AD_wData[0] = ATD0DR0; //将结果寄存器中的值存放到数组中 AD_wData[1] = ATD0DR1; //将结果寄存器中的值存放到数组中 AD_wData[2] = ATD0DR2; //将结果寄存器中的值存放到数组中 } #pragma CODE_SEG DEFAULT_ROMSlide 14TMFreescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2005.word AD_wData[3]; //全局变量存放 AD0,AD1,AD2的结果 void main(void) { dword i; AD_Init(); //AD 初始化 DDRB = 0xFF; PORTB = 0x00; AD_wData[0] = 0; //全局变量初始化 AD_wData[1] = 0; AD_wData[2] = 0; EnableInterrupts; for(;;) { if(ATD0CTL2_ASCIE == 0) //采用查询方式 { while(!ATD0STAT1_CCF0); //等待通道0转换结束 AD_wData[0] = ATD0DR0; //读通道0的转换结果 while(!ATD0STAT1_CCF1); //等待通道1转换结束 AD_wData[1] = ATD0DR1; //读通道1的转换结果 while(!ATD0STAT1_CCF2); //等待通道2转换结束 AD_wData[2] = ATD0DR2; //读通道2的转换结果 } PORTB = (byte)AD_wData[0]; //用PORT B来显示AD0的值 for(i=0;i<0xFFFFF;i++); //delay PORTB = (byte)AD_wData[1]; //用PORT B来显示AD1的值 for(i=0;i<0xFFFFF;i++); //delay PORTB = (byte)AD_wData[2]; //用PORT B来显示AD1的值 for(i=0;i<0xFFFFF;i++); //delay } }Slide 15TMFreescale Semiconductor Confidential and Proprietary Information. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2005.。