its fairly easy to get 3 different pwm streams from one ccpm module , you just to need to
1. set pulse width for channel
2. set pin steering to channel pin
in a sequentially multiplexed routine
eg
Code:
/**
Generated Main Source File
Device : PIC16F1825
Driver Version : 2.00
*/
int pwmv[3];
char cnt = 0;
void ticker(void);
#include "mcc_generated_files/mcc.h"
/*
Main application
*/
void main(void) {
// initialize the device
SYSTEM_Initialize();
TMR1_SetInterruptHandler(ticker);
// When using interrupts, you need to set the Global and Peripheral Interrupt Enable bits
// Use the following macros to:
PSTR1CON = 0x10;
// Enable the Global Interrupts
INTERRUPT_GlobalInterruptEnable();
// Enable the Peripheral Interrupts
INTERRUPT_PeripheralInterruptEnable();
// Disable the Global Interrupts
//INTERRUPT_GlobalInterruptDisable();
// Disable the Peripheral Interrupts
//INTERRUPT_PeripheralInterruptDisable();
while (1) {
pwmv[cnt] = ADC_GetConversion(cnt);
__delay_ms(300);
cnt++;
cnt &= 3;
// Add your application code
}
}
void ticker(void) {
static char inx = 0;
CCPR1L = pwmv[inx] >>8;
CCP1CON = ((pwmv[inx]&0xc0)>>2) | 0xC;
PSTR1CON = 0x10 | (2 << inx);
inx++;
inx &= 3;
}
this sort of led modulation is exactly how those p10 led modules work
Last edited by richard; - 22nd January 2020 at 02:04.
Bookmarks