Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

writing random numbers in PIC16F1936 Internal EEPROM

Status
Not open for further replies.
I appreciate there may be language difficulties but how many times do we have to explain. :-x

Phase1 = starts at the beginning of your table
Phase2 = starts one third of the way along your table
Phase3 = starts two thirds of the way along your table.

Try this:
Plot a graph of the 240 values in your table, it should give a close approximation to a sine wave.
Plot another graph line of the 240 values, this time starting one third along (index 80), wrapping back to the beginning when you reach the end until you reach index 79.
Plot another graph line of the 240 values, this time starting two thirds along (index 160), wrapping back to the beginning when you reach the end until you reach index 159.

Do you notice anything about the curves and their phase relationships?

Then consider what this code might do if you call it repeatedly:
Code:
if(index++ > 79) index = 0;
phase1 = table[index];
phase2 = table[index + 80];
phase3 = table[index + 160];

Brian.
 

Isn't it that you need to calculate three separate modulo 240 operations for the three phase indices to have each phase value rotating through the full 360 degree range?
 

Sorry, I had a 'senior moment'!

Yes, you are quite right, it should be more like:
Code:
if(index++ > 240) index = 0;
phase1 = table[index];
phase2 = table[(index + 80) % 240];
phase3 = table[(index + 160) % 240];

otherwise only part of the table would be used.

Brian.
 

Hi,

to avoid the modulo operation (twice per PWM cycle) one simply could add the first 160 data to the existing 240 data.

Klaus
 

I think, for a small CPU without hardware divider, you can best avoid the modulation operation by using three separate pointers that are "free running" after being initialized with correct offset. Checking the code size and execution time in MPLab simulator stop watch can help to identify the smallest/fastest code.
 

If it was my project I would probably build three 90 degree tables with the appropriate shift incorporated in them and generate the remaining three quadrants mathematically. In a working system the rate of stepping from one table entry to the next would determine the resulting power waveform from the PWM outputs so for frequency accuracy it would be done using a timer interrupt. To some degree that makes the system less critical of modulo math delays as long as the math is completed between interrupts.

Regardless of how it is done, I think the OP is having conceptual problems of extracting three different phase values from a single table. I'm sensing they can see how one phase is produced but think the other two are derived from it in software rather than being independantly generated.

Brian.
 

Hi,Could you advise on those tables??
 

The way I produce them is with a spreadsheet (I use Libre Office).
Put the angle in degrees in the first column 'A'
Put the formula '=INT(RADIANS(SIN(A1)) * 127) in column 'B' then select and drag it down to the end row of the angles you entered.
Column B then contains the values for your table.

Brian.
 

This is producing one table,what about the second and third,I understand that the formula is the same but the angles might change,

Please help.

Thank you

- - - Updated - - -

Hey,betwixt;the formula seems to be not correct.
 

Hi,

This is producing one table,what about the second and third,I understand that the formula is the same but the angles might change,

Are you really asking for this answer:

Use a second column and add 120° to the angle (= column A) wich is in radians:
120 × 2 × pi () / 360 = 2 × Pi() / 3

Put the formula '=INT(RADIANS(SIN(A1 +(2 × pi () / 3))) * 127)' in column C
And '=INT(RADIANS(SIN(A1 +(4 × pi () / 3))) * 127)' in column D

Klaus
 

Hi,I found it easier for me to edit the codes of AN889 on microchip and adapt those codes to my PIC16F1936 (this has 3ECCP and 2 CCP Modules),here in attachment is what I am getting while simulating with proteus,the graph on CCP1 is not ok,you find also the codes corresponding to what I changed.find the attachment.

The project is done in Assembly language.!!

Please help to handle the concern here.!!

Thank you!!
 

Attachments

  • Codes.zip
    268.7 KB · Views: 62

I still can't work out what you are having trouble with. The table in the asm file is exactly the same as the ones we have already explained except in a different quadrant of the sine wave and for fewer points. The numbers are just the sine values of the angles but scaled to fit an 8-bit variable.

Sine values of angles from the center to circumference of a circle fall in the range -1 to +1.
The PWM duty ratio accepts 10-bit numbers but you can ignore the two LSB so the numeric range of 8 bits is 0 to 255. (0x00 to 0xFF in hex)
So you need to scale -1 to +1 so it falls between 0 and 255.
The way to do it is to add 1 so the sine values are 0 to 2 then multiply the result by 127. You lose one count (255) but you can live with that.
-1 to +1 becomes 0 to 254.

If you are using the 19 values in the table, representing 180 degrees, you need to use the values twice to complete 360 degrees. The rate you move through the table is the number of points you plot multiplied by the frequency you are generating. The offset angle for each phase is derived by picking the value from a different place in the table.

Brian.
 

Hey Betwixt,could you let me know why the graph on the oscilloscope looks as the one iI posted,how should I preced in 16f1936 configuration for getting three three controlling signals?


I may use CCP1,CCP2 and CCP3 of the PIC16F1936,those modules has also the ECCP capabilities,please help!!

Thank you!!
 

What is wrong with the three signals?
Obviously, I can't see where you are measuring them from but if it's the 3 PWM outputs those waveforms may be fine although I might expect the ratios to be different between them. What are you expecting them to be?

Brian.
 

They looks like there is a problem of ratio difference the two of CCP2 and CCP3 are uniform but they are different to the one of CCP1,I configured the PR2,CCP1CON,CCP2CON,CCP3CON,CCPR1L,CCPR2L,CCPR3L APFCON,SPTR1S,etc as the datasheet states but they can`t be uniform,with three phase system implementation is it possible to visualise the phase shifting of 120degree with PWM Signals??

Please help!!

Thx
 

To be honest I don't use MikroC or Proteus so I'm not sue of their limitations when simulating. What I would expect to see is the three waveforms repeating at the same rate but each having a different high/low ratio. If you can stop the simulation at sine 0, 120 and 240 you should see each one in turn being at minimum high time so the display differences would be more obvious.

Alternatively, an assuming the simulator is accurate, try adjusting the horizontal sweep time so the 'density' of pulse changing is easier to see.

Brian.
 

I did but still,it shows the difference in duty cycle!!


Thanks.
 

Possibly it's a limitation of Proteus then. As I said, I have never used it. The debugging tools I normally use have a 'PWM voltmeter' device which can be hooked up to the three PWM outputs to show the average voltage they are producing. It's real purpose is showing the recovered DC average from the waveform but it also works as an instantaneous voltmeter if the program is stopped by a breakpoint. Maybe Proteus has something similar you could use instead of the oscilloscope.

Brian.
 

Which software are you using?
Now I made a physical circuit on CCP1 I get nothing on the oscilloscope,only on the CCP2 and CCP3 the signals are there,what could be the mistake?

Thank you!
 

Can you post your complete source code again please so we can see exactly what you are doing at the moment.

I use either "Wiz-C Pro" or XC8 for that type of processor. XC8 is slightly better as a compiler, Wiz-C's optimizer isn't quite as good as XC8 but it is far better at simulation.

Brian.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top