5 Replies - 269 Views - Last Post: 26 September 2018 - 09:35 AM Rate Topic: -----

#1 EETStudent1   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 25-September 18

School Assignment help

Posted 25 September 2018 - 06:59 AM

Hello, I've been struggling in this class and need some help. I'll get semi functional code and land zero's for assignments. When i ask for examples of similar projects or help i get "figure it out" as a response. Below is the assignment and my current code (that he said isn't correct).

PROJECT REQUIREMENTS:
Requirement: You must demo your program on a dragon12-Light board.

Goal: To become familiar with using Buzzer on Dragon12-Light boards, the timer output compare function, and interrupt method, as well as to improve your programming skills.

Project: Please study Example 11-2C of your textbook. Then, write a C program to do the following:

Run this example program, Buzzer.txtPreview the document to see how the Buzzer on a controller board is turned on and off. Please note that, in the example program, the Buzzer is turned on and off in approximately one millisecond frequency.
Write your own program to turn the Buzzer on and off in exactly one millisecond frequency by using the timer output compare and interrupt method.
The Buzzer is connected to PT5 of the port T. In your main program, you need to write codes to configure PT5 and timer channel 5 so that interrupt for channel 5 output compare is enabled, and PT5 is configured in toggle mode. You need to write an interrupt service routine for timer channel 5 to provide a one millisecond delay (or interrupt).
In EVB (or Debug) mode, the clock frequency for instructions is 24MHz. Use a variable called “ClockCycles” that provides the correct number of clock cycles for the service routine to generate exactly one millisecond delay. This variable is similar to the variable “Period” in the example program Buzzer.txt.


MY CODE: Wrote this with code warrior
//*****************************************************************
//	        Include derivative-specific definitions                   
//*****************************************************************     
//The microcontroller chip used by Dragon12-Light boards 
#include <mc9s12dg256.h>      /* derivative information */


//*****************************************************************
//           Gloable Variables                        
//***************************************************************** 

//*****************************************************************
//           Function Prototype                        
//***************************************************************** 
void MSDelay(unsigned int, unsigned in);

//*****************************************************************
//           Main program section                   
//*****************************************************************
  void main(void)  
 { 
 
    DDRT    =      0b00100000;    //PTT5 as output 
    TSCR2   =      0x80;
    TSCR1   =      0b00000111;
    TIOS    =      0b00100111;
    TCTL1   =      0x04; 
    TIE     =      0x20;

 
    for (;;)/>/> {
        PTT = PTT | 0x20;       //make PT5=1
        MSDelay(100,100);        //change the delay size to see what happens
        
        PTT = PTT & 0xDF;       //Make PT5=0
        MSDelay(1000,1000);        //change delay size....
    
   

    }
}

//*****************************************************************
//           Subroutine: MSDelay                   
//*****************************************************************
void MSDelay(unsigned int itime, unsigned int jtime)  //msec delay
  {
    unsigned int i; unsigned int j;
    for(i=0;i<itime;i++)
      for(j=0;j<jtime;j++);
  }

//*****************************************************************
//           Interrupt Service Routines                          
//**************************************************************
:code:

This post has been edited by modi123_1: 25 September 2018 - 07:01 AM
Reason for edit:: In the future, please use the [code] tag button in the editor.


Is This A Good Question/Topic? 0
  • +

Replies To: School Assignment help

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14690
  • View blog
  • Posts: 58,701
  • Joined: 12-June 08

Re: School Assignment help

Posted 25 September 2018 - 07:00 AM

What's your question?
Was This Post Helpful? 0
  • +
  • -

#3 EETStudent1   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 25-September 18

Re: School Assignment help

Posted 25 September 2018 - 07:20 AM

my bad. I received a zero on this assignment. the comments left where "good job, but you are not supposed to manually toggle the buzzer, but instead use subsystem interrupts to automatically toggle the buzzer. he also noted i needed to learn how to calculate the value to add to Tcount, and add maskable interrupts.

I need help fixing this, or some pointers on what i did wrong/need to add. Just trying to learn!
Was This Post Helpful? 0
  • +
  • -

#4 Salem_c   User is offline

  • void main'ers are DOOMED
  • member icon

Reputation: 2279
  • View blog
  • Posts: 4,362
  • Joined: 30-May 10

Re: School Assignment help

Posted 25 September 2018 - 10:27 PM

This, or something like it, should be in your course books.
http://www.microdigi...lus-Support.htm

Study the C examples for setting interrupt handlers.
Was This Post Helpful? 0
  • +
  • -

#5 EETStudent1   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 25-September 18

Re: School Assignment help

Posted 26 September 2018 - 05:29 AM

It's still making little to no sense to me. Can someone take a look at it and tell me what i need to do to fix it. super frustrated...
Was This Post Helpful? 0
  • +
  • -

#6 Salem_c   User is offline

  • void main'ers are DOOMED
  • member icon

Reputation: 2279
  • View blog
  • Posts: 4,362
  • Joined: 30-May 10

Re: School Assignment help

Posted 26 September 2018 - 09:35 AM

Some steps.
1. Figure out how many clock ticks at 24Mhz equates to an elapsed time of 1mS.
2. Figure out how to program the timer/counter with that value.
3. Figure out how to make said timer/counter trigger an interrupt.
4. Figure out which interrupt vector the processor will use when the timer/counter interrupts.

5. Write a function along the lines of
interrupt void handle1MsTimerIRQ ( void ) {
    // do something quick
}


Exactly how you do this depends on the compiler / processor in use.
The link I posted showed one example syntax. I don't know whether this specifically applies in your case.
Anyway, you should be able to find some local resources to help you (check the examples).
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1