Hi all
I have a signal PWM in my BLE peripheral project example, and it works.
the thing is that in the function periodictask in the simpleBLEperipheral project i want to call to my function call Change_DutyCycle
to change the value of T4CC1 to the value of the characteristic value 1
I try this but the pwm appear at the beginning with the initial value, but when the program enter in the periodictask the PWM stop, it could be
because the initial value of the characteristic value 1 is 1 but i change it and nothing change, so i think that my problem is my function Change_DutyCycle
and i know if i need to add anything more
Here i go my code:
here is the file of the PWM
/*******************************************************************************
Filename: PWM1.c
Description:
*******************************************************************************/
/*******************************************************************************
* INCLUDES
*/
#include <hal_types.h>
// Include Name definitions of individual bits and bit-fields in the CC254x device registers.
#include <ioCC254x_bitdef.h>
// Include device specific file
#include "ioCC2541.h"
#include "PWM1.h"
/*******************************************************************************
* @fn main
*
* @brief Configures P1_0 as Timer 4 output, sets up Timer 4 for centre-
* aligned PWM operation and enables overflow interrupts.
*
* @param void
*
* @return 0
*******************************************************************************/
void PWM_Init(void)
{
/***************************************************************************
* Setup clock & frequency
*/
// Set global timer tick frequency to 4 MHz
CLKCONCMD = (CLKCONCMD & ~CLKCON_TICKSPD) | CLKCON_TICKSPD_250K;
/***************************************************************************
* Setup peripheral I/O for Timer 4
*/
// LED1 as GPIO.
// Set LED1 as output.
P1SEL |= 0x02;
//Select Timer 4 pin location as alterntive 1
PERCFG &= ~0x08;
/***************************************************************************
/***************************************************************************
* Timer 4 Setup
*
* Timer 4 channel 1 compare control configuration. Selects the output mode
* so that the output is set on compare-up and cleared on compare-down and
* enables compare mode. This also disables compare interrupts.
*/
T4CCTL1 = T4CCTLn_CMP_SET_CMP_UP_CLR_0 | T4CCTLn_MODE;
/* Timer 4 channel 0 compare value. Sets the Timer 4 terminal count value
* to 244, which makes the Timer count up to 244 before counting down to 0.
* Hence it controls the PWM period and dynamic range.
*/
T4CC0 = 0xFF;
/* Timer 4 channel 1 compare value. Sets the initial compare value to 0x40
* This value controls the pulse width (duty cycle) and is changed at each
* Timer overflow interrupt.
*/
T4CC1 = 0x40;
/* Timer 4 control. Sets the prescaler divider value to 128, starts the Timer,
* enables overflow interrupts, clears the Timer and sets the mode to
* up-down.
*/
T4CTL = T4CTL_DIV_128 | T4CTL_START | T4CTL_OVFIM |
T4CTL_CLR | T4CTL_MODE_UPDOWN;
}
/*******************************************************************************
* @fn
*
* @brief Timer 4 channel 1 compare value. Sets the initial compare value.
* This value controls the pulse width (duty cycle)
* @param void
*
* @return 0
*******************************************************************************/
void PWM_ChangeDutyCycle (uint8 valueT4CC1)
{
T4CC1 = valueT4CC1;
}
And here is my function periodic task in the simpleBLEPeripheral
static void performPeriodicTask( void )
{
uint8 valueToCopy;
uint8 stat;
// Call to retrieve the value of the third characteristic in the profile
stat = SimpleProfile_GetParameter( SIMPLEPROFILE_CHAR1, &valueToCopy);
if( stat == SUCCESS )
{
/*////////////////////////////////////////////////////////////
CAMBIO EL DUTY CYCLE DE LA PWM
*///////////////////////////////////////////////////////////
PWM_ChangeDutyCycle(valueToCopy); <-----------------HERE IS THE PROBLEM, I DOESNT WORK PROPERLY, WHEN THE PROGRAM ENTER HERE, THE
} THE PWM STOP WORKING
}
and in the function SimpleBLEPeripheral_Init
i call PWM_Init();
I know that is not a problem of the PWM because if i dont use change_dutyCycle it works, but the problem is when i want to use it
to change the duty cycle and change the light power of some led.
thanks and sorry for the long code, but i dont know how to explain it