Blogs

2018-2019 Student Blogs

Each of the following links takes you to the individual blog of one 2018-2019 student of DT009/3 Robotics and Industrial Electronics:

2017-2018 Student Blogs

Each of the following links takes you to the individual blog of one 2017-2018 student of Robotics 3.1:

2016-2017 Student Blogs

Each of the following links takes you to the individual blog of one 2016-2017 student of Robotics 3.1:

2015-2016 Student Blogs

Each of the following links takes you to the individual blog of one 2015-2016 student of Robotics 3.1:

2013-2014 Student Blogs

Each of the following links takes you to the individual blog of one 2013-2014 student of Robotics 3.1:

2012-2013 Student Blogs

Each of the following links takes you to the individual blog of one 2012-2013 student of Robotics 3.1:

2011-2012 Student Blogs

Each of the following links takes you to the individual blog of one 2011-2012 student of Robotics 3.1:

Advertisements

1 Response to Blogs

  1. i need help reworking a simple program that has already been running. i need to add a few adjustments but I a not a programmer. I will pay for your time. I need to add a few pauses in some of my switching routines so i eliminate crossover from the power mosfets. also need to change a duty cycle routine that currently has only a 50-95% duty setting i need it to be fully adjustable say from 5% to 95%. this is for the dspic 304011 i have the source code. can you help me out. thanks

    Warren

    attached is the code:

    /*******************************************************************************
    * Project name:
    BT Controller
    * Target Platform:
    dsPIC
    * Test configuration:
    MCU: dsPIC30F4011
    Oscillator: XTHS-PLL16, 7.3728MHz = 117.9648MHz
    Ext. Modules: None.
    SW: mikroC for dsPIC30/33 and PIC24 v4.6.0.0
    * NOTES:
    None.
    */
    //*******************************************************************************

    unsigned long cnt;
    unsigned long cnt1;
    unsigned long cnt2;
    unsigned long Loop_Time;
    unsigned long BSR;
    unsigned long CDSR;
    unsigned long CDSR_On1;
    unsigned long CDSR_On2;
    unsigned long CDP_Period;
    unsigned long eeAddr;

    float Scratch1_Float;
    float Scratch2_Float;

    unsigned int CDP_Count;
    unsigned int CD_On_Period;
    unsigned int CD_Off_Period;
    unsigned int Pwm_period1;
    unsigned int Pwm_period2;
    unsigned int i,x,y;
    unsigned int DVS1, DVS2;
    unsigned int Duty1; // 5 – 95%
    unsigned int BAT_SR;
    unsigned int CD_Freq;
    unsigned int CD_Duty; // 5-95%
    unsigned int PWM_Duty; // 0-99%
    unsigned int eeData;

    char PWM_FREQ_txt[8];
    char PWM_FREQ_Fmt[8];
    char PWM_DUTY_txt[4];
    char PWM_DUTY_Fmt[4];
    char PWM_Fmt[4];
    char BAT_SR_txt[8];
    char BAT_SR_Fmt[8];
    char CD_Frq_txt[8];
    char CD_Freq_fmt[8];
    char CD_DUTY_txt[8];
    char CD_DUTY_fmt[8];

    bit Toggle_PWR, Int_Toggle, Int_Toggle1;
    bit Toggle1, Toggle2, Toggle3, Toggle4;
    bit PWM_Toggle, CD_Toggle;

    // Define Port I/O bits

    sbit CD_DUTY_INC at RC13_bit;
    sbit CD_DUTY_DEC at RC14_bit;

    sbit PWM_DUTY_INC at RE8_bit;
    sbit PWM_DUTY_DEC at RD3_bit;

    sbit CDP_Count_INC at RF2_bit;
    sbit CDP_Count_DEC at RF3_bit;

    sbit BSR_INC at RF4_bit;
    sbit BSR_DEC at RF5_bit;

    sbit On_Off at RF6_bit;

    // setup LCD module connections

    sbit LCD_RS at LATB4_bit;
    sbit LCD_EN at LATB5_bit;
    sbit LCD_D4 at LATB0_bit;
    sbit LCD_D5 at LATB1_bit;
    sbit LCD_D6 at LATB2_bit;
    sbit LCD_D7 at LATB3_bit;

    sbit LCD_RS_Direction at TRISB4_bit;
    sbit LCD_EN_Direction at TRISB5_bit;
    sbit LCD_D4_Direction at TRISB0_bit;
    sbit LCD_D5_Direction at TRISB1_bit;
    sbit LCD_D6_Direction at TRISB2_bit;
    sbit LCD_D7_Direction at TRISB3_bit;

    sbit SW1 at LATE0_bit;
    sbit SW1_Direction at TRISE0_bit;
    sbit SW2 at LATE1_bit;
    sbit SW2_Direction at TRISE1_bit;
    sbit SW3 at LATE2_bit;
    sbit SW3_Direction at TRISE2_bit;
    sbit SW4 at LATE3_bit;
    sbit SW4_Direction at TRISE3_bit;
    sbit SW5 at LATE4_bit;
    sbit SW5_Direction at TRISE4_bit;
    sbit SW6 at LATE5_bit;
    sbit SW6_Direction at TRISE5_bit;
    sbit SW7 at LATE8_bit;
    sbit SW7_Direction at TRISE8_bit;

    sbit CD_Out1 at LATF0_bit;
    sbit CD_Out1_Direction at TRISF0_bit;
    sbit CD_Out2 at LATF1_bit;
    sbit CD_Out2_Direction at TRISF1_bit;

    sbit CB_Out1 at LATB6_bit;
    sbit CB_Out1_Direction at TRISB6_bit;
    sbit CB_Out2 at LATB7_bit;
    sbit CB_Out2_Direction at TRISB7_bit;

    sbit Test_Out1 at LATD2_bit;
    sbit Test_Out1_Direction at TRISD2_bit;

    sbit PWM1_OUT at LATD0_bit;
    sbit PWM1_OUT_Direction at TRISD0_bit;

    sbit PWM2_OUT at LATD1_bit;
    sbit PWM2_OUT_Direction at TRISD1_bit;

    //*******************************************************************************
    //Functions
    void Read_Settings();
    void Initialize_Ports();
    void Set_PWM();
    void Configure_ADC();
    void Initialize_Variables();
    void Startup_LCD();
    void Update_LCD();
    void Calc_Freq();
    void Off_SUB();

    //*******************************************************************************

    void Read_Settings(){

    eeAddr = 0x7FFC00;
    Bat_SR = EEPROM_Read(eeAddr);
    if (Bat_SR > 200)Bat_SR = 10;
    eeAddr+=2;
    CD_Duty = EEPROM_Read(eeAddr);
    if(CD_Duty > 95)CD_Duty = 50;
    eeAddr+=2;
    CDP_Count = EEPROM_Read(eeAddr);
    if(CDP_Count > 100)CDP_Count = 4;
    eeAddr+=2;
    PWM_Duty = EEPROM_Read(eeAddr);
    if(PWM_Duty > 99)PWM_Duty = 0;

    }

    //*******************************************************************************

    void Initialize_Ports(){

    ADPCFG = 0XFEFF; // all PORTB = Digital; RB8 = analog

    TRISB = 0b0000000000000000;
    TRISC = 0b0110000000000000;
    TRISD = 0b0000000000001000;
    TRISE = 0b0000000100000000;
    TRISF = 0b0000000001111100;

    }

    //*******************************************************************************

    void Set_PWM(){

    Pwm_period1 = PWM_Init((1000), 1, 1, 2);
    DVS1 = ((Pwm_Period1/100) * PWM_Duty);
    PWM_Set_Duty(DVS1, 1);

    PWM_period2 = PWM_Init(1000, 2, 1, 3);
    DVS2 = ((Pwm_Period2/100) * PWM_Duty);
    PWM_Set_Duty(DVS2, 2);

    PWM_Start(1);
    PWM_Start(2);

    }

    //*******************************************************************************

    void Configure_ADC(){

    ADPCFG = 0xFFFE; // all PORTB = Digital; RB0 = analog
    ADCON1 = 0x00E4; // SSRC bit = 111 implies internal
    ADCON3 = 0x0104;
    ADCON2 = 0x0040; //was 0104;
    ADCHS = 0x0010;
    ADCSSL = 0;
    ADCON1bits.ADON = 1; // turn ADC ON
    }

    //*******************************************************************************

    void Initialize_Variables(){

    Toggle_PWR = 0;
    PWM_Toggle = 0;
    Int_toggle = 0;
    BAT_SR = 10;
    CD_Freq = BAT_SR * 2;
    CD_DUTY = 50;
    CDP_Count = 8;
    cnt = 0;
    cnt1 = 0;
    cnt2 = 0;
    PWM_Duty = 50;

    }

    //******************************************************************************

    void Startup_LCD(){

    Lcd_Init();
    // Initialize LCD
    Lcd_Cmd(_LCD_CLEAR); // Clear display

    Lcd_Cmd(_LCD_CURSOR_OFF);

    Lcd_out(1,1,” SERPS_2X “);
    Lcd_out(2,1,” CONTROL INTERFACE “);

    Delay_ms(4000);

    Lcd_Cmd(_LCD_CLEAR); // Clear display

    }

    //******************************************************************************

    void Update_LCD(){

    Lcd_Out(1,1,”BSR”);
    Sprinti(BAT_SR_Fmt,”%3d”, BAT_SR);
    Lcd_Out(1,4,BAT_SR_Fmt);
    LCD_Out(1,7,”Hz”);
    Lcd_Out(1,10,”CD%”);
    Sprinti(CD_Duty_Fmt,”%2d”, CD_Duty);
    Lcd_Out(1,14,CD_Duty_Fmt);

    Lcd_Out(2,1,”CDPC”);
    Sprinti(PWM_FREQ_Fmt,”%3d”, CDP_Count/2);
    Lcd_Out(2,5,PWM_FREQ_Fmt);
    Lcd_Out(2,9,”PWMO%”);
    Sprinti(PWM_Fmt,”%2d”, PWM_Duty);
    Lcd_Out(2,15,PWM_Fmt);
    if(Toggle_PWR == 1){
    Lcd_Out(2,18,”ON “);
    }else{
    Lcd_Out(2,18,”OFF”);
    }
    }

    //******************************************************************************

    void Calc_Freq(){

    Scratch2_Float = (float)CD_Freq;
    Scratch1_Float = (1/Scratch2_Float)/1.648E-6; //1.5195E-6;
    Loop_Time = (unsigned long)Scratch1_Float;

    BSR = Loop_Time/2;
    CDSR = Loop_Time/4;

    CDSR_On1 = ((BSR/100)* CD_Duty);
    CDSR_On2 = CDSR_On1 + BSR;
    CDP_Period = CDSR_on1/CDP_Count;

    PWM_START(1);
    PWM_START(2);

    Update_LCD();

    }

    //*****************************************************************************

    void Off_SUB(){

    SW1 = 0;
    SW2 = 0;
    SW3 = 0;
    SW4 = 0;
    SW5 = 0;
    SW6 = 0;
    PWM_Stop(1);
    PWM_Stop(2);
    PWM1_OUT = 0;
    PWM2_OUT = 0;
    CD_Out1 = 0;
    CD_Out2 = 0;
    PORTDbits.RD0 = 0;
    PORTDbits.RD1 = 0;
    PWM_Toggle = 0;

    }

    //*****************************************************************************

    void main(){

    Initialize_Ports();

    Initialize_Variables();

    Read_Settings();

    Startup_LCD();

    Calc_Freq();

    Set_PWM();
    PWM_STOP(1);
    PWM_STOP(2);

    cnt = 0;
    cnt1 = 0;
    cnt2 = 0;

    CB_Out1 = 0;
    CB_Out2 = 0;
    CD_Toggle = 0;

    while(1){
    Test_Out1 = 1;
    if(Toggle_PWR == 1){
    Cnt++;
    Cnt1++;
    if(cnt < BSR){ // Cnt = 0
    if(cnt < CDSR_On1 && CD_Toggle == 1){ // while cnt = CDP_Period && cnt + CDP_Period < CDSR_On1){
    CB_Out1 = !CB_Out1;
    cnt1 = 0;
    }
    if(CDSR_on1 – cnt BSR){
    if(cnt = CDP_Period){
    if(cnt1 >= CDP_Period && cnt + CDP_Period < CDSR_On2){
    CB_Out2 = !CB_Out2;
    cnt1 = 0;
    }
    if(CDSR_on2 – cnt = Loop_Time){
    cnt = 0; //Starts the loop over
    CD_Toggle = !CD_Toggle;
    }
    if(CD_DUTY_INC == 0){
    Off_SUB();
    Delay_ms(10);
    if(CD_DUTY_INC == 0){
    while(CD_DUTY_INC == 0){Off_SUB();}
    if(CD_DUTY 50){
    CD_DUTY–;
    EEPROM_Write(0x7FFC02,CD_DUTY);
    while(WR_bit);
    }
    Calc_Freq();
    }
    }
    if(CDP_Count_INC == 0){
    Off_SUB();
    Delay_ms(10);
    if(CDP_Count_INC == 0){
    while(CDP_Count_INC == 0){Off_SUB();}
    if(CDP_Count 2){
    CDP_Count-=2;
    EEPROM_Write(0x7FFC04,CDP_Count);
    while(WR_bit);
    }
    Calc_Freq();
    }
    }
    if(BSR_INC == 0){
    Off_SUB();
    Delay_ms(10);
    if(BSR_INC == 0){
    while(BSR_INC == 0){Off_SUB();}
    if (BAT_SR 1){
    BAT_SR–;
    EEPROM_Write(0x7FFC00,BAT_SR);
    while(WR_bit);
    }
    CD_Freq = BAT_SR * 2;
    Calc_Freq();
    }
    }
    if(PWM_DUTY_INC == 0){
    Delay_ms(10);
    if(PWM_DUTY_INC == 0){
    while(PWM_DUTY_INC == 0){Off_SUB();}
    if (PWM_DUTY 1){
    PWM_DUTY–;
    EEPROM_Write(0x7FFC06,PWM_DUTY);
    while(WR_bit);
    }
    Update_LCD();
    Set_PWM();

    }
    }
    }
    if(On_Off == 0){
    Delay_ms(10);
    if(On_Off == 0){
    while(On_Off == 0){asm nop;}
    Toggle_PWR = !Toggle_PWR;
    if(Toggle_PWR == 1){
    Set_PWM();
    PWM_Start(1);
    PWM_Start(2);
    }else{
    Off_SUB();
    }
    Update_LCD();
    }
    }
    Test_Out1 = 0;
    }

    }

    //*******************************************************************************

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s