Sascha Ming

Stopping the PWM-Output? HC908QY4 on the SofTec NitronKit

Discussion created by Sascha Ming on Jan 14, 2007
Latest reply on Jan 15, 2007 by bigmac
Hello there
 
I've got the Nitron-Kit from SofTec with the HC908QY4 and USB to MON08 Interface.
 
Now I wrote a little program wich generates a PWM-Signal on the channel 0. The dutycycle can be changed with the value from de ADC. If the value from the ADC is 0x00, i want to stop and set the PWM-Output to 0x00, so there is a clean "0" on the PTA0. Otherwise, if the ADC reaches the value for a 100% dutycycle, i want to set the PWM-Output to 0x01, so there is a clean "1" on the PTA0.
 
With my solution, setting the PWM-Output to "1" doesn't work very good. Sometimes it will be set to "1", sometimes it will be set to "0".... Any solutions?
 
 
Heres my Code:
 
Code:
Initialize--------------void pwm_init(){ TSC = 0x30;               //Timer stoppen und zurücksetzen TMODH = 0x00;                   //PWM-Grundfrequenz setzen (ca. 20kHz) TMODL = 0xA0;                   //PWM-Grundfrequenz setzen (ca. 20kHz) TCH0H = 0x00;                   //PWM-DutyCycle setzen TCH0L = 0x00;                   //PWM-DutyCycle setzen TSC0 = 0x1A;                    //PWM-Generator konfigurieren //TSC = 0x00;                     //Timer starten}Main-program------------------              //BETRIEBSART POTI         //////////////////         //Falls Poti in Nullstellung ist         while (TRUE){                             if (ADR == 0x00)                {                     TSC = 0x30;      //Timer stoppen und zurücksetzen             PTA = 0x00;           //PWM-Port löschen             ADR = 0x00;         }                  //Falls Poti in Maximalstellung (0xA0 = Maximum weil PWM Grundfrequenz!)         if (ADR > 0x9F)                {                      TSC = 0x30;      //Timer stoppen und zurücksetzen             PTA = 0x01;           //PWM-Port immer setzen             ADR = 0x00;                  }                  //Falls Poti in gültiger Stellung ist         if ((ADR > 0x00) && (ADR <= 0x9F))         {           TSC = 0x00;            //Timer starten           TCH0L = ADR;           //PWM-DutyCycle (lowerByte) fix einstellen              }                  }

 
Thank you very much!
 
(Alban: code format - SRC button)

Message Edited by Alban on 2007-01-15 12:06 PM

Outcomes