Hello guys.
I'm starting at piccolo f28027. I've learned to light some leds with
some didactic.
At this point, I would like to insert a square wave in ADC, and show that the output signal, an LED lighting and extinguishing the GPIO 0.
The input signal has an offset of 1V. Subtract a value from the ADC (4095/3.3) relative to 1V, and compare it to zero.
Already configured the ADC and GPIO, but I can not get the desired result.
And In expressions, I do not see the value of the variable. Generates an error.
Could anyone help me?
Thank you.
This is the code I used
/*
* main.c
*/
#include <stdio.h>
#include <file.h>
#include "DSP28x_Project.h" // DSP28x Headerfile
#include "f2802x_common/include/adc.h"
#include "f2802x_common/include/clk.h"
#include "f2802x_common/include/gpio.h"
#include "f2802x_common/include/pie.h"
#include "f2802x_common/include/pll.h"
#include "f2802x_common/include/wdog.h"
interrupt void adc_isr(void);
//#ifdef _FLASH
// memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (size_t)&RamfuncsLoadSize);
//#endif
int16 SaidaAdc;
int16 Tensao;
ADC_Handle myAdc;
CLK_Handle myClk;
GPIO_Handle myGpio;
PWM_Handle myPwm;
void main()
{
CPU_Handle myCpu;
WDOG_Handle myWDog;
PLL_Handle myPll;
myAdc = ADC_init((void *)ADC_BASE_ADDR, sizeof(ADC_Obj));
myClk = CLK_init((void *)CLK_BASE_ADDR, sizeof(CLK_Obj));
myCpu = CPU_init((void *)NULL, sizeof(CPU_Obj));
myGpio = GPIO_init((void *)GPIO_BASE_ADDR, sizeof(GPIO_Obj));
myPll = PLL_init((void *)PLL_BASE_ADDR, sizeof(PLL_Obj));
myPwm = PWM_init((void *)PWM_ePWM1_BASE_ADDR, sizeof(PWM_Obj));
myWDog = WDOG_init((void *)WDOG_BASE_ADDR, sizeof(WDOG_Obj));
// Perform basic system initialization
WDOG_disable(myWDog);
CLK_enableAdcClock(myClk);
//Select the internal oscillator 1 as the clock source
CLK_setOscSrc(myClk, CLK_OscSrc_Internal);
// Setup the PLL for x12 /2 which will yield 60Mhz = 10Mhz * 12 / 2
PLL_setup(myPll, PLL_Multiplier_12, PLL_DivideSelect_ClkIn_by_2);
// Disable the PIE and all interrupts
CPU_disableGlobalInts(myCpu);
CPU_clearIntFlags(myCpu);
//INICIALIZAÇÃO E CONFIGURAÇÃO DO GPIO
myGpio = GPIO_init((void *)GPIO_BASE_ADDR, sizeof(GPIO_Obj));
GPIO_setMode(myGpio, GPIO_Number_0, GPIO_0_Mode_GeneralPurpose);
GPIO_setDirection(myGpio, GPIO_Number_0, GPIO_Direction_Output);
GPIO_setMode(myGpio, GPIO_Number_1, GPIO_1_Mode_GeneralPurpose);
GPIO_setDirection(myGpio, GPIO_Number_1, GPIO_Direction_Output);
GPIO_setMode(myGpio, GPIO_Number_2, GPIO_2_Mode_GeneralPurpose);
GPIO_setDirection(myGpio, GPIO_Number_2, GPIO_Direction_Output);
GPIO_setMode(myGpio, GPIO_Number_3, GPIO_3_Mode_GeneralPurpose);
GPIO_setDirection(myGpio, GPIO_Number_3, GPIO_Direction_Output);
//INICIALIZAÇÃO E CONFIGURAÇÃO DO ADC
ADC_enableBandGap(myAdc);
ADC_enableRefBuffers(myAdc);
ADC_powerUp(myAdc);
ADC_enable(myAdc);
ADC_setVoltRefSrc(myAdc, ADC_VoltageRefSrc_Int);
//ADC_setIntPulseGenMode(myAdc, ADC_IntPulseGenMode_Prior);
// AdcRegs.INTSEL1N2.bit.INT1E = 1; //Enabled ADCINT1
ADC_enableInt(myAdc, ADC_IntNumber_1);
// AdcRegs.INTSEL1N2.bit.INT1CONT = 0; //Disable ADCINT1 Continuous mode
ADC_setIntMode(myAdc, ADC_IntNumber_1, ADC_IntMode_ClearFlag);
// AdcRegs.INTSEL1N2.bit.INT1SEL = 1; //setup EOC1 to trigger ADCINT1 to fire
ADC_setIntSrc(myAdc, ADC_IntNumber_1, ADC_IntSrc_EOC1);
// AdcRegs.ADCSOC0CTL.bit.CHSEL = 5; //set SOC0 channel select to ADCINA5 (which is internally connected to the temperature sensor)
ADC_setSocChanNumber (myAdc, ADC_SocNumber_0, ADC_SocChanNumber_A1);
ADC_setSocSampleWindow(myAdc, ADC_SocNumber_0, ADC_SocSampleWindow_7_cycles);
//}
// PROGRAMA
// GPIO_setHigh(myGpio, GPIO_Number_0);
// GPIO_setHigh(myGpio, GPIO_Number_1);
// GPIO_setHigh(myGpio, GPIO_Number_2);
// GPIO_setHigh(myGpio, GPIO_Number_3);
while(1)
{
SaidaAdc = ADC_readResult(myAdc, ADC_ResultNumber_1);
Tensao = SaidaAdc-1241;
if(Tensao >= 0)
{
GPIO_setHigh(myGpio, GPIO_Number_0);
}
else
GPIO_setLow(myGpio, GPIO_Number_0);
}
}








