Exemple #1
0
void tone(uint8_t pin, unsigned int frequency, unsigned long duration)
{
	/* Use TIMERA0B since it is not on any pin */

	tone_timer = digitalPinToTimer(pin);

	if(tone_timer == NOT_ON_TIMER)
		return;

	if(tone_state != 0 && pin != current_pin)
		return;

	g_duration = duration;
	current_pin = pin;
	tone_state = 2;

	MAP_PRCMPeripheralClkEnable(PRCM_TIMERA0, PRCM_RUN_MODE_CLK);
	MAP_PRCMPeripheralReset(PRCM_TIMERA0);
	MAP_TimerConfigure(TIMERA0_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_B_PERIODIC);
	MAP_TimerIntRegister(TIMERA0_BASE, TIMER_B, ToneIntHandler);
	MAP_TimerIntEnable(TIMERA0_BASE, TIMER_TIMB_TIMEOUT);
	MAP_TimerPrescaleSet(TIMERA0_BASE, TIMER_B, 7);
	MAP_TimerLoadSet(TIMERA0_BASE, TIMER_B, (F_CPU / 8) / 1000);
	MAP_TimerEnable(TIMERA0_BASE, TIMER_B);

	PWMWrite(pin, 256, 128, frequency);
}
Exemple #2
0
void tone(uint8_t pin, unsigned int frequency)
{
	tone_timer = digitalPinToTimer(pin);

	if(tone_timer == NOT_ON_TIMER)
		return;

	if(tone_state == 0 || pin == current_pin) {
		PWMWrite(pin, 255, 128, frequency);
		tone_state = 1;
		current_pin = pin;
	}
}
Exemple #3
0
void tone(uint8_t _pin, unsigned int frequency)
{

    uint8_t port = digitalPinToPort(_pin);

    if (port == NOT_A_PORT) return;

    if(tone_state == 0 || _pin == current_pin) {
        tone_timer = digitalPinToTimer(_pin);
        PWMWrite(_pin, 256, 128, frequency);
        tone_state = 1;
    }

}
void analogWrite(uint8_t pin, int val) {
	/* duty cycle(%) = val / 255;
	 * Frequency of 490Hz specified by Arduino API */
	uint8_t timer = digitalPinToTimer(pin);

	if(timer == NOT_ON_TIMER)
		return;

	if (val == 0) {
		pinMode(pin, OUTPUT);
		digitalWrite(pin, LOW);
		return;
	}

	if (val >= 255) {
		pinMode(pin, OUTPUT);
		digitalWrite(pin, HIGH);
		return;
	}

	PWMWrite(pin, 255, val, 490);
}
Exemple #5
0
void tone(uint8_t _pin, unsigned int frequency, unsigned long duration)
{
    uint8_t port = digitalPinToPort(_pin);
    if (port == NOT_A_PORT) return;
    if (tone_state == 0 || _pin == current_pin) {

    	//Setup PWM
    	current_pin = _pin;
        tone_timer = digitalPinToTimer(_pin);
        uint32_t timerBase = getTimerBase(timerToOffset(tone_timer));
        tone_state = 1;
        g_duration = duration;
        PWMWrite(_pin, 256, 128, frequency);

        //Setup interrupts for duration, interrupting at 1kHz
        ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER4);
        ROM_IntMasterEnable();
        ROM_TimerConfigure(TIMER4_BASE, TIMER_CFG_PERIODIC);
        ROM_TimerLoadSet(TIMER4_BASE, TIMER_A, ROM_SysCtlClockGet()/1000);
        ROM_IntEnable(INT_TIMER4A);
        ROM_TimerIntEnable(TIMER4_BASE, TIMER_TIMA_TIMEOUT);
        ROM_TimerEnable(TIMER4_BASE, TIMER_A);
    }
}