Пример #1
0
/*
 * Analog Read
 * As usually, 10bit ADC is enough, to increase the compatibility, will use only 10bit.
 * if if your ADC is 12bit, you need to >>2, or your ADC is 8Bit, you need to <<2
 */
int16 suli_analog_read(ANALOG_T *aio)
{
    vAHI_AdcEnable(E_AHI_ADC_SINGLE_SHOT, E_AHI_AP_INPUT_RANGE_2, *aio);  //2*vref = 1.2*2 = 2.4V
    vAHI_AdcStartSample();
    // Wait until ADC data is available
    while(bAHI_AdcPoll());

    uint16 val = u16AHI_AdcRead();

    return val;

    //convert the output to 5V - 1024
    //return (int16)(val * 6.6f / 5.0f);
}
Пример #2
0
/****************************************************************************
 *
 * NAME:       		LAMP_vInit
 *
 * DESCRIPTION:		Initialises the lamp drive system
 *
 * PARAMETERS:      Name     RW  Usage
 *
 *
 * RETURNS:
 * void
 *
 ****************************************************************************/
PUBLIC void DriverBulb_vInit(void)
{
	bool_t bLampTimerInt = FALSE;

	static bool_t bInit = FALSE;

	if (bInit == FALSE)
	{

		/* Configure DIO pins */
		vAHI_DioSetDirection(0, (LAMP_ON_OFF_MASK | (1 <<LAMP_BLEEDER_PIN)));

		/* Turn CFL lamp off */
		vAHI_DioSetOutput(0, LAMP_ON_OFF_MASK);

		/* Mimic PWM to led ? */
		#if (LAMP_LED_PIN < 21)
		{
			/* Configure as output */
			vAHI_DioSetDirection(0, (1 << LAMP_LED_PIN));
			/* Turn CFL lamp off */
			vAHI_DioSetOutput(0, (1 << LAMP_LED_PIN)/*, 0*/);
			/* Register interrupt callback */
			vAHI_Timer0RegisterCallback(vCbTimer0);
			/* Note we want to generate interrupts */
			bLampTimerInt = TRUE;
		}
		#endif

		/* Configure timer 0 to generate a PWM output on its output pin */
		vAHI_TimerEnable(LAMP_TIMER, LAMP_TIMER_PRESCALE, bLampTimerInt, bLampTimerInt, TRUE);
		vAHI_TimerConfigureOutputs(LAMP_TIMER, FALSE, TRUE);
		vAHI_TimerClockSelect(LAMP_TIMER, FALSE, TRUE);

		/* turn on lamp - this is the default state */

		vAHI_DioSetOutput((1 << LAMP_BLEEDER_PIN),0);
		vAHI_DioSetOutput(LAMP_ON_OFF_MASK,0);


		vAHI_ApConfigure(E_AHI_AP_REGULATOR_ENABLE,
							 E_AHI_AP_INT_DISABLE,
							 E_AHI_AP_SAMPLE_8,
							 E_AHI_AP_CLOCKDIV_500KHZ,
							 E_AHI_AP_INTREF);

		while (!bAHI_APRegulatorEnabled());   /* spin on reg not enabled */

		vAHI_AdcEnable(E_AHI_ADC_SINGLE_SHOT, E_AHI_AP_INPUT_RANGE_2, ADC_USED);

		do
		{
			vAHI_AdcStartSample();
			while(bAHI_AdcPoll());
			gu32BusVoltage = ((uint32)u16AHI_AdcRead()*VBUS_MAXIMUM) >> ADC_BITS;
		} while (gu32BusVoltage< VBUS_TRIP_LO);

		vAHI_AdcDisable();

		vAHI_ApConfigure(E_AHI_AP_REGULATOR_DISABLE,
						 E_AHI_AP_INT_DISABLE,
					     E_AHI_AP_SAMPLE_8,
						 E_AHI_AP_CLOCKDIV_500KHZ,
						 E_AHI_AP_INTREF);

		vAHI_TimerStartRepeat(LAMP_TIMER, PWM_COUNT, PWM_COUNT );

		bInit = TRUE;
		bIsOn = TRUE;

	}