Family Reference Manual. Digital Signal Controllers. Note the following details of the code protection feature on Microchip devices:. All of these methods, to our. Most likely, the person doing so is engaged in theft of intellectual property.

Author:Nikonos Tetaur
Language:English (Spanish)
Published (Last):3 October 2013
PDF File Size:3.30 Mb
ePub File Size:15.72 Mb
Price:Free* [*Free Regsitration Required]

This section contains several useful pieces of sample code for different tasks on the dsPIC. There is just one example question at the end , which provides a reasonably detailed description of an imagined control scenario for which you are asked to write a dsPIC program in C. The microcontroller that we use in the Robotics module lab sessions and mini-project belongs to the PIC range, which is produced by Microchip Inc.

This range of microcontrollers contains hundred of different chips, grouped into several product families. Microcontrollers with features similar to those in the PIC range are available from many other manufacturers e.

Texas Instruments, Intel, Atmel, etc. What that means is that each of its registers aka memory locations stores one bit binary number. DIP chips have a standard pin size and spacing that makes them suitable for plugging straight into a breadboard. It is possible to buy the exact same dsPIC in a much smaller surface-mount package, but it cannot then be used easily in a breadboard. The DIP package is therefore much more convenient for the ad hoc experimental work we do in the Robotics lab.

The following are some of the main reasons why the dsPIC30F was chosen as the microcontroller for this module:. Please take a few minutes to read the full list of features on pages 1 and 2 of the dsPIC30F datasheet. Of the dsPIC-related documents supplied by the manufacturer, those which are most useful to have at your side while programming are the following:. Nevertheless, the basic principles of operation are identical across the 30F range of microcontrollers and once you have learned to program one you should be able to transfer that knowedge to other chips in the same family without much difficulty.

The following example program demonstrates basic analog input on the dsPIC30F The total time per measurement including sampling time and conversion time should be less than 2. One feature of the dsPIC30F that is very useful in control, automation and robotics is that it provides three dedicated pairs of PWM output pins, each of which can be used to control a servo, to vary the speed of a DC motor, or for many other purposes.

The PWM period, , is calculated as follows:. The formula for calculating the pulse width is as follows:. The duty cycle of each of the three PWM channels is controlled by an analog input. All three PWM channels are configured in complementary mode — i. The PWM period should be 20ms. Sometimes, we want to make the dsPIC perform the same action over and over again at a regular time interval. For example, we might want to flash an LED by toggling a digital output pin once every ms.

Or we might want to read an analog input once every 10ms. The dsPIC provides a very convenient way of designating a function in our C program that it will automatically call at a regular interval that we specify. The dsPIC uses one of its timers to tell it when to call the function. When the timer reaches a particular value which we have specified in our program the dsPIC interrupts whatever it is doing and jumps to the designated function, which we call the interrupt service routine ISR.

When we write a C program to run on a PC, we often use the printf function to display text messages on the screen. In general, the dsPIC has no screen attached to it, but we can still use printf to display messages via a serial connection to a PC.

The dsPIC contains a subsystem called a UART universal asynchronous receiver and transmitter which allows data to be transmitted and received serially i. This program repeatedly reads bit analog readings from AN0-AN7 and then prints the results to the serial output. The baud rate is set to 38, You are writing a C program for the dsPIC controller in a service elevator, which is used to transport one trolley at a time carrying materials from the ground floor delivery area of a factory to the production line on the first floor.

The elevator should behave as follows:. The position of the elevator is sensed using a pair of contact switches that are connected to two of the dsPIC digital input pins RD2 and RD3 as follows:. The elevator is fitted with an analog weight sensor that outputs a voltage between 0V and 5V. Write a C program to control the elevator. You can assume that the appropriate pins have already been designated as digital inputs, digital outputs, analog inputs, etc.

Before writing the program, we just need to know what values the ADC will read at the two critical threshold voltages 2V and 3V. The full input voltage range of the ADC is 0V-5V and because it is a bit device, there are voltage levels over that range i.

The ADC output at the lower threshold 2V is calculated as follows:. So, when the ADC reads the voltage on pin AN0 and the result is less than , there is definitely no trolley in the elevator. Conversely, when the ADC reads AN0 and the result is greater than , there is definitely a full trolley in the elevator. This is great. Best of luck getting the H-bridge going! First I have to thank you. These day I will see if it works phisically. Since each hex digit represents four binary digits i.

In particular, look are section The info is basically given in section So the clock frequency of the chip is MHz. That means the clock signal inside the chip repeats ,, times per second. However, the dsPIC performs only one machine instruction for every four clock cycles.

Therefore, the number of machine instructions performed each second is 30,, The time taken to perform a single machine instruction is what we call the instruction cycle, T cy. When programming the dsPIC, T cy is the most important time to be aware of since every time value specified in your program will be specified as a multiple of it.

If you select a different clock speed for your chip, the value of T cy will change. We can write this same value as the following bit binary value:. As explained in section Also, according to section It is possible to move the ADC and interrupt code to another C file, which will be accessed via a single function call from main.

Thank You Sir …. The following lines from the example program are the ones that enable PWM output on all three channels:. For example, these are the lines that repeatedly update the duty cycle on PWM channel 1 to reflect changes in the analog voltage on AN You should begin by running the PWM example from this page without modifying it in any way.

Then just check with an oscilloscope or logic analyzer to see that the PWM signal is coming out as expected.

You do not need to do anything else to enable the PWM outputs. I have got the first part of it so if i sense the volatge from the analog input it will covert the volatge to Digital as the Duty Cycle will be the Function of the Input Volatge and voltage reference ie 12 V battery. How can this be done Can u please explain me.. I will update my code and Can u please go through it and help my mistakes.. Dear sir, my name is nor.

Are you using the C30 compiler? Also, have you tried setting the heap size to something smaller than ? I think this example will work ok with a smaller heap size e. Regards, Ted. I am using a 6. Please Respond Soon. Is the program downloading to the chip without errors? Have you tried running the simpler examples to check that they are working for you? Have you got at least the minimum required wiring done — i. What output are you seeing on pin 38?

Have you modified the code to select an external oscillator? Did you check pin 37 PWM1H? Did you make any other changes to the code? Thank you so much for the quick response Sir. I did all those things what you have told to do and got that whatever I want. Sir your program is working very nicely once again I am very thankful to you. Just one more question Sir how can I vary the frequency of the PWM signal according to me through the code and can i use the differential equations in the C code.

If your clock speed is different, the number above will produce a different frequency. If I wanted to double the frequency i. Thank you so much for responding soon and helping me. Now I am able to control PWM signal from your post. What all will be required for this i want to know. Waiting for your reply. Thank you again Sir. Hi Batchloaf I have gone through your tutorial for dspic30f and I have found it very useful and well organised notes.

At the moment I am working on my final year project and I have generated two PWM with the same duty ratio which I can control those pulses by a potentiometer. I just need to make a phase shift of degrees between them.





dsPIC30F Datasheet PDF



dsPIC30F Datasheet


Related Articles