Hi,
I wanted to send out data at 9600 bps, and do variable duty cycle PWM @40Khz.
My PIC18F2550 is clocked @ 20Mhz and here is the code so far:
Code in PICC:
Code:
[/code]
#define _PLIB
#include <htc.h>
// will automatically include peripheral library header files when --runtime=+plib is used (had to pass this explicitly to the commandline)
#include <pic18.h>
#include <stdio.h>
void
main(void)
{
GIE=0; /* no interrupts are used */
IPEN=0;
TRISC=0; /* PORTC.1 is the output from PWM */
OpenUSART( USART_TX_INT_OFF &
USART_RX_INT_OFF &
USART_ASYNCH_MODE &
USART_EIGHT_BIT &
USART_CONT_RX &
USART_BRGH_HIGH,
129 );
/*
This function configures the specified PWM channel for period and for time base.
PWM uses only Timer2.
In addition to opening the PWM, Timer2 must also be opened with an OpenTimer2() statement before the PWM will operate.
period Can be any value from 0x00 to 0xff.
This value determines the PWM frequency by using the following formula:
PWM period = [(period) + 1] x 4 x TOSC x TMR2 prescaler */
OpenTimer2(TIMER_INT_OFF & T2_PS_1_1 & T2_POST_1_1);
OpenPWM2(124);
SetDCPWM2(0);
//SetOutputPWM2(SINGLE_OUT, PWM_MODE_1);
while (1){
putsUSART("Test\r\n");
}
CloseTimer2();
ClosePWM2();
CloseUSART();
}
[/code]
Code is incorrect as:
1. The first character (first "T") never makes it, but then I seem to get the remaining ones
2. I get no PWM output and for the love of --- could not figure out how to use SetDCPWM2, and just now, in times of desperation I put in random values, to get no change/no output :-(
Help me :-(
I wanted to send out data at 9600 bps, and do variable duty cycle PWM @40Khz.
My PIC18F2550 is clocked @ 20Mhz and here is the code so far:
Code in PICC:
Code:
[/code]
#define _PLIB
#include <htc.h>
// will automatically include peripheral library header files when --runtime=+plib is used (had to pass this explicitly to the commandline)
#include <pic18.h>
#include <stdio.h>
void
main(void)
{
GIE=0; /* no interrupts are used */
IPEN=0;
TRISC=0; /* PORTC.1 is the output from PWM */
OpenUSART( USART_TX_INT_OFF &
USART_RX_INT_OFF &
USART_ASYNCH_MODE &
USART_EIGHT_BIT &
USART_CONT_RX &
USART_BRGH_HIGH,
129 );
/*
This function configures the specified PWM channel for period and for time base.
PWM uses only Timer2.
In addition to opening the PWM, Timer2 must also be opened with an OpenTimer2() statement before the PWM will operate.
period Can be any value from 0x00 to 0xff.
This value determines the PWM frequency by using the following formula:
PWM period = [(period) + 1] x 4 x TOSC x TMR2 prescaler */
OpenTimer2(TIMER_INT_OFF & T2_PS_1_1 & T2_POST_1_1);
OpenPWM2(124);
SetDCPWM2(0);
//SetOutputPWM2(SINGLE_OUT, PWM_MODE_1);
while (1){
putsUSART("Test\r\n");
}
CloseTimer2();
ClosePWM2();
CloseUSART();
}
[/code]
Code is incorrect as:
1. The first character (first "T") never makes it, but then I seem to get the remaining ones
2. I get no PWM output and for the love of --- could not figure out how to use SetDCPWM2, and just now, in times of desperation I put in random values, to get no change/no output :-(
Help me :-(