📄 pwm.c
字号:
/*****************************************************************************
* *
* ********** *
* ************ *
* *** *** *
* *** +++ *** *
* *** + + *** *
* *** + CHIPCON CC1010 EXAMPLE PROGRAM *
* *** + + *** PWM *
* *** +++ *** *
* *** *** *
* *********** *
* ********* *
* *
*****************************************************************************
* Demonstrates use of the timer module as a PWM source. Uses: *
* - PWM2_SET_PERIOD, PWM2_SET_DUTY_CYCLE macros *
* - various other HAL functions and macros *
* *
* The program configures timer 2 as a PWM timer. The pulse width can be *
* changed by turning the pot on the evaluation board. Connect P3.4 to an *
* oscilloscope or light source to observe the generated waveform. *
*****************************************************************************
* Author: TEL/ARR *
*****************************************************************************
* Revision history: *
* 1.0 2002/04/26 First Public Release *
* 1.1 2002/08/29 Modified by KHT to run at full speed, read ADC *
* *
* $Log: pwm.C,v $
* Revision 1.3 2003/08/18 12:01:13 tos
* Cosmetic preparation before release.
*
* Revision 1.2 2002/11/18 11:57:15 kht
* Added startup macros
*
* Revision 1.1 2002/10/14 09:45:07 tos
* Initial version in CVS.
*
* *
****************************************************************************/
#include <chipcon/hal.h>
#include <chipcon/cc1010eb.h>
int duty_cycle = 128;
int main(){
// Disable watchdog timer
WDT_ENABLE(FALSE);
// Startup macros for speed and low power consumption
MEM_NO_WAIT_STATES();
FLASH_SET_POWER_MODE(FLASH_STANDBY_BETWEEN_READS);
// All I/Os are inputs after reset. Make I/Os connected to LEDs outputs
RLED=YLED=GLED=BLED=LED_OFF;
RLED_OE(TRUE); YLED_OE(TRUE); GLED_OE(TRUE); BLED_OE(TRUE);
// Setup PWM2 pin direction
PORTDIRBIT(3, 4, POUT);
// Configure timer 2 as a PWM timer, max timeout interval
halConfigTimer23(TIMER2 | TIMER23_PWM, 0, CC1010EB_CLKFREQ);
PWM2_SET_PERIOD(1);
PWM2_SET_DUTY_CYCLE(duty_cycle);
TIMER2_RUN(TRUE);
// Setup ADC, select the CC1010EB pot meter, and turn it on
halConfigADC(ADC_MODE_SINGLE | ADC_REFERENCE_VDD, CC1010EB_CLKFREQ,0); // 0: Threshold value (not used in this program)
ADC_SELECT_INPUT(ADC_INPUT_AD0);
ADC_POWER(TRUE); // Power up ADC from sleep mode
// infinite loop
while(1) {
// read inputbutton
duty_cycle = ADC_GET_SAMPLE_8BIT();
ADC_SAMPLE_SINGLE();
PWM2_SET_DUTY_CYCLE(duty_cycle);
}
} // end main
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -