AnsweredAssumed Answered

Pulse Postion Modulation or Pulse Distance Protocol

Question asked by Satinder Sekhon on Jan 14, 2012
Latest reply on Jan 25, 2012 by bigmac

Hi,

 

I am trying to generate PPM signal using MCS9S08SG4 microcontroller but have been unsuccessful so far. I am using time pulse modualtor to generate these pulses. Since time period for sending logic 0 and logic 1 is different so I have set two mod counter( TPM1MOD) one for each logic 0 and logic 1 after checking which bit has to be sent. But the problem is that I am redundant pulses which do not want. The whole purpose of writing this code is that I am writing this code to implement steering wheel control for a vehicle whose input is given to car audio. Can anybody tell me if I am using the correct approach. Please see my code below. Also check PDP for the protocol that I am trying to implement.

 

#include <hidef.h> /* for EnableInterrupts macro */
#include "derivative.h" /* include peripheral declarations */


// DEFINE ////////////////////////////////////////////////////////////
//---------------------------------------------------------------------


#define CH7 0b00000000


// GLOBAL VARIABLES ///////////////////////////////////////////////////
//---------------------------------------------------------------------
#pragma CONST_SEG SATINDER
const unsigned int Count;
unsigned int repeat_frame=0;
unsigned int i=0;
unsigned int flag=0;
unsigned int bit=0;
const unsigned int Mode[33] = {1,0,0,1,1,1,0,1,0,1,1,0,0,0,1,0,1,1,0,0,1,0,0,0,0,0,1,1,0,1,1,1,1};
const unsigned int SeekPlus[] = {1,0,0,1,1,1,0,1,0,1,1,0,0,0,1,0,1,1,0,1,0,0,0,0,0,0,1,0,1,1,1,1,1};
const unsigned int SeekMinus[33] = {1,0,0,1,1,1,0,1,0,1,1,0,0,0,1,0,0,1,0,1,0,0,0,0,1,0,1,0,1,1,1,1,1};
const unsigned int VolumePlus[33] = {1,0,0,1,1,1,0,1,0,1,1,0,0,0,1,0,0,0,1,0,1,0,0,0,1,1,0,1,0,1,1,1,1};
const unsigned int VolumeMinus[33] = {1,0,0,1,1,1,0,1,0,1,1,0,0,0,1,0,1,0,1,0,1,0,0,0,0,1,0,1,0,1,1,1,1};

#pragma CONST_SEG DEFAULT

unsigned int Input_Voltage=0;


// FUNCTION HEADERS ///////////////////////////////////////////////////
//---------------------------------------------------------------------
void MCU_Init(void);
void MCU_Delay(word delay);
void Gen_PWM(const unsigned int data[]);
word read_adc(byte chan); // Analog-to-Digital Converter byte word: enter channel to read

// *** MAIN ***********************************************************
//---------------------------------------------------------------------

void main(void) {

//MCU_Init(); // MCU Initialization; has to be done prior to anything else
unsigned int j=0;
SOPT1=0;// disable COP, enable Stop, map TPMCH1 to PTB5; Reset & Bkgd = BDM
SOPT2=0x00;

ADCCFG=0x28;
APCTL1=0xFF;
ICSC1=0x04;
ICSC2=0x40; //8 Mhz clock.
//ICSTRM=0x80;

EnableInterrupts;

for(;:smileywink:
{
//Poll for StartPI flag

Input_Voltage = read_adc(CH7);

if(Input_Voltage>=0 && Input_Voltage<=895) {


Gen_PWM(SeekPlus);
}
/*else if(Input_Voltage>=941 && Input_Voltage<=945){

Gen_PWM(SeekMinus);

}
else if(Input_Voltage>=735 && Input_Voltage<738) {

Gen_PWM(VolumePlus);

}
else if(Input_Voltage>=819 && Input_Voltage<=821){

Gen_PWM(VolumeMinus);

}
else if(Input_Voltage>=625 && Input_Voltage<=628){

Gen_PWM(Mode);

} */
}
}

void Gen_PWM(const unsigned int data[])
{

i=0;
APCTL1=0x00;
// ### Init_TPM init PWM code
TPM1C0SC = 0; // Channel 0 int flag clearing (first part)




TPM1C0SC = 0x28; //OUTPUT COMPARE MODE Edge Aligned High True Pulses.

TPM1SC = 0x4C; // Prescale clock 16




while(i!=33)
{

if(flag==0) {


if(data[i]==0)
{

TPM1C0V = 0x230; // time-period of 1.125ms
TPM1C0V=0x117; // Duty Cycle of .565ms //Logic 0
flag=1;
}

if(data[i]==1) {

TPM1MOD =0x464; //time-period of 2.25ms
TPM1C0V=0x117; // Duty Cycle of .565ms
flag=1;
//Logic 1

}
}

}


}

void MCU_Delay(word delay) // Delay in multiples of 100us (e.g. use 10000 for 1 second)
{
word delw;
for (delw=0;delw<delay;delw++)
{

}
}

word read_adc(byte chan) // Analog-to-Digital Converter byte read: enter channel to read
{
ADCSC1=chan;
while (!ADCSC1_COCO);
return ADCR;
}


void interrupt VectorNumber_Vtpm1ovf Vtpm1ovf_ISR(void)
{


TPM1SC;
TPM1SC_TOF = 0;

i++;
flag=0;


}

Outcomes