I don’t completely understand this, though I get the general idea. I haven’t seen the email yet, so if you have already sent it let me know, maybe you need to give me your email and I’ll email you. I have a couple more questions, which will probably give away my newb-ness to this, here goes:
You are controlling 3 pins (1,2 and 5) with PWM, running them at 200Hz and turning off/on from .NET, correct? It doesn’t look like you are precisely controlling when the 200Hz starts and stops. Why aren’t you able to just take PWM pin from .NET and set it to go at 200Hz?
There are lots of variables set here that don’t appear to be used so I’m guessing they are used elsewhere, such as PWM1TCR. Can you give more context so I can see how they are used or are they in pwm.c/h? Where is pwm.c/h found or is that what you are emailing me?
Is Pclk the clock used to drive PWM? How did you arrive at 18Mhz?
I get how the cycle width gives you 200Hz (5000 * 200 = 1M), what is nominal center for? Is it because there is some delay in the PWM turning on and off which makes it 3000 and not 5000 cycles long?
In my case I need to take a given binary rep of a byte, say 10010100 and generate PWM in sequence - A low tone, say 1000Hz for all the zeros and a high tone, say 1200Hz for the ones with the timing between bits based on the baud rate. I think I’ll just be doing the same thing you have in here, but I’ll be doing the content of Pwm_Start and Stop inside one method based on an incoming byte array, doing the above per byte. Sound reasonable?
Here is the code I’m using right now that only works for low baud rates since once I reach 100 baud the Thread.Sleep is around 10ms which becomes not terribly reliable.
const int CHARBITS = 5;
const int START = 1;
const int STOP = 1;
const int BAUD = 75;
static int INTER_BIT_DELAY = (1000 / BAUD);
//tones in Hz for low(space) and high(mark)
const int HIGH = 2295;
const int LOW = 2125;
private static void SendByte(PWM signal, byte c)
{
for (int i = 0; i < START; i++)
RTTYBit(signal, 0);
int b = 1;
for (int i = 0; i < CHARBITS; i++, b *= 2)
RTTYBit(signal, c & b);
for (int i = 0; i < STOP; i++)
RTTYBit(signal, 1);
}
static void RTTYBit(PWM signal, int b)
{
signal.Set(b > 0 ? HIGH : LOW, 90);
Thread.Sleep(INTER_BIT_DELAY);
}