View previous topic :: View next topic |
Author |
Message |
canipusA Guest
|
Trying to gate EX_SINE.C on/off |
Posted: Thu Dec 13, 2007 6:42 pm |
|
|
Can someone please add in the statement required to help me gate on/off the sine wave in the EX_SINE.C. I nearly have it working. From power up I can gate the sine wave on at pin A0 of my PIC16F87. However, once the interupt loop has started I can't gate it off. The line of code that gated the sine wave on is now outside the interupt loop that keeps circling through the sine table and my beginner skills in C aren't strong enough yet to work out how to get the program to go back and check my A0 logic level to see whether the Sine wave should be gated off. I have posted the top of my file and the changes I have made at the bottom. The rest of the program is more or less the default example file (which I haven't posted to comply with the posting rules). I am so close. I have a perfect sine wave (I did actually change the frequency by choosing a different reload factor but this is not material to my problem). I just want to be able to gate the sine wave on or off in synchronism to the logic level on A0
Please help...desperate Code: |
#if defined(__PCM__)
#include <16F87.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=16000000)
//#use fast_io(a)
//#use fast_io(b)
#ifndef MAX517_SDA
#define MAX517_SDA PIN_B1
#define MAX517_SCL PIN_B4
#define gate PIN_A0
// continue with EX_SINE.C
// .............
// .............
// .............
// end changed below to gate sine wave on/off
void main() {
while (!input(gate)); //waits for gate to go high
OUTPUT_B(0xFF); //port B set high while waiting for gate to go high
setup_counters( RTCC_INTERNAL, RTCC_DIV_16); //gate gone high
enable_interrupts(INT_RTCC);
enable_interrupts(GLOBAL);
while (TRUE) {
}
} |
|
|
|
CanipusA Guest
|
|
Posted: Fri Dec 14, 2007 12:21 pm |
|
|
I don't freaking well believe this! Isn't there one god damn person reading this group that is willing to help a newcomer out with a couple of lines of code or syntax?
Maybe I should just give up try to learn CCS. It's got a buggy reputation anyway so I guess I'm wasting my time. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Dec 14, 2007 12:21 pm |
|
|
The simple way is to add a test inside your isr, at the point where it
writes the Sine wave values to the DAC. If pin A0 is high, then write
the value from the the Sine Table. If pin A0 is low, then write some
idle state value. I picked 128 as the idle state because it appears to
be at the midpoint of the sine table values.
There could be some issues with switch debouncing (assuming you have
a switch on pin A0), and also the code below will continue to advance
the table index on each interrupt. So when you re-enable pin A0, the
sinewave will re-start at the current position in the table, and not where
it left off. But you could modify the code slightly to do that, if needed.
The code below is good enough to get you started.
Code: |
#define SINEWAVE_IDLE_STATE 128
#int_rtcc
void isr()
{
set_rtcc(102);
if(input(PIN_A0))
write_dac(SINE_WAVE[sine_index]);
else
write_dac(SINEWAVE_IDLE_STATE);
if(++sine_index==200) {
sine_index=0;
}
} |
|
|
|
amcfall
Joined: 20 Oct 2005 Posts: 44
|
|
Posted: Fri Dec 14, 2007 12:32 pm |
|
|
CanipusA wrote: | I don't freaking well believe this! Isn't there one god damn person reading this group that is willing to help a newcomer out with a couple of lines of code or syntax?
Maybe I should just give up try to learn CCS. It's got a buggy reputation anyway so I guess I'm wasting my time. |
Well, this is sure not a good way to get help. Sure, just berate the people you are asking for (free) help. |
|
|
CanipusA Guest
|
|
Posted: Fri Dec 14, 2007 12:33 pm |
|
|
PCM Programmer.
Gods bless you. You are my life saver. I was beginning to think this group didn't care about anybody that was trying to learn. I will add your suggestion and work from there. I have already tried using PWM C code to get this sine wave but even after filtering, the shape on the osc-scope was not too hot. The gating is going to be from external logic not a mechanical switch so swiych bounce isn't an issue - but thank you for alerting me to that potential problem. Not sure yet if the advancing sine table during the gate off period is going to be an issue. Probably not but if it is I'm sure I can now solve that problem. Thank you again for bailing me out. I was getting desperate because this code gives by far and away the best shaped sine wave on the osc-scope. I guess everybody is too busy working on really deep esoteric stuff to get involved with simple code probllems like this. |
|
|
Guest
|
|
Posted: Fri Dec 14, 2007 12:37 pm |
|
|
[quote="
Well, this is sure not a good way to get help. Sure, just berate the people you are asking for (free) help.[/quote]
I'm sorry. Just totally frustrated that all the other posts were getting responses and mine was being passed over and no one seemed to care. And it wasn't like I was asking someone to write and program the entire project. I just needed pushing along a bit and PCM Programmer has kindly done that |
|
|
|