• slider image 442
  • slider image 483
  • slider image 484
  • slider image 485
  • slider image 486
  • slider image 487
:::

論壇索引


Board index » All Posts (fer56w)




PIC16F18323 ADC to PWM
#1
新會員
新會員


各位前輩好目前使用PIC16F18323 ADC功能以及CCP功能來控制PWM DUTY

目前遇到困難在我的ADC接受外部是用可變電阻調變0~100K

但是在式波器上PWM顯示DUTY的部分卻不是線性調變

下面這邊是我的PWM輸出,而adc 以及CCPREG兩個都是選擇從右邊數
而我的RP2沒有帶入255,是用其他值去計算出來的目前已計算過為79

系統Osc 32Mhz,pwm freq :100khz


PR2 = (_XTAL_FREQ/(PWM_freq*4*1)) - 1;

void duty(unsigned int adcvaule)
{
if(adcvaule<1023) //total 10bit data
{
//adc 10bit conver back*duty formula duty cycle
//adc converter Vin=ADdata*(Vref+ - Vref-)/1023(2^10 bits)
adcvaule=(((float)adcvaule)/1023)*(4*(PR2+1)); //duty cycle * 4*pr2+1
// adcvaule = ((float)adcvaule/1023)*(_XTAL_FREQ/(PWM_freq*1));
//CCP1 select FMT0 H 2bit L 8bit
// duty reg is CCPR1H CCPR1L
//define CCPW is total CPPR1H<1:0>+CCPR1L<7:0> sum of the 10 bits reg
// CCPR1H<1:0> is using CCPW <9:8> bits
// CCPR1L<7:0> is using CCPW <7:0> bits
CCPR1H =(adcvaule>>8);// put duty first data still at 0 & 1 need to put at 8&9
CCPR1L = (adcvaule & ADRESL); //CCPR1L has 8 bit use or left it and leave the last over 2bit

}
}

發表於: 2020/5/13 20:29
頂部






:::

Microchip連結

https://www.facebook.com/microchiptechnologytaiwan/
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=13
https://mu.microchip.com/page/tmu
http://elearning.microchip.com.tw/modules/tad_link/index.php?cate_sn=1
https://page.microchip.com/APAC-PrefCenters-TW.html
http://www.microchip.com/
http://www.microchip.com/treelink
http://www.microchipdirect.com/
http://www.microchip.com.cn/newcommunity/index.php?m=Video&a=index&id=103
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=2
http://www.microchip.com.tw/Data_CD/eLearning/index.html
http://www.microchip.com.tw/RTC/RTC_DVD/
https://www.microchip.com/development-tools/
https://www.youtube.com/user/MicrochipTechnology
[ more... ]

教育訓練中心

!開發工具購買
辦法說明 [業界客戶] [教育單位]
----------------------------------
!校園樣品申請
辦法說明 [教師資格] [學生資格]
----------------------------------