/* * File: main.c * Example of using a 16-bit tuning word for a simple DDS (Direct…
- User
/*
- File: main.c
- Example of using a 16-bit tuning word for a simple DDS (Direct Digital Synthesis)
- on a PIC16F1503 with minimal float usage to reduce memory overhead.
- The code demonstrates:
-
- 16-bit phase accumulator (phAcc).
-
- 16-bit tuning word calculation using purely integer math.
-
- A 256-sample sine lookup table.
-
- 3-phase output using 3 PWM channels if available (PWM1, PWM2, PWM3).
- NOTE:
-
- Adjust oscillator settings, #pragma config, and #defines for your hardware.
-
- This example uses minimal float usage only for an optional setFrequency16Bit()
- function. If needed, you can remove or replace it with completely integer-based math. */
/----------------------------------------------------------------------------/ /* PIC16F1503 Configuration Bit Settings / /----------------------------------------------------------------------------*/ // CONFIG1 #pragma config FOSC = INTOSC // Oscillator: INTOSC #pragma config WDTE = OFF // Watchdog Timer Enable: off #pragma config PWRTE = OFF // Power-up Timer Enable: off #pragma config MCLRE = OFF // MCLR Pin Function: MCLR off (digital input) #pragma config CP = OFF // Flash Program Memory Code Protection: off #pragma config BOREN = OFF // Brown-out Reset Enable: off #pragma config CLKOUTEN = OFF // Clock Out Enable: off
// CONFIG2 #pragma config WRT = OFF // Flash Memory Self-Write Protection: off #pragma config STVREN = OFF // Stack Overflow/Underflow Reset Enable: off #pragma config BORV = LO // Brown-out Reset Voltage: low trip point #pragma config LPBOR = OFF // Low-Power Brown Out Reset: off #pragma config LVP = OFF // Low-Voltage Programming Enable: off
#include <xc.h> #include <stdint.h>
/----------------------------------------------------------------------------/ /* Defines / /----------------------------------------------------------------------------*/ #define _XTAL_FREQ 16000000UL // 16 MHz internal oscillator #define SAMPLE_RATE 17085UL // Approx. PWM or interrupt frequency
/----------------------------------------------------------------------------/ /* DDS Global Variables / /----------------------------------------------------------------------------*/
- Assistant