728x90

728x90

Tuesday, September 16, 2025

dsPIC30F2010 Prototype Board CCS PICC Examples (Continue)

In previous post I putted some examples of using the dsPIC30F2010 prototype board. However it's too long. So I need to write some remaining posts here.

Creating a PWM Output Using Code Generation Wizard

Generating a PWM output signal could be done from scratch with a few line of code using CCS PICC. We can use its code generation wizard or even manually. 

dsPIC30F2010 Prototype Board CCS PICC Examples (Continue)
PWM Output Pin of OC1
 

After clicking on Create Project it will generate source code. Then pressing F9 to compile this project.

The main.c C source code is just like below.

  1. #include <main.h>


  2. void main()
  3. {

  4. while(TRUE)
  5. {
  6. //TODO: User Code
  7. }

  8. }

 Then double click on the main.h header file we will see its source code.

  1. #include <30F2010.h>
  2. #device ICSP=1
  3. #use delay(crystal=20000000)

  4. #FUSES NOWDT //No Watch Dog Timer
  5. #FUSES CKSFSM //Clock Switching is enabled, fail Safe clock monitor is enabled


  6. #use pwm(OC1,TIMER=2,FREQUENCY=10000,DUTY=0)


It will generate a PWM signal output at pin OC1 (RC13) with a frequency of 10kHz and 0% duty cycle. If we want a 50% duty cycle we need to change the DUTY parameter to 50, and rebuilt it.

PWM Duty Cycle Adjusting with ADC

After using the code generation wizard I got some idea of using PWM in CCS PICC. So I modify and write more codes to adjust PWM signal. I use the on-board ADC input from a potentiometer. Then it will convert to PWM duty cycle ranging from 0% to 100%.

  1. #include "board.h"

  2. #use pwm(OC1,TIMER=2,FREQUENCY=10000,STREAM=_1,DUTY=50)
  3. void main()
  4. {
  5. long adc_value = 0;
  6. float duty_cycle = 0;
  7. setup_adc_ports(sAN4);
  8. setup_adc(ADC_CLOCK_INTERNAL | ADC_TAD_MUL_31);


  9. while(TRUE)
  10. {
  11. //TODO: User Code
  12. set_adc_channel(4);
  13. delay_us(10);
  14. adc_value = read_adc();
  15. duty_cycle = (1000.0*adc_value)/1023;
  16. pwm_set_duty(_1,(int)duty_cycle);
  17. //pwm_set_duty_percent(_1,(int)duty_cycle);
  18. delay_ms(100);
  19. }

  20. }


And its "board.h" file:

  1. #include <30F2010.h>
  2. #device ADC=10
  3. #device ICSP=1
  4. #fuses HS,NODEBUG,NOWDT,PR,CKSFSM
  5. #use delay(crystal=20000000)


  6. #use FIXED_IO( D_outputs=PIN_D1,PIN_D0 )
  7. #use rs232(UART1, baud=9600, stream=UART_PORT1)

  8. #define LED0 PIN_D0
  9. #define LED1 PIN_D1
  10. #define SW0 PIN_C13
  11. #define SW1 PIN_C14

  12. #define DELAY 500


It work fine without wiring additional components. However we can connect the OC1(RC13) PWM pin to a larger LED ( for instance a 5VDC 10mm LED).

 

dsPIC30F2010 Prototype Board CCS PICC Examples (Continue)
Low Duty Cycle

dsPIC30F2010 Prototype Board CCS PICC Examples (Continue)
High Duty Cycle

ADC with On-board Tactile Switches and PWM

Fortunately there are two on-board tactile switches that could be used to adjust PWM duty cycle. So I will use ADC channel 4, SW4 (RC13) and SW5(RC14) to adjust PWM duty cycle of OC1 and OC2 respectively.

The PWM OC1 is generated by Timer 2 while the PWM OC2 is generated by Timer 3. 

 

 

320x50

Search This Blog

Labels

25AA010A (1) 8051 (7) 93AA46B (1) ADC (32) Analog Comparator (1) Arduino (15) ARM (6) AT89C52 (7) ATMega32 (57) AVR (58) CCS PICC (29) DAC (1) DHT11 (2) Display (106) Distance Sensor (3) DS18B20 (3) dsPIC (3) dsPIC30F1010 (3) dsPIC30F2010 (2) EEPROM (5) Environment Sensor (4) esp8266 (1) I2C (29) Input/Output (68) Interrupt (19) Keil (5) Keypad (10) LCD (49) Master/Slave (1) MAX7221 (1) MCP23017 (5) MCP23S17 (4) Meter (3) MikroC (2) Motor (15) MPLABX (73) Nokia 5110 LCD (3) OLED (2) One-Wire (6) Oscillator (8) PCB (10) PCD8544 (3) PCF8574 (5) PIC (108) PIC12F (3) PIC16F628A (3) PIC16F630 (2) PIC16F716 (4) PIC16F818 (11) PIC16F818/819 (3) PIC16F84A (16) PIC16F876A (2) PIC16F877A (9) PIC16F88 (2) PIC16F887 (60) PIC18 (19) PIC18F1220 (5) PIC18F2550 (5) PIC18F4550 (12) PICKit2 (1) PWM (12) RTC (9) Sensor (11) SH1106 (1) Shift Register (11) Shift Registers (3) SPI (24) STM32 (6) STM32 Blue Pill (6) STM32CubeIDE (6) STM32F103C8T6 (6) SysTick (3) temperature sensor (11) Thermometer (21) Timer/Counter (31) TM1637 (2) UART (8) Ultrasonic (4) Voltmeter (7) WDT (1) XC16 (2) XC8 (96)

tyro-728x90