1 Reply Latest reply on Apr 1, 2016 6:18 PM by david.tomanek

    PSoC 4 ADC

    skariaroy

      I am writting a code in FreeRTOS with PSoC 4. I am writting a code to read the output from an LDR and transmit it through USART. 

         

      Initial it is showing 4000-4900. when i turn off the light. The value reduces to something around 900 and then the adc stops working. Unless it continuously transmit adc values. Please help

         

      int main( void )
      {   
          #if 1
          CyGlobalIntEnable;
          UART_1_Start() ;
          UART_1_PutString("Hello");
          LED_DEF_Write(pdFALSE);
          ADC_SAR_1_Start();
          ADC_SAR_1_IRQ_Start();
          count = 0;
          /* Place your initialization/startup code here (e.g. MyInst_Start()) */
          prvHardwareSetup();
         // Switch1_Queue = xQueueCreate(5,sizeof(int));
          vSemaphoreCreateBinary(ADC_sem);
          vSemaphoreCreateBinary(UART_semphr);
          

         

          /* Create the LED_BLUE blink task */
            ( void ) xTaskCreate( UART_TEMP_Task, "Blink", BLINK_STACK_SIZE, NULL, UART_TEMP_Priority, NULL );

         

          
          /* Create the Switch Control Task blink task2 */
            // ( void ) xTaskCreate(TEST1, "Blink", BLINK_STACK_SIZE, NULL, TEST1_PRIORITY, NULL );
          xSemaphoreGive( ADC_sem );
          xSemaphoreGive( UART_semphr );
          // xSemaphoreTake(ADC_sem,portMAX_DELAY); 
          /* Start the OS */
          vTaskStartScheduler();
          
          /*NOTREACHED*/
          for(;;);
          # endif
      }

         

       

         

       

         

       

         

       

         

      static void UART_TEMP_Task(void *parm)
      {
          UART_1_PutChar(0x0c);

         

          while( FOREVER )
          {
              LED_DEF_Write( 1 );
              ADC_SAR_1_StartConvert();
              ADC_SAR_1_IRQ_Start();
              if(xSemaphoreTake(ADC_sem,portMAX_DELAY)==pdPASS)
              {
                  adcresult -= (~adcresult)&0x0FFF;
                  adcresult++;
                  sprintf( adcstr, "%d",adcresult );
                  UART_1_PutChar('\r');
                  UART_1_PutChar('\n');

         

                  UART_1_PutString(adcstr);

         

              }
              vTaskDelay(100);

         

          }
      }

         

       

         

      CY_ISR(ADC_SAR_1_IRQ_Interrupt)
      {

          static BaseType_t xHigherPriorityTaskWoken;
          xHigherPriorityTaskWoken = pdFALSE;
          adcresult = ADC_SAR_1_GetResult16();
          xSemaphoreGiveFromISR(ADC_sem, &xHigherPriorityTaskWoken);

      }