5 Replies Latest reply on Apr 22, 2014 6:26 AM by SpiderKenny

    How to generate 1.6kHz square wave...? Help!

    Don_Fantom_Juan

      Hello:

        I'm trying to generate 1.6Khz PWM square wave, so when I finished reading the "Cypress CY8C9520A datasheet", I wrote the code as follow to control this chip:

       

       

        Wire.begin();

        pinMode(PIN, OUTPUT);

        analogWrite(PIN,1);

       

       

        Wire.beginTransmission(0x20);

        Wire.write(0x2C);

        Wire.write(0xFF);

        Wire.endTransmission();

       

        Wire.beginTransmission(0x20);

        Wire.write(0x29);

        Wire.write(0x04);

        Wire.endTransmission();

       

        Wire.beginTransmission(0x20);

        Wire.write(0x2a);

        Wire.write(0xff);

        Wire.endTransmission();

       

        Wire.beginTransmission(0x20);

        Wire.write(0x2b);

        Wire.write(0x80);

        Wire.endTransmission();

       

       

        You know 29H is to select the clock source for PWM, and 2CH is to set the frequency ont the output of the programmable divider. But when I changed the clock source to any other options besides 367.6hz(04H), it doesn't work. For example, I changed clock source to 32kHz, but it generated 95Hz in oscilloscope, and at the same time, the divider register doesn't work.(93.75k-377  32K-95  1.5M--6.1k  24M-97k).

       

       

      So my question is

        1.How can I get 1.6kHz PWM square wave?

        2.On what condition the divider register(2CH) works ?

       

       

      Thanks !!!