Hi there,
Can someone please assist me with the enabling a PWM outpit channel for sending a very specific signal as output .
Signal that need to be sent is in the following format
for transmitting Data 0 : 1ms high level + 3ms low level
for transmitting Data 1 : 3ms high level + 1ms low level
I want to send the 0x5555 which in Binary is 0101010101010101. So, i belive this can be send through the PWM output. If,yes. How can i set up the PWM for an output GPIO. And send the above mentioned signal
P.s: I am using a S32k14x EAR SDK v0.8.6
So, please kindly assist me in any way possible
Hi,
signal looks very similar as one mentioned in https://mcuoneclipse.com/2016/05/22/nxp-flexio-generator-for-the-ws2812b-led-stripe-protocol/ maybe you can refer to this or other links mentioned there.
BR, Petr
Hi @PetrS ,
Currently i am trying to interface the LED Stripe WS2812B with NXP S32k344 . I want to generate the PWM (24bits) to control the RGB LED . Please suggest which SW driver(Flexio_PWM , EMIOS_PWM ) should i need to use it for PWM generation. Please share me the configuration for the respective driver along with the any sample code if possible.
Thanks!
Hi @PetrS
I have tried to develop the code with out the requirement of PWM. But i am getting some system and syntax error from the software. which i couldn't able to resolve . attaching the code and the error information below. Please help me understand the error and also can you please judge my code. let me know anywhere i can improve or make changes.
/* Including needed modules to compile this module/procedure */
#include "S32K146.h"
#include "Cpu.h"
#include "clockMan1.h"
#include "pin_mux.h"
volatile int exit_code = 0;
/* User includes (#include below this line is not maintained by Processor Expert) */
#include <stdint.h>
#include <stdbool.h>
//#define LED_PORT PORTD
//#define GPIO_PORT PTD
//#define PCC_CLOCK PCC_PORTD_CLOCK
//#define LED1 15U
//#define LED2 16U
#define LOCK_COMM 7 //Output
#define Lock_Status 1 //Locked: 1, Unlocked 0
#define LOCK_COMMAND 0xAAAA //1010 1010 1010 1010
#define UNLOCK_COMMAND 0x5555 //0101 0101 0101 0101
void delay_ms(uint32_t milliseconds)
{
/* Delay function - do nothing for a number of cycles */
uint32_t ticks = milliseconds*(SystemCoreClock / 1000);
while(ticks--){}
}
void sendData( int dataLevel )
{
if (dataLevel == 1)
{
// Data 1:
// Turn on the LED
PTE->PCOR |= (1 << LOCK_COMM);
delay_ms(3);
// Turn off the LED
PTE->PSOR |= (1 << LOCK_COMM);
delay_ms(1); // Total 4ms delay
}
else if (dataLevel == 0)
{
// Data 0:
// Turn on the LED
PTE->PCOR |= (1 << LOCK_COMM);
delay_ms(1);
// Turn off the LED
PTE->PSOR |= (1 << LOCK_COMM);
delay_ms(3); // Total 4ms delay
}
//void initOneWirePin(void)
//{
// //configure GPIO pin PTE7 for command transmission
// PTE->PDDR &= ~COMMAND_PIN_MASK; // Set pin as input (pull-up)
//}
int main(void)
{
/*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
#ifdef PEX_RTOS_INIT
PEX_RTOS_INIT(); /* Initialization of the selected RTOS. Macro is defined by the RTOS component. */
#endif
/*** End of Processor Expert internal initialization. ***/
//initOneWirePin();
// Enable clock to PORT E (where the LOCK_COMM is connected)
PCC->PCCn[PCC_PORTE_INDEX] |= PCC_PCCn_CGC_MASK;
// Set pin as GPIO
PORTE->PCR[LOCK_COMM] |= PORT_PCR_MUX(1);
// Set pin as output
PTE->PDDR |= (1 << LOCK_COMM);
while (1)
{
int k = 0;
if (Lock_Status == 1){
// send 0xAAAA
delay_ms(5); //sync. head
for (int i = 0; i < 15; i++) {
//sendData(1);
//sendData(0);
sendData((LOCK_COMMAND >> i) & 0x01); // Send each bit of the lock command 1 or 0
}
delay_ms(4); //ACK
}
else if(Lock_Status == 0){
// send 0x5555
delay_ms(5); //sync. head
for (int i = 0; i < 15; i++) {
//sendData(0);
//sendData(1);
sendData((UNLOCK_COMMAND >> i) & 0x01); // Send each bit of the unlock command 1 or 0
}
delay_ms(4); //ACK
}
delay_ms(200);
if( k += 10)
{
break;
}
}
/*** Don't write any code pass this line, or it will be deleted during code generation. ***/
/*** RTOS startup code. Macro PEX_RTOS_START is defined by the RTOS component. DON'T MODIFY THIS CODE!!! ***/
#ifdef PEX_RTOS_START
PEX_RTOS_START(); /* Startup of the selected RTOS. Macro is defined by the RTOS component. */
#endif
/*** End of RTOS startup code. ***/
/*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/
for(;;) {
if(exit_code != 0) {
break;
}
}
return exit_code;
/*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/
}/*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/
/* END main */
/*!
** @}
*/
/*
** ###################################################################
**
** This file was created by Processor Expert 10.1 [05.21]
** for the Freescale S32K series of microcontrollers.
**
** ###################################################################
*/
In the below image you can also notice the error symbol in the project tree at sendData function. So, is there any issue with my sendData function.?