I am having some problems with MC9S08QG8. I have two of these microcontrollers, one takes an analogue signal converts it to 8 bit and sends via serial. The other receives this message and turns it in two a PWM signal.
This is part of a optical communications project and I therefore have some circuitry between the Tx and Rx pins of the MC’s but I have removed this at the moment. I therefore have the Tx pin on one MC connected directly to the Rx on the other.
The system behaves roughly as I would have expected however at certain voltage inputs the PWM jumps to a different pulse width. This happens a lot and I cant see a pattern, although an increasing PW can be seen as the voltage increases.
To find cause of problem I have tried various parts on there own and all were successful, including ADC to Serial, ADC to PWM. I also wrote code that incremented an integer which was sent via serial and converted to PWM. Therefore i have no idea what the problem is.
All I can think of is lack of any additional components to get rid of noise. Please could someone advise me to how the input/outputs should be connected and any other things I should be aware of.
Thanks
Code:
// *************************************// ** **// ** Name: ADC to SCI Transmit **// ** Verion: 1.0 **// ** Desc: PA1 as ADC sent with SCI **// ** MC: 9S08QG8 **// ** **// *************************************#include <hidef.h> /* for EnableInterrupts macro */#include "derivative.h" /* include peripheral declarations */int Temp;void main(void) { int i; // For Loop Var int j; // For Loop Var ADCSC1 = 0x00; // Set to Channel 1 ADCSC2 = 0x00; // Settings ADCCFG = 0x90; // Speeds APCTL1 = 0x01; // Configure Pin as ADC SCIBDL = 0xFF; // Select baud rate SCIC1 = 0x12; // Settings SCIC1_PT = 0; SCIC2_TE = 1; // Enable Transmitter EnableInterrupts; for(;;) // Loop Forever { for(i=1;i<50;i++) // PAUSE { for(j=1;j<254;j++) { } } ADCSC1 = 0x00; // Write for conversion to take place while (ADCSC1_COCO == 0){}// Wait until conversion complete Temp = ADCRL; SCID = Temp; // ADC value sent SCIS1_TDRE = 0; // Clear flag to send __RESET_WATCHDOG(); }}
Code:
// *************************************// ** **// ** Name: SCI Recieve to PWM **// ** Verion: 1.0 **// ** Desc: **// ** MC: 9S08QG8 **// ** **// *************************************#include <hidef.h> /* for EnableInterrupts macro */#include "derivative.h" /* include peripheral declarations */int Data;int BadData;void main(void) { // VARIABLES int i; // For Loop Var int j; // For Loop Var int Temp=0; // PWM TPMSC = 0x0F; // Settings TPMMODH = 0x00; // Period H TPMMODL = 0xFF; // Period L TPMC0SC = 0x28; // Settings TPMC0VH = 0x00; // Duty H TPMC0VL = 0xAF; // Duty L // OUTPUT PTADD_PTADD0 = 1; // Set PTB7 as an output // SCI SCIBDL = 0x7F; // Select baud rate SCIC1 = 0x12; // Settings 9 bit with parity SCIC2_RE = 1; // Enable Transmitter SCIC2_TE = 0; EnableInterrupts; for(;;) // Loop Forever { for(i=1;i<10;i++) // PAUSE { for(j=1;j<254;j++) { } } if(SCIS1_RDRF == 1) { if((SCIS1_NF == 0) && (SCIS1_PF == 0)) { Data = SCID; TPMC0VH = 0x00; // Duty H TPMC0VL = Data; // Duty L } else { BadData = SCID; } } __RESET_WATCHDOG(); // feeds the dog }}
Alban clarified subject
Message Edited by Alban on 2007-02-26 05:50 PM