<commit_before>#include <cc2511_map.h>
#include <servo.h>
#include <wixel.h>
#include <usb.h>
#include <usb_com.h>

volatile uint8 DATA servoCounter = 0;

ISR(T1,0)
{
    switch(servoCounter++)
    {
    case 0:
        //PERCFG |= (1<<6);  // PERCFG.T1CFG = 1:  Move Timer 1 to Alt. 2 location (P1_2, P1_1, P1_0)
        //T1CC0 = 1;
        //T1CC1 = -25000;
        //T1CC2 = -26000;
        break;
    case 1:
        T1CC0 = T1CC1 = T1CC2 = 0xFFFF;
        break;

    case 2:
        //PERCFG &= ~(1<<6);  // PERCFG.T1CFG = 0:  Move Timer 1 to Alt. 1 location (P0_2, P0_3, P0_4)
        T1CC0 = -30000;
        T1CC1 = -32000;
        T1CC2 = 0x10000-34000;
        break;

    case 3:
        T1CC0 = T1CC1 = T1CC2 = 0xFFFF;
        break;

    case 7:
        servoCounter = 0;
        break;
    }

}

void main()
{
    systemInit();
    usbInit();

    P2SEL |= (1<<3); // might not be necessary, makes Timer 1 have priority over USART1

    // Set up hardware PWM.
    PERCFG &= ~(1<<6);  // PERCFG.T1CFG = 0:  Move Timer 1 to Alt. 1 location (P0_2, P0_3, P0_4)
    P1SEL |= 0b111;
    P1DIR |= 0b111;

    P0SEL |= 0b11100;
    P0DIR |= 0b11100;

    T1CC0 = 60000;         // Period = 60000/24 = 2500 microseconds.

    // Configure Timer 1 Channels 0-2 to be in compare mode.  Set output on compare-up, clear on 0.
    // With this configuration, we can set T1CC0, T1CC1, or T1CC2 to -N to get a pulse of with N,
    // as long as N > 1.
    // We can set the register to -1 or 0 to disable the pulse.
    T1CCTL0 = T1CCTL1 = T1CCTL2 = 0b00011100;

    T1CTL = 0b00000001;    // Timer 1: Start free-running mode, counting from 0x0000 to 0xFFFF.

    T1CC0 = -1;
    T1CC1 = -9;
    T1CC2 = -15;

    IP0 |= (1<<1);
    IP1 |= (1<<1);
    T1IE = 1; // Enable the Timer 1 interrupt.
    EA = 1;   // Enable interrupts in general.

    P1DIR |= (1<<4);

    while(1)<commit_msg>test_servos app: Achieved hardware servo control on 6 channels, but the lines seem to be floating part of the time and that should be fixed.<commit_after>#include <cc2511_map.h>
#include <servo.h>
#include <wixel.h>
#include <usb.h>
#include <usb_com.h>

volatile uint8 DATA servoCounter = 0;

ISR(T1,0)
{
    switch(servoCounter++)
    {
    case 0:
        PERCFG |= (1<<6);  // PERCFG.T1CFG = 1:  Move Timer 1 to Alt. 2 location (P1_2, P1_1, P1_0)
        T1CC0 = 1;
        T1CC1 = -25000;
        T1CC2 = -26000;
        break;
    case 1:
        T1CC0 = T1CC1 = T1CC2 = 0xFFFF;
        break;

    case 2:
        PERCFG &= ~(1<<6);  // PERCFG.T1CFG = 0:  Move Timer 1 to Alt. 1 location (P0_2, P0_3, P0_4)
        T1CC0 = -30000;
        T1CC1 = -32000;
        T1CC2 = 0x10000-34000;
        break;

    case 3:
        T1CC0 = T1CC1 = T1CC2 = 0xFFFF;
        break;

    case 7:
        servoCounter = 0;
        break;
    }

}

void main()
{
    systemInit();
    usbInit();

    P2DIR = (P2DIR & ~0b11000000) | 0b11000000;
    P2SEL |= (1<<3); // might not be necessary, makes Timer 1 have priority over USART1 on Port 1

    // Set up hardware PWM.
    PERCFG &= ~(1<<6);  // PERCFG.T1CFG = 0:  Move Timer 1 to Alt. 1 location (P0_2, P0_3, P0_4)
    P1SEL |= 0b111;
    P1DIR |= 0b111;

    P0SEL |= 0b11100;
    P0DIR |= 0b11100;

    T1CC0 = 60000;         // Period = 60000/24 = 2500 microseconds.

    // Configure Timer 1 Channels 0-2 to be in compare mode.  Set output on compare-up, clear on 0.
    // With this configuration, we can set T1CC0, T1CC1, or T1CC2 to -N to get a pulse of with N,
    // as long as N > 1.
    // We can set the register to -1 or 0 to disable the pulse.
    T1CCTL0 = T1CCTL1 = T1CCTL2 = 0b00011100;

    T1CTL = 0b00000001;    // Timer 1: Start free-running mode, counting from 0x0000 to 0xFFFF.

    T1CC0 = -1;
    T1CC1 = -9;
    T1CC2 = -15;

    IP0 |= (1<<1);
    IP1 |= (1<<1);
    T1IE = 1; // Enable the Timer 1 interrupt.
    EA = 1;   // Enable interrupts in general.

    P1DIR |= (1<<4);

    while(1)
{'fraction_non_alphanumeric': 0.12850999241082722, 'fraction_numerical': 0.11889704022261574, 'mean_word_length': 1.9640179910044977, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4901895', 'n_tokens_mistral': 1843, 'n_tokens_neox': 1580, 'n_words': 484}