Replies: 3 comments 1 reply
-
Hi Paul, did you read this? |
Beta Was this translation helpful? Give feedback.
-
I did, thank you. And I've re-read it again this evening. I must say that in many ways Spence's documentation is better than Microchips, as to the detail it provides. But I think I'm getting lost in a bit of that detail. I think I need some basic examples (and once I get my understanding of how to use PWM I'd be happy to offer a couple of basic examples). I don't see on the page you referenced a statement that says what the default timer will be for PWM if I don't do any portmux changes and simply have a line in the code that says "analogWrite(PIN_PA2, 127);" I don't know which timer I'm going to end up using. It seems like TCA0 would be that timer, but it appears that when I make changes to PORTMUX.TCAROUTEA that it has no effect on which PORT the PWM appears on. For example, if my program executes "analogWrite(PIN_PA2, 120);" I can see a PWM signal on PA2. But if I read the value of PORTMUX.TCAROUTEA I find that the value is 0x03, which I think would point to the D port. I didn't set the value PORTMUX.TCAROUTEA, it seems that the core initialized it to 0x03, so that's what I read for the value of PORTMUX.TCAROUTEA. So why would I get PWM on A2 if the core set PORTMUX.TCAROUTEA to 0x03? if PORTMUX.TCAROUTEA is set to 0x03 then shouldn't I get no PWM signal until I do something like "analogWrite(PIN_PD2, 120)"? Thanks, |
Beta Was this translation helpful? Give feedback.
-
Spence, thanks for this detailed explanation. But I'm still feeling kinda dense. So let me as a few questions that may seem very elementary. I'm using version 1.5.6 DxCore on an AVR128DB32 test board with VCC at 5 volts. If I run this code
So with the program above running and if I monitor pin PA2 with an old school analog D'Arsonval movement DC voltmeter (the total meter resistance is about 50K on the 5V scale, so there's very little loading) I see a voltage of about 2.5 volts. So all of that is good, just what I would expect. Based on the data sheet, looking at the table in section "3.1 I/O Multiplexing", if I'm getting PWM output on PA2 then I assume that I'm getting it from the "0, WO2" output from TCA0 (and not from the "0, WO" output from TCB0). And yet, if I look at the value stored in PORTMUX.TCAROUTEA, I find that the Core has set that to a value of 0x03 (I assume the Core set it to that value because I didn't set it and the device data sheet says that the reset value of PORTMUX.TCAROUTEA is 0x00). So if PORTMUX.TCAROUTEA is set to 0x03 then why do I get a PWM output on PA2? If I get any PWM, shouldn't I get output on PD2 if PORTMUX.TCAROUTEA is 0x03? My end goal is to have PWM output on PD2. But when I run the follow program:
I do not get a PWM output on PD2 (nor is there PWM on PA2). Again, in this case I find that the Core has set the value of PORTMUX.TCAROUTEA to 0x03. So what DX Core commands would I need to use to get a PWM output on PD2? Thanks, Paul |
Beta Was this translation helpful? Give feedback.
-
I'm trying to do some basic stuff with PWM, and although it sorta works, I don't think its working the way I think it should (based on the docs).
I'm using an AVR128DB32 on a homebrew board. I've got a 24 Mhz crystal on PA0 PA1, but for these tests I'm running on the internal 24 MHz clock. My serial console is on PF4 PF5.
Here's my test code:
`
#define Serial0 Serial2
void setup() {
// for the DB Nano the serial port is UART2 ALT-1 - MTX PF4, MRX PF5 - swap(1)
// for the DD Nano the serial port is UART0 ALT-3 - MTX PD4, MRX PD5 - swap(3)
Serial.swap(1); // UART2 pinout option 1 (MTX PF4, MRX PF5)
Serial.begin(57600, SERIAL_8N1);
Serial.printf("_test_analog_write_PWM_230514-01\n\n");
//PORTMUX.TCAROUTEA = 3;
//PORTMUX.TCAROUTEA = PORTMUX_TCA01_bm | PORTMUX_TCA00_bm;
Serial.printf("show value of PORTMUX.TCAROUTEA 0x%02X\n", PORTMUX.TCAROUTEA);
}
void loop() {
uint8_t lapCtr = 0;
while(1) {
analogWrite(PIN_PA2, 120);
delay(750);
analogWrite(PIN_PA2, 240);
delay(750);
Serial.printf("show value of PORTMUX.TCAROUTEA 0x%02X\n", PORTMUX.TCAROUTEA);
Serial.printf("redoing loop, Count=%d\n", ++lapCtr);
}
}
`
First question is: "how to I know which timer the DX Core is using for PWM?" I assume that the default PWM timer is TCA0, but I don't see in the docs where it says explicitly that the DX core will default to TCA0 for PWM.
How would I cause the DX core to use some other timer for PWM?
Another thing I notice is that my test code works fine for the A ports (I tested only A2, A3 and A5) but the value I find in PORTMUX.TCAROUTEA is 0x03, which should mean (from the data sheet) that port D is used for the PWM outputs from TCA0. Why am I getting PWM output on the A port when PORTMUX.TCAROUTEA is 0x03? Is some timer other than TCA0 providing the PWM function? If so, which timer is it? If I set the value of PORTMUX.TCAROUTEA to 0x02 (which should put PWM on the C port) I find that PWM stays on the A port.
Which leads to the question that started my looking at all this. How do I get the PWM signals to appear on the D port?
thanks,
Paul
Beta Was this translation helpful? Give feedback.
All reactions