NY8B062E 例程之 ADC_Interrupt

本文详细介绍NY8B062E ADC转换中断结束后的工作流程,包括设置1MHz时钟、配置ADC输入、存储转换结果,并重点讲解了NY8B062E与NY8B062D的主要区别。适合了解NY8B062E ADC模块高级用法的开发者。
摘要由CSDN通过智能技术生成

转载请注明出处!


首先介绍下NY8B062E与NY8B062D最终区别:

其实NY8B062E就是NY8B062D升级款,NY8B062D基本停产了,成本也高于NY8B062E

  1. NY8B062E 有ADC 偏移校准 NY8B062D没有

  2. NY8B062E ADC耗电只需要500mV,NY8B062D则需要3mA

  3. NY8B062E 内部LDO误差只有百分之正负0.5,而NY8B062D是正负百分之1

  4. NY8B062E 输入施密特触发 是可以开启和关闭的,NY8B062D是没有的

  5. NY8B062E PWM 通道有4组(非常适合RGBW应用),NY8B062只有3路,勉强做个RGB应用

NY8B062D 视频简介

*项目:NY8B062E ADC_Interrupt
*文件:NY8B062E main.c
*描述:NY8B062E ADC转换中断结束
*1.设置ADC时钟频率为1MHz,采样脉冲宽度为8 ADC时钟,
*NY8B062E ADC转换时间=(8+12+2)*1us=22us,ADC转换率=1/22us=45.5KHz
*2.NY8B062E 将AIN1(PA1)设置为ADC模拟输入
*3.NY8B062E 将ADC转换结果bit11~bit4存储到RAM“R_AIN1_DATA_HB”,bit3~bit0存储到RAM“R_ AIN1_ DATA_ LB[3:0]”(x=0~4)

#include <ny8.h>
#include "ny8_constant.h"

unsigned char R_AIN1_DATA_HB;	
unsigned char R_AIN1_DATA_LB;

#define UPDATE_REG(x)	__asm__("MOVR _" #x ",F")

void F_wait_eoc(void);
void delay(int);

//! interrupt service routine
void isr(void) __interrupt(0)
{
	ADRbits.ADIF = 0;						// Clear adc interrupt flag bit
	R_AIN1_DATA_HB = ADD;					// RAM "R_AIN1_DATA_HB" Store AIN1's ADC data bit 11~4
	R_AIN1_DATA_LB = 0x0F & ADR;			// RAM "R_AIN1_DATA_LB" bit3~0 Store AIN1's ADC data bit 3~0
	ADMDbits.START =1;						// Start a ADC conversion session		

}

void main(void)
{
    R_AIN1_DATA_HB=R_AIN1_DATA_LB=0x00;
  //----- Initial GPIO-----
    IOSTA = C_PA_Input;						// Set PortA as input port
    PORTA = 0xFF;							// PortA Data Register = 0xFF
    INTE  = 0x00;							// INTE = 0x00

 //----- Initial ADC-----	  
	ADMD  = C_ADC_En | C_ADC_CH_Dis | C_ADC_PA1 ;	// Enable ADC power, Disable global ADC input channel. Select PA1 pad as ADC input (SFR "ADMD")
 
 //----- ADC high reference voltage source select-----
	ADVREFH = C_Vrefh_VDD;					// ADC reference high voltage is supplied by internal VDD (Note: ADC clock freq. must be equal or less than 2MHz @ VDD=5.0V) 
 	//ADVREFH = C_Vrefh_4V;					// ADC reference high voltage is supplied by internal 4V  (Note: ADC clock freq. must be equal or less than 1MHz)
 	//ADVREFH = C_Vrefh_3V;					// ADC reference high voltage is supplied by internal 3V  (Note: ADC clock freq. must be equal or less than 500KHz)
 	//ADVREFH = C_Vrefh_2V;					// ADC reference high voltage is supplied by internal 2V  (Note: ADC clock freq. must be equal or less than 250KHz)
 
//----- ADC clock frequency select----------------------------	 
	ADR	 = C_Ckl_Div1;						// ADC clock=Fcpu/1, Clear ADIF, disable ADC interrupt	
	//ADR	 = C_Ckl_Div2;					// ADC clock=Fcpu/2, Clear ADIF, disable ADC interrupt	
	//ADR	  = C_Ckl_Div8;					// ADC clock=Fcpu/8, Clear ADIF, disable ADC interrupt	
	//ADR	 = C_Ckl_Div16;					// ADC clock=Fcpu/16, Clear ADIF, disable ADC interrupt	
 
//----- ADC Sampling pulse width select-------------	 
 	//ADCR  = C_Sample_1clk | C_12BIT;		// Sample pulse width=1 adc clock, ADC select 12-bit conversion ( Note: ADC clock freq. must be equal or less than 500KHz)
 	//ADCR  = C_Sample_2clk | C_12BIT;		// Sample pulse width=2 adc clock, ADC select 12-bit conversion ( Note: ADC clock freq. must be equal or less than 1MHz)
 	//ADCR  = C_Sample_4clk | C_12BIT;		// Sample pulse width=4 adc clock, ADC select 12-bit conversion ( Note: ADC clock freq. must be equal or less than 1.25MHz)
 	ADCR  = C_Sample_8clk | C_12BIT; 		// Sample pulse width=8 adc clock, ADC select 12-bit conversion ( Note: ADC clock freq. must be equal or less than 2MHz)	

//--------------------------------------------------	
	PACON = C_PA1_AIN1;						// Set AIN1(PA1) as pure ADC input for reducing power consumption (SFR "PACON")
	ADMDbits.GCHS = 1;						// Enable global ADC channel	(SFR "ADMD")
	ADRbits.ADIF = 0;						// Clear adc interrupt flag bit
	ADRbits.ADIE = 1;						// Enable adc interrupt bit
	delay(50);								// Delay 1.12ms(Instruction clock=4MHz/4T) for waiting ADC stable
	ADMDbits.START =1;						// Start a ADC conversion session	
	ENI();
		 
    while(1)
    {
        CLRWDT();							// Clear WatchDog
    }
}

void delay(int count)
{
	int i;
	for(i=1;i<=count;i++)
	;
}

更多关于NY8B062E,请留言或者与我联系!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

倪彬笑阳

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值